Difference between revisions of "Maple/Simultaneous Equations"
Line 2: | Line 2: | ||
This page focuses on using Maple to find both the symbolic and the numeric solutions to equations obtained from electric circuits. It assumes that you have already taken the steps in [[Maple/Initialization and Documentation]] to start Maple and begin documenting your work. | This page focuses on using Maple to find both the symbolic and the numeric solutions to equations obtained from electric circuits. It assumes that you have already taken the steps in [[Maple/Initialization and Documentation]] to start Maple and begin documenting your work. | ||
− | + | ==Defining Variables and Equations== | |
− | |||
− | |||
− | |||
In Maple, the way you define a variable is by typing the name of the | In Maple, the way you define a variable is by typing the name of the | ||
variable, followed by the symbols ''':=''', followed by whatever items | variable, followed by the symbols ''':=''', followed by whatever items | ||
Line 38: | Line 35: | ||
items in the equations. | items in the equations. | ||
− | + | ==Solving Equations With Maple== | |
To solve the equations, all you need to do is use Maple's built in | To solve the equations, all you need to do is use Maple's built in | ||
'''solve''' function. One of the best ways to use the '''solve''' | '''solve''' function. One of the best ways to use the '''solve''' | ||
Line 76: | Line 73: | ||
later. | later. | ||
− | + | ==Substituting Values== | |
Now that you have the symbolic answers to the variables ''x'', ''y'', and | Now that you have the symbolic answers to the variables ''x'', ''y'', and | ||
''z'', you may want to substitute the actual coefficient values to | ''z'', you may want to substitute the actual coefficient values to | ||
Line 208: | Line 205: | ||
<math>\frac{1}{3}</math> when everything gets substituted in. | <math>\frac{1}{3}</math> when everything gets substituted in. | ||
− | + | ==Cleaning Things Up== | |
Many times, Maple will produce an expression that is more complicated | Many times, Maple will produce an expression that is more complicated | ||
than it needs to be. To get what it considers to be the simplest | than it needs to be. To get what it considers to be the simplest | ||
Line 223: | Line 220: | ||
</source> | </source> | ||
will produce a floating point result for <math>\alpha</math>. With practice, you | will produce a floating point result for <math>\alpha</math>. With practice, you | ||
− | will see how best to combine | + | will see how best to combine <code>evalf</code>, <code>simplify</code>, and <code>expand</code> to get the form of answer you want. |
− | |||
==Memory Issues== | ==Memory Issues== | ||
Line 236: | Line 232: | ||
worksheet is the !!! button at the top of the window. | worksheet is the !!! button at the top of the window. | ||
− | == | + | <!-- |
− | + | == Examples == | |
− | Each of the samples | + | ===Solving Circuit Variables=== |
− | absorbed by resistor <math>R_{4}</math> in the circuit | + | [[File:SampleStarter.png|thumb]] |
− | + | Each of the samples in this section will involve solving for the power | |
− | + | absorbed by resistor <math>R_{4}</math> in the circuit at right | |
− | |||
by using a different method. The circuit will be presented several times | by using a different method. The circuit will be presented several times | ||
along the way to demonstrate how to label it properly for the given | along the way to demonstrate how to label it properly for the given | ||
method. | method. | ||
+ | <br clear=all> | ||
− | + | ====Node Voltage Method==== | |
+ | =====Choose Ground Node ===== | ||
+ | [[file:SampleNVM1.png|thumbs|Circuit now shown with ground node.]] | ||
First, choose a ground node. In this case, the large bottom node is | First, choose a ground node. In this case, the large bottom node is | ||
as good as any: | as good as any: | ||
− | + | =====Label Each Node===== | |
− | |||
− | |||
Next, circle or otherwise mark each node: | Next, circle or otherwise mark each node: | ||
Line 270: | Line 266: | ||
Note that other unknowns could have been selected so long as they | Note that other unknowns could have been selected so long as they | ||
gave equations for each of the nodes. | gave equations for each of the nodes. | ||
− | + | =====Determine Equations===== | |
Finally, you can write the KCL equations. In this case, there are | Finally, you can write the KCL equations. In this case, there are | ||
three unknowns so you need to pick three of the nodes. To help | three unknowns so you need to pick three of the nodes. To help | ||
Line 280: | Line 276: | ||
leaving} the node through each branch that passes through the node | leaving} the node through each branch that passes through the node | ||
boundary, are: | boundary, are: | ||
− | + | ||
Assume you have a circuit for which the KCL equations are: | Assume you have a circuit for which the KCL equations are: | ||
<center><math> | <center><math> | ||
Line 304: | Line 300: | ||
squared divided by the resistance. | squared divided by the resistance. | ||
− | + | ||
− | + | ====Branch Current Method==== | |
For the BCM, start be determining the number of branches. In this | For the BCM, start be determining the number of branches. In this | ||
particular case, there are five branches. One of them - the very top | particular case, there are five branches. One of them - the very top | ||
Line 365: | Line 361: | ||
\pagebreak | \pagebreak | ||
− | + | ====Mesh Current Method==== | |
For the MCM, start by labeling the mesh currents in the primary loops. | For the MCM, start by labeling the mesh currents in the primary loops. | ||
In this particular case, there are three primary loops. As to avoid | In this particular case, there are three primary loops. As to avoid | ||
Line 403: | Line 399: | ||
squared multiplied by the resistance. | squared multiplied by the resistance. | ||
+ | <!-- | ||
\section{Assignment} | \section{Assignment} | ||
Create three worksheets - one each to solve the equations generated by | Create three worksheets - one each to solve the equations generated by |
Revision as of 20:51, 5 January 2014
Contents
Introduction
This page focuses on using Maple to find both the symbolic and the numeric solutions to equations obtained from electric circuits. It assumes that you have already taken the steps in Maple/Initialization and Documentation to start Maple and begin documenting your work.
Defining Variables and Equations
In Maple, the way you define a variable is by typing the name of the variable, followed by the symbols :=, followed by whatever items you want to store in the variable. Note the importance of the colon directly in front of the equals sign - without it, Maple will not assign a value to a variable but will merely print out the equation you typed. One benefit of this is you can define variables to hold on to equations and then use those variables later, in concert with Maple's solver, to get answers for the unknowns. Let us assume that we want to solve the following equations:
where x, y, and z are unknowns, a through i are known coefficients, and j through l are known variables. To teach Maple about these equations, you would create three variables, each holding on to one of the equations. At the prompt, type:
eqn1:=a*x+b*y+c*z=j
eqn2:=d*x+e*y+f*z=k
eqn3:=g*x+h*y+i*z=l
Note that each time you hit return to go to the next line, Maple processes your input and reports back what it has done. It will also number the outputs for you so you can refer to them later. At this point, Maple now has three variables, each of which defined as an equation. It is perfectly happy having undefined items in the equations.
Solving Equations With Maple
To solve the equations, all you need to do is use Maple's built in solve function. One of the best ways to use the solve function is to give it a list of the equations and an array of items for which to solve. In the equations above, for example, there are three equations with a total of fifteen symbols - we need to tell Maple which ones are unknown and it will assume that the others are known. Add the line:
solve({eqn1, eqn2, eqn3}, [x, y, z])
and note that the equations are bracketed with curly braces while the unknowns are in a list set off with square brackets. Hit return, and you will note that Maple produces a list - set off with double brackets - containing the answers for x, y, and z in terms of the other variables. If we had not included the variable list and instead had asked
solve({eqn1, eqn2, eqn3})
Maple would have given all possible combinations of all 15 symbols that would satisfy the equations. Conversely, if we had given Maple only x to work with as an unknown by typing:
solve({eqn1, eqn2, eqn3}, [x])
the answer would come back as empty because no value of x satisfies the three equations for arbitrary values of the other 14 variables.
In order to use these solutions, you should give them a name. Click at the start of the solve line and pre-pend it with MySoln:= so it resembles:
MySoln:=solve({eqn1, eqn2, eqn3}, [x, y, z])
This will assign the solution list to a variable that we can use later.
Substituting Values
Now that you have the symbolic answers to the variables x, y, and z, you may want to substitute the actual coefficient values to obtain a numerical solution. One way to do this is to generate a list of the known values, then tell Maple to substitute in the numerical values by using the built-in subs command. Add the following lines of code:
Vals := {a=-1, b=2, c=3, d=4, e=5, f=6, g=7, h=8, i=9, j=10, k=11, l=12}
subs(Vals, MySoln)
The list in MySoln will now be shown with numerical values instead of symbols. Note that you have not made any actual changes to any of the variables - you have just asked Maple to show you what they would look like given the particular substitutions presented in Vals. This is a very powerful tool, since you can substitute in a variety of values to see how one or more parameters influence a particular variable or variables.
Multiple and Dependent Substitution Lists
If you have several sets of equations you want to use for substitution
- including some which are dependent on values set in other equations,
you can still use subs
-- you just need to be careful about the
order of the substitutions. As an example, imagine some variable:
where
and
To get m in terms of r, s, t, and u, you could write:
MyEqn:=m=p+q;
SubsList1:=p=r*s, q=t-u;
subs(SubsList1, MyEqn);
If you want to get m's numerical value, you must first get m in terms of r, s, t, and u, and then you can substitute in the numbers for those variables. Specifically:
MyEqn:=m=p+q;
SubsList1:=p=r*s, q=t-u;
SubsList2:=r=1, s=2, t=3, u=4;
subs(SubsList1, SubsList2, MyEqn);
Putting the equations in the wrong order will end up yielding an
answer that is still in terms of r, s, t, and u. The reason
is that subs
only makes substitutions into the last entry
in the argument list.
Sometimes, you will need to take equations out of a set of brackets to use them. For example, assume that you have some variable you want to calculate called alpha, which has a formula of:
You can put in the solutions for x, y, and z to get alpha
in terms of those characters. What makes
this a bit difficult is that MySoln
is given as a
single-row matrix and subs
just wants the equations
themselves. To extract only the equations, you can write:
subs(MySoln[1][], Vals, ThingToSubInFor)
Go ahead and add the line
subs(MySoln[1][], Vals, alpha)
to the end of your worksheet.
Again - the order is important - you need to first substitute in the
equations for the variables higher in the dependency list, then give values to the
known quantities, then substitute all that into whatever is in the
final argument of subs
.
Run the entire script and make sure that \(\alpha\) is
\(\frac{1}{3}\) when everything gets substituted in.
Cleaning Things Up
Many times, Maple will produce an expression that is more complicated than it needs to be. To get what it considers to be the simplest form, use the simplify(expand( )) compound function. The expand will take the expression and represent it using as many simple terms as necessary while simplify will recombine them in the most compact form. Finally, to get a decimal value, use the evalf[N]( ) function, where N represents the number of decimal digits to use. For example,
simplify(expand(alpha))
will produce the most symbolically simplified version of \(\alpha\) while
evalf[8](subs(Vals, alpha))
will produce a floating point result for \(\alpha\). With practice, you
will see how best to combine evalf
, simplify
, and expand
to get the form of answer you want.
Memory Issues
A major issue to consider with Maple is its memory. At the end of the worksheet above, there are several variables that are defined, including x, y, and z. If you go back near the beginning, click in the line where eqn1 is defined, and hit return, you will notice that where x, y, and z were before, their symbolic solutions from much further down the worksheet are being used. This is why the restart command is so helpful - if you need to to run a worksheet again, it is best to always start from scratch. A shortcut for running an entire worksheet is the !!! button at the top of the window.