Symbolic Math Toolbox |
 |
Solving Equations
Solving Algebraic Equations
If S
is a symbolic expression,
solve(S)
attempts to find values of the symbolic variable in S
(as determined by findsym
) for which S
is zero. For example,
syms a b c x
S = a*x^2 + b*x + c;
solve(S)
uses the familiar quadratic formula to produce
ans =
[1/2/a*(-b+(b^2-4*a*c)^(1/2))]
[1/2/a*(-b-(b^2-4*a*c)^(1/2))]
This is a symbolic vector whose elements are the two solutions.
If you want to solve for a specific variable, you must specify that variable as an additional argument. For example, if you want to solve S
for b
, use the command
b = solve(S,b)
which returns
b =
-(a*x^2+c)/x
Note that these examples assume equations of the form f(x) = 0. If you need to solve equations of the form f(x) = q(x), you must use quoted strings. In particular, the command
s = solve('cos(2*x)+sin(x)=1')
returns a vector with four solutions.
s =
[ 0]
[ pi]
[ 1/6*pi]
[ 5/6*pi]
| Eigenvalue Trajectories | | Several Algebraic Equations |  |