Difference between revisions of "Maple/Example/CAD Fig 03 14"

From PrattWiki
Jump to navigation Jump to search
(Created page with "This page goes over how to get the equations from and solve the circuit in Figure 3-14 of [https://cad.eecs.umich.edu/ "Circuit Analysis and Design" by Ulaby, Maharbiz, and Fu...")
 
m (DukeEgr93 moved page Maple/Example/CAD Fig 03 13 to Maple/Example/CAD Fig 03 14 without leaving a redirect: 14 is not 13)
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
This page goes over how to get the equations from and solve the circuit in Figure 3-14 of [https://cad.eecs.umich.edu/ "Circuit Analysis and Design" by Ulaby, Maharbiz, and Furse].   
+
This page goes over how to get the equations from and solve the circuit in Figure 3-14 of [https://cad.eecs.umich.edu/ "Circuit Analysis and Design" by Ulaby, Maharbiz, and Furse].  The full Maple example is available on the Maple Cloud at [https://maple.cloud/app/4564611728801792/CAD_Fig03p14?key=91476187A8C04D1BA3DF1224600039971BC0759636FC4B3B9DB5AA8F55B78998 CAD_Fig03p14]
  
 
== Convert to Symbols ==
 
== Convert to Symbols ==
Line 11: Line 11:
 
as the first executable in your worksheet.
 
as the first executable in your worksheet.
  
=== Define Equations ===
+
== Define Equations ==
 
To solve this circuit using Mesh Current Method, note that there are three meshes and no current sources so you have three independent KVL equations.  While there are six loops to choose from, there is no reason to not just choose the three meshes.  If you start at the lower-left hand corner of each mesh and count the voltage drops clockwise, you get:
 
To solve this circuit using Mesh Current Method, note that there are three meshes and no current sources so you have three independent KVL equations.  While there are six loops to choose from, there is no reason to not just choose the three meshes.  If you start at the lower-left hand corner of each mesh and count the voltage drops clockwise, you get:
 
<center><math>
 
<center><math>
 
\begin{align*}
 
\begin{align*}
KVL,l1&=-v_1+R_2I_1+R_3(I_1-I_2)+R_6(I_1-I_3)+v_2=0
+
KVL,l1&=-v_1+R_2I_1+R_3(I_1-I_2)+R_6(I_1-I_3)+v_2=0\\
 +
KVL,l2&=R_3(I_2-I_1)+R_4I_2+R_5(I_2-I_3)=0\\
 +
KVL,l3&=-v_2+R_6(I_3-I_1)+R_5(I_3-I_2)+R_7I_3=0
 
\end{align*}
 
\end{align*}
 
</math></center>
 
</math></center>
 +
You can add those to your Maple worksheet with:
 +
<syntaxhighlight lang=text>
 +
KVLl1 := -v1 + R2*I1 + R3*(I1 - I2) + R6*(I1 - I3) + v2 = 0;
 +
KVLl2 := R3*(I2 - I1) + R4*I2 + R5*(I2 - I3) = 0;
 +
KVLl3 := -v2 + R6*(I3 - I1) + R5*(I3 - I2) + R7*I3 = 0;
 +
</syntaxhighlight>
  
=== Solve Equations ===
+
== Solve Equations ==
The easiest way to solve an equation (or a system) of equations is to use the <code>solve</code> command.  The most formal, and flexible, way to use this command is to give it a set of equations (surrounded by curly brackets) and a list of variables (surrounded by square brackets).  The result will be an expression, set of expressions, list of expressions, or list of list of expressions depending on the nature and number of the equations and the solutions.  For example, if you add the code:
+
You now want to solve the equations for the mesh currents; you can get the solutions (and store them) with the code:
 
<syntaxhighlight>
 
<syntaxhighlight>
soln1 := solve({eqn1}, [x])
+
soln1 := solve({KVLl1, KVLl2, KVLl3}, [I1, I2, I3])
 +
</syntaxhighlight>
 +
In the example worksheet, the solutions are printed out.  You should generally run this command at least once without putting a : at the end to make sure you are actually getting a set of solutions and not just an empty list.  Once you have confirmed that you are getting a solution, if you do not need to see the full symbolic solutions, you can then add a : to the end of this line to suppress printing.
 +
 
 +
== Make Substitutions ==
 +
Now that you have symbolic answers, you can make numerical substitutions for those symbols using the <code>subs</code> command.  For this problem, you can make a variable that has all the substitutions and then use them.  You may also want Maple to display the results as floating point numbers rather than fractions; use the <code>evalf</code> command for that:
 +
<syntaxhighlight lang=text>
 +
vals := R2 = 2, R3 = 3, R4 = 4, R5 = 5, R6 = 6, R7 = 7, v1 = 6, v2 = 4;
 +
numsoln1 := subs(vals, soln1);
 +
evalf[4](numsoln1);
 +
</syntaxhighlight>
 +
 
 +
== Define Auxiliary Equations ==
 +
You may want to find the powers delivered by each source and the powers absorbed by each resistor.  To do that, make a set of auxiliary equations and then perform the necessary substitutions; note that the second line is fairly long and is probably wrapping on your screen.
 +
<syntaxhighlight lang=text>
 +
psource := pdelv1 = v1*I1, pdelv2 = v2*(I3 - I1);
 +
presistor := pabsR2 = R2*I1^2, pabsR3 = R3*(I1 - I2)^2, pabsR4 = R4*I2^2, pabsR5 = R5*(I2 - I3)^2, pabsR6 = R6*(I1 - I3)^2, pabsR7 = R7*I3^2;
 +
numpower := subs(soln1[1][], vals, [psource, presistor]);
 +
evalf[4](numpower);
 
</syntaxhighlight>
 
</syntaxhighlight>
then Maple will produce a variable called <code>soln1</code> that has a list with a list with an expression; specifically, $$soln1 := [[x = \frac{d}{a}]]$$
 
  
=== Make Substitutions ===
+
== Check Conservation of Power ==
Now that you have symbolic answers, you can make numerical substitutions for those symbols using the <code>subs</code> command.  The subs command expects a series of equalities to define the substitutions followed by a single item into which to make those substitutionsFor example, to see what x is when d is 10, you can write:
+
Finally, you may want to see if power is conserved.  To do that, you will want to add the powers delivered by the two sources together, then add the powers absorbed by the six resistors together, then compare those two numbers.  They should be the same.  One way to accomplish this goal is to use a loop in Maple.  Inside the loop, you will want to access one of the expressions in the <code>power</code> list, extract the right hand side of the expression, then add that to some kind of accumulator variableHere is some example code to do just that for this particular problem:
<syntaxhighlight>
+
<syntaxhighlight lang=text>
subs(d = 10, soln1)
+
pdel := 0:
 +
for k to 2 do
 +
    pdel := pdel + rhs(power[k]);
 +
end do:
 +
pdel;
 
</syntaxhighlight>
 
</syntaxhighlight>
and you will get the new list of lists $$[[x = \frac{10}{a}]]$$.  If you want to see multiple substitutions, you can put them all at the start of the soln command:
+
<syntaxhighlight lang=text>
<syntaxhighlight>
+
pabs := 0;
subs(a=3, d = 10, soln1)
+
for k from 3 to 8 do
 +
    pabs := pabs + rhs(power[k]);
 +
end do:
 +
pabs;
 
</syntaxhighlight>
 
</syntaxhighlight>
will give $$[[x = \frac{10}{3}]]$$
+
Note that the : at the end of the <code>end do:</code> command tells Maple to suppress printing out intermediate results in the loop.  If you want to see what it is doing, replace the : with a ;
 +
 
 +
For this circuit, you should get that the power delivered by the sources is 4124/1327 and that the power absorbed by all the resistors is also that amount.

Latest revision as of 18:59, 13 January 2024

This page goes over how to get the equations from and solve the circuit in Figure 3-14 of "Circuit Analysis and Design" by Ulaby, Maharbiz, and Furse. The full Maple example is available on the Maple Cloud at CAD_Fig03p14

Convert to Symbols

For the Maple worksheet, we are going to use symbols for each of the circuit elements. The 6 V source will be $$v_1$$ and the 4 V source will be $$v_2$$. For the resistors, label each with a subscript that matches the value in ohms (e.g. the 6 $$\Omega$$ resistor will be called $$R_6$$.

Initialization

Go ahead and put

restart

as the first executable in your worksheet.

Define Equations

To solve this circuit using Mesh Current Method, note that there are three meshes and no current sources so you have three independent KVL equations. While there are six loops to choose from, there is no reason to not just choose the three meshes. If you start at the lower-left hand corner of each mesh and count the voltage drops clockwise, you get:

\( \begin{align*} KVL,l1&=-v_1+R_2I_1+R_3(I_1-I_2)+R_6(I_1-I_3)+v_2=0\\ KVL,l2&=R_3(I_2-I_1)+R_4I_2+R_5(I_2-I_3)=0\\ KVL,l3&=-v_2+R_6(I_3-I_1)+R_5(I_3-I_2)+R_7I_3=0 \end{align*} \)

You can add those to your Maple worksheet with:

KVLl1 := -v1 + R2*I1 + R3*(I1 - I2) + R6*(I1 - I3) + v2 = 0;
KVLl2 := R3*(I2 - I1) + R4*I2 + R5*(I2 - I3) = 0;
KVLl3 := -v2 + R6*(I3 - I1) + R5*(I3 - I2) + R7*I3 = 0;

Solve Equations

You now want to solve the equations for the mesh currents; you can get the solutions (and store them) with the code:

soln1 := solve({KVLl1, KVLl2, KVLl3}, [I1, I2, I3])

In the example worksheet, the solutions are printed out. You should generally run this command at least once without putting a : at the end to make sure you are actually getting a set of solutions and not just an empty list. Once you have confirmed that you are getting a solution, if you do not need to see the full symbolic solutions, you can then add a : to the end of this line to suppress printing.

Make Substitutions

Now that you have symbolic answers, you can make numerical substitutions for those symbols using the subs command. For this problem, you can make a variable that has all the substitutions and then use them. You may also want Maple to display the results as floating point numbers rather than fractions; use the evalf command for that:

vals := R2 = 2, R3 = 3, R4 = 4, R5 = 5, R6 = 6, R7 = 7, v1 = 6, v2 = 4;
numsoln1 := subs(vals, soln1);
evalf[4](numsoln1);

Define Auxiliary Equations

You may want to find the powers delivered by each source and the powers absorbed by each resistor. To do that, make a set of auxiliary equations and then perform the necessary substitutions; note that the second line is fairly long and is probably wrapping on your screen.

psource := pdelv1 = v1*I1, pdelv2 = v2*(I3 - I1);
presistor := pabsR2 = R2*I1^2, pabsR3 = R3*(I1 - I2)^2, pabsR4 = R4*I2^2, pabsR5 = R5*(I2 - I3)^2, pabsR6 = R6*(I1 - I3)^2, pabsR7 = R7*I3^2;
numpower := subs(soln1[1][], vals, [psource, presistor]);
evalf[4](numpower);

Check Conservation of Power

Finally, you may want to see if power is conserved. To do that, you will want to add the powers delivered by the two sources together, then add the powers absorbed by the six resistors together, then compare those two numbers. They should be the same. One way to accomplish this goal is to use a loop in Maple. Inside the loop, you will want to access one of the expressions in the power list, extract the right hand side of the expression, then add that to some kind of accumulator variable. Here is some example code to do just that for this particular problem:

pdel := 0:
for k to 2 do
    pdel := pdel + rhs(power[k]);
end do:
pdel;
pabs := 0;
for k from 3 to 8 do
    pabs := pabs + rhs(power[k]);
end do:
pabs;

Note that the : at the end of the end do: command tells Maple to suppress printing out intermediate results in the loop. If you want to see what it is doing, replace the : with a ;

For this circuit, you should get that the power delivered by the sources is 4124/1327 and that the power absorbed by all the resistors is also that amount.