Page 205 - Applied Numerical Methods Using MATLAB
P. 205
194 NONLINEAR EQUATIONS
numerical solutions. One of them is “solve()”, which can be used for obtaining the
symbolic or numeric roots of equations. According to what we could see by typing
‘help solve’ into the MATLAB command window, its usages are as follows:
>>solve(’p*sin(x) = r’) %regarding x as an unknown variable and p as a parameter
−1
ans = asin(r/p) %sin (r/p)
>>[x1,x2] = solve(’x1^2 + 4*x2^2-5= 0’,’2* x 1^2 - 2*x1 - 3*x2-2.5 = 0’)
x1 = [ 2.] x2 = [ 0.500000]
[ -1.206459] [ 0.941336]
[0.603229 -0.392630*i] [-1.095668 -0.540415e-1*i]
[0.603229 +0.392630*i] [-1.095668 +0.540415e-1*i]
>>S = solve(’x^3 - y^3 = 2’,’x = y’) %returns the solution in a structure.
S = x: [3x1 sym]
y: [3x1 sym]
>>S.x
ans = [ 1]
[ -1/2+1/2*i*3^(1/2)]
[ -1/2-1/2*i*3^(1/2)]
>>S.y
ans = [ -1]
[ 1/2 - 1/2*i*3^(1/2)]
[ 1/2 + 1/2*i*3^(1/2)]
>>[u,v] = solve(’a*u^2 + v^2 = 0’,’u - v = 1’)%regarding u,v as unknowns and a as a parameter
u = [1/2/(a + 1)*(-2*a + 2*(-a)^(1/2)) + 1] v = [1/2/(a + 1)*(-2*a + 2*(-a)^(1/2))]
[1/2/(a + 1)*(-2*a - 2*(-a)^(1/2)) + 1] [1/2/(a + 1)*(-2*a - 2*(-a)^(1/2))]
>>[a,u] = solve(’a*u^2 + v^2’,’u-v = 1’,’a,u’) %regards only v as a parameter
a = -v^2/(v^2 + 2*v + 1) u=v+1
Note that in the case where the routine “solve()” finds the symbols more
than the equations in its input arguments—say, M symbols and N equations with
M> N —it regards the N symbols closest alphabetically to ‘x’ as variables and
the other M − N symbols as constants, giving the priority of being a variable to
the symbol after ‘x’ than to one before ‘x’ for two symbols that are at the same
distance from ‘x’. Consequently, the priority order of being treated as a symbolic
variable is as follows:
x > y > w > z > v > u > t > s > r > q > ···
Actually, we can use the MATLAB built-in function “findsym()”tosee the
priority order.
>>symsxyzqrstuvw %declare 10 symbols to consider
>>findsym(x+y+ z*q*r + s + t*u-v- w,10) %symbolic variables?
ans = x,y,w,z,v,u,t,s,r,q
4.8 A REAL-WORLD PROBLEM
Let’s see the following example.
Example 4.3. The Orbit of NASA’s “Wind” Satellite. One of the previous NASA
plans is to launch a satellite, called Wind, which is to stay at a fixed position
along a line from the earth to the sun as depicted in Fig. 4.7 so that the solar
wind passes around the satellite on its way to earth. In order to find the distance