Symbolic Math Toolbox | ![]() ![]() |
Several Algebraic Equations
Now let's look at systems of equations. Suppose we have the system
and we want to solve for x and y. First create the necessary symbolic objects.
There are several ways to address the output of solve
. One is to use a two-output call
Consequently, the solution vector
appears to have redundant components. This is due to the first equation , which has two solutions in x and y:
,
. Changing the equations to
produces four distinct solutions:
x = [ 1/2*alpha+1/2*(alpha^2+2)^(1/2)] [ 1/2*alpha-1/2*(alpha^2+2)^(1/2)] [ 1/2*alpha+1/2*(alpha^2-2)^(1/2)] [ 1/2*alpha-1/2*(alpha^2-2)^(1/2)] y = [ -alpha+(alpha^2+2)^(1/2)] [ -alpha-(alpha^2+2)^(1/2)] [ -alpha+(alpha^2-2)^(1/2)] [ -alpha-(alpha^2-2)^(1/2)]
Since we did not specify the dependent variables, solve
uses findsym
to determine the variables.
This way of assigning output from solve
is quite successful for "small" systems. Plainly, if we had, say, a 10-by-10 system of equations, typing
is both awkward and time consuming. To circumvent this difficulty, solve
can return a structure whose fields are the solutions. In particular, consider the system u^2-v^2 = a^2
, u + v = 1
, a^2-2*a = 3
. The command
The solutions for a
reside in the "a
-field" of S
. That is,
Similar comments apply to the solutions for u
and v
. The structure S
can now be manipulated by field and index to access a particular portion of the solution. For example, if we want to examine the second solution, we can use the following statement
to extract the second component of each field.
whose rows comprise the distinct solutions of the system.
Linear systems of simultaneous equations can also be solved using matrix division. For example,
Thus s
and z
produce the same solution, although the results are assigned to different variables.
![]() | Solving Equations | Single Differential Equation | ![]() |