Graphics Programs Reference
In-Depth Information
1
±
√
5. To get numerical solutions, type
double(ans)
,or
vpa(ans)
to dis-
play more digits.
The command
solve
can solve higher-degree polynomial equations, as well
as many other types of equations. It can also solve equations involving more
thanonevariable.Iftherearefewerequationsthanvariables,youshouldspec-
ify(asstrings)whichvariable(s)tosolvefor.Forexample,type
solve('2*x -
log(y) = 1', 'y')
to solve 2
x
−
log
y
=
1 for
y
in terms of
x
. You can
specify more than one equation as well. For example,
>> [x, y] = solve('xˆ2-y=2','y-2*x=5')
x=
[ 1+2*2^(1/2)]
[ 1-2*2^(1/2)]
y=
[ 7+4*2^(1/2)]
[ 7-4*2^(1/2)]
This system of equations has two solutions. MATLAB reports the solution by
giving the two
x
values and the two
y
values for those solutions. Thus the first
solution consists of the first value of
x
together with the first value of
y
.You
can extract these values by typing
x(1)
and
y(1)
:
>> x(1)
ans =
1+2*2^(1/2)
>> y(1)
ans =
7+4*2^(1/2)
The second solution can be extracted with
x(2)
and
y(2)
.
Note that in the preceding
solve
command, we assigned the output to the
vector
[x, y]
. If you use
solve
on a system of equations without assigning
theoutputtoavector,thenMATLABdoesnotautomaticallydisplaythevalues
of the solution:
>> sol = solve('xˆ2-y=2','y-2*x=5')
Search WWH ::
Custom Search