CHAPTER 5

image

Equations and Systems

MATLAB offers certain commands that allow you to solve equations and systems. Among them are the following:

  • solve('equation','x') solves the equation in the variable x.
  • syms x; solve(equ(x),x) solves the equation equ(x)in the variable x.
  • solve('eq1,eq2,...,eqn','x1,x2,...,xn') solves n simultaneous equations eq1,. . .,eqn (in the variables x1,. . ., xn).
  • syms x1 x2 ... xn; solve(eq1,eq2,...,eqn,x1,x2,...,xn) solves n simultaneous equations eq1,...,eqn (in the variables x1,..., xn).
  • X = linsolve(A,B) solves A * X = B for a square matrix A, where B and X are matrices.
  • x = nnls(A,b) solves A * x = b in the least-squares sense, where x is a vector (x≥0).
  • x = lscov(A,b,V) gives  the vector x that minimizes (A * x-b)'* inv(V) *(A*x-b).
  • roots(V) gives the roots of the polynomial whose coefficients are the components of the vector V.
  • X = AB solves the system A * X = B.
  • X = a/b solves the system X * A = B.

5-1. Special Commands

In addition, equations and systems can be solved using the following commands (all of them must be preceded by the maple command):

  • solve(equation,variable) solves the given equation in the specified variable.
  • solve(expression,variable) solves the equation expression = 0 in the given variable.
  • solve({expr1,..,exprn},{var1,..,varn}) solves the system given by the specified equations in the given variables.
  • solve(equation) solves the equation for all of its variables.
  • solve(expr1,...,exprn) solves the specified system of equations for all possible variables.
  • solve(inequality,variable) solves the inequality for the specified variable.
  • solve(s,var) solves the set of equations s for the specified variable.
  • LHS(equation) returns the left-hand side of the equation.
  • LHS(inequality) returns the left-hand side of the inequality.
  • RHS(equation) returns the right-hand side of the equation.
  • RHS(inequality) returns the right-hand side of the inequality.
  • readlib(isolate): isolate(equation,expression) isolates the specified expression in the given equation.
  • readlib(isolate): isolate(expr1,expr2) isolates the subexpression expr2 in the equation expr1 = 0.
  • reablib(isolate): isolate(equation,expression,n) isolates the specified expression in the given equation by running at least n transformations or steps in the calculations.
  • testeq(expr1=expr2) or testeq(expr1,expr2) tests whether the expressions are equivalent. The purpose may be to eliminate redundant equations in a system.
  • eliminate(setequ,setvar) eliminates the given set of variables in the specified set of equations.
  • isolve(equation) returns the set of integer solutions of the given equation for all of its variables.
  • isolve(expression) returns the set of integer solutions of the equation expression = 0 for all of its variables.
  • isolve({equ1,..,equn}) gives the set of integer solutions of the specified system of equations for all variables.
  • isolve(equation,variable) returns the integer solutions of the specified equation in the given variable.
  • isolve({equ1,...,equn},{var1,...,varn}) finds the integer solutions of the specified system in the given variables.
  • isolve(equation,{var1,...,varn}) finds the set of integer solutions of the given equation for the specified variables.
  • fsolve(equation,variable) solves the equation for the given variable, by Newton’s method.
  • fsolve(expression,variable) solves the equation expression = 0 for the given variable, by Newton’s method.
  • fsolve({equ1,...,equn},{var1,...,varn}) solves the system of equations for the variables given, by numerical methods (the number of equations is equal to the number of unknowns).
  • fsolve(expr) or fsolve({equ1,...,equn}) solves the equation expr = 0 or the system of equations in the given variables by numerical methods.
  • fsolve(equation,var,a..b) solves the equation in the variable var by numerical methods, obtaining solutions in the interval [a,b].
  • fsolve({equ1,...,equn},{var1,...,varn},{var1=a1..B1,..., varn=an...BN}) finds real solutions of the system in the given variables that are in the specified intervals (by numerical methods).
  • fsolve(equation,variable,complex) finds all the complex solutions of the given equation.
  • fsolve(equation,variable,'maxsols'=m) finds only the m least solutions of the equation.
  • fsolve(equation,variable,'fulldigits') ensures an optimum value of digits for computing the largest number of possible solutions of the given equation in the specified variable.
  • msolve(equation,m) solves the equation modulo m in all its variables.
  • msolve(expression,m) solves the equation expression = 0 modulo m in all its variables.
  • msolve({equ1,...,equn},m) solves the given system modulo m in all its variables.
  • msolve(equation,variable,m) or msolve(equation,{var1,...,varn},m) solves the equation modulo m in the variable or variables specified.
  • msolve({equ1,...,equn},{var1,...,varn},m) solves the given system modulo m in the specified variables.
  • RootOf(Equation,variable) represents the roots of the given equation in the variable given in the form of RootOf expressions. The solution of certain transcendental equations and systems are usually given in terms of RootOf expressions.
  • RootOf(expression,variable) presents the solutions of the equation expression = 0 in terms of RootOf expressions.
  • RootOf(equation) presents in the form of RootOf expressions the solutions of the given univariate equation.
  • allvalues(expr) gives all the possible values of the specified RootOf expression. This command uses solve to calculate the exact roots of the expression, and if this is not possible, uses fsolve to calculate the approximate roots.
  • allvalues(expr,d) ensures that identical RootOfs in the expression are only evaluated once, thus avoiding redundant calculations and increasing efficiency.
  • convert(ineq,equality) converts the given inequality to an equality by replacing the signs < or < = by =.
  • convert(equ,lessequal) converts the given equation or strict inequality into a non-strict inequality, by replacing < or = with < =.
  • convert(equ,lessthan) converts the equation or non-strict inequality into the corresponding strict inequality, replacing the symbols = or < = with the symbol <.
  • with(student):equate(list1,list2) creates a set of equations of the form (list1[1] = list2[1],...,list1[n] = list2[n]).
  • equate(list) creates set of equations of the form {list[1] = 0,..., list[n] = 0}.
  • equate(array1,array2) converts the two arrays to a set of equations.
  • equate(Table1,Table2) converts the two tables to a set of equations.
  • equate(expr1,expr2) converts the two expressions to the equation expr1 = expr2.

Here are some examples. First, we solve an equation in exact and approximate form and check one of the solutions.

>> pretty(sym(maple('eq := x^4-5*x^2+6*x=2: solve(eq,x)')))
      1/2        1/2
-1 + 3   , -1 - 3   , 1, 1
>> pretty(sym(maple('sols := [solve(eq,x)] : evalf(sols,10)')))
[.732050808    -2.732050808    1.    1.]
>> pretty(simple(sym(maple('subs(x=sols[1],eq )'))))
2 = 2

The previous equation also can be solved as follows:

>> solve('x^4-5*x^2+6*x=2')
ans =

[- 1 + 3 ^(1/2)]
[^(1/2) - 1-3]
[          1]
[          1]

Another way to solve the same equation would be as follows:

>> syms x
>> solve(x^4-5*x^2+6*x-2)
ans =

[- 1 + 3 ^(1/2)]
[^(1/2) - 1-3]
[          1]
[          1]

Next we solve a system and check its solutions.

>> maple('eqns:= {u+v+w=1, 3*u+v=3, u-2*v-w=0}:sols:= solve(eqns)')
ans =
sols := {w = -2/5, v = 3/5, u = 4/5}
>> maple('subs(sols,eqns)')
ans =
{1 = 1, 0 = 0, 3 = 3}

The previous system can also be solved in the following way:

>> syms u v w
>> [u,v,w] = solve(u+v+w-1, 3*u+v-3, u-2*v-w, u, v, w)
u =

4/5

v =

3/5

w =

-2/5

The same system can also be solved in another way:

>> [u,v,w] = solve('u+v+w=1', '3*u+v=3', 'u-2*v-w=0', 'u','v','w')
u =

4/5

 v =

3/5

 w =

-2/5

Finally, we can solve the system in the following way:

>> [u,v,w] = solve('u+v+w=1, 3*u+v=3, u-2*v-w=0', 'u,v,w')
u =

4/5

 v =

3/5

 w =

-2/5

Next we solve some systems, subject to certain conditions.

>> pretty(sym(maple('solve({x^2*y^2=0, x-y=1})')))
   {x = 0, y = - 1}, {x = 0, y = - 1}, {x = 1, y = 0}, {x = 1, y = 0}
>> pretty(sym(maple('solve({x^2*y^2=0, x-y=1, x<>0})')))
                    {x = 1, y = 0}, {x = 1, y = 0}
>> pretty(sym(maple('solve({x^2*y^2-b, x^2-y^2-a},{x,y})')))
>> pretty(sym(maple('solve({x^2*y^2-b, x^2-y^2-a},{x,y})')))
{y = 1/2 %4, x = 1/2 %3}, {y = 1/2 %4, x = - 1/2 %3},

    {y = - 1/2 %4, x = 1/2 %3}, {y = - 1/2 %4, x = - 1/2 %3},

    {y = 1/2 %1, x = 1/2 %2}, {x = - 1/2 %2, y = 1/2 %1},

    {y = - 1/2 %1, x = 1/2 %2}, {x = - 1/2 %2, y = - 1/2 %1}

                  2       1/2 1/2
%1 := (-2 a - 2 (a  + 4 b)   )

                 2       1/2 1/2
%2 := (2 a - 2 (a  + 4 b)   )

                 2       1/2 1/2
%3 := (2 a + 2 (a  + 4 b)   )

                  2       1/2 1/2
%4 := (-2 a + 2 (a  + 4 b)   )

Next we find the integer solutions of an equation:

>> pretty(sym(maple('isolve(3*x-4*y=7)')))
                    {y = 2 + 3 _N1, x = 5 + 4 _N1}

Now we solve system and an equation approximately.

>> maple('f: = sin(x + y) - exp(x) * y = 0: ' g: = x ^ 2 - y = 2:'),
>> pretty(sym(maple('fsolve({f,g},{x,y},{x=-1..1,y=-2..0})')))
                 {y = -1.552838698, x = -.6687012050}
>> maple('f:=10-(ln(v+(v^2-1)^(1/2))-ln(3+(3^2-1)^(1/2)))'),
>> pretty(sym(maple('fsolve(f,v)')))
                             64189.82535
>> pretty(sym(maple('fsolve(f,v,1..infinity)')))
                            64189.82535

In the two following equations, instead of solving for x, we solve for sin(x) in the first and x2 in the second.

>> pretty(sym(maple('readlib(isolate):isolate(4*x*sin(x)=3,sin(x))')))
                           sin(x) = 3/4 x
>> pretty(sym(maple('isolate(x^2-3*x-5,x^2)')))
                              2
                             x = 3 x + 5

Now we test whether two expressions are not equal but probabilistically equivalent.

>> maple('a: = (sin(x) ^ 2 - cos(x) * tan(x)) * (sin(x) ^ 2 + cos(x) * tan(x)) ^ 2:)
          b: = 1/4 * sin(2*x) ^ 2 - 1/2 * sin(2*x) * cos(x) - 2 * cos(x) ^ 2
               (+ 1/2 * sin(2*x) * cos(x) ^ 3 + 3 * cos(x) ^ 4 - cos(x) ^ 6:'),
>> pretty(sym(maple('evalb(a = b)')))
                               false
>> pretty(sym(maple('evalb(expand(a) = expand(b))')))
                                false
>> pretty(sym(maple('testeq(a = b)')))
                                true

In the following example, we eliminate a variable from a system:

>> pretty(sym(maple('readlib(eliminate):eliminate({x^2+y^2-1,x^3-y^2*x+x*y-3},x)')))
              3             6      4      5      3      2
 [{x = - ------------}, {4 y  - 7 y  - 4 y  + 6 y  + 4 y  - 2 y + 8}]
            2
         2 y  - y – 1

EXERCISE 5-1

Find solutions to the following equations:

sin(x) cos(x) = 0, sin(x) = acos(x), ax ^ 2 + bx + c = 0 and sin(x) + cos(x) = sqrt(3) / 2

>> solve('sin(x) * cos(x) = 0')

ans =

[       0]
[1/2 * pi]
[-1/2 * pi]

>> solve('sin(x) = a * cos(x)','x')

ans =

atan (a)

>> solve('a*x^2+b*x+c=0','x')

ans =

[1/2/a * (-b + (b ^ 2-4 * a * c) ^(1/2))]
[1/2/a * (-b-(b^2-4*a*c) ^(1/2))]

>> solve('sin(x)+cos(x)=sqrt(3)/2')

ans =

[1/2 * 3 ^(1/2)]
[1/2 * 3 ^(1/2)]

EXERCISE 5-2

Find at least two solutions for each of the following trigonometric and exponential equations:

x sin (x) = 1/2 and 2x ^ 3 = 4 (23 x)

Initially, we use the fsolve command:

>> maple ('fsolve(x * sin(x) = 1/2)')

ans =
-.74084095509549062101093540994313

>> maple('fsolve(2^(x^3)=4*2^(3*x))')

ans =
2.0000000000000000000000000000000

For both equations we get a single solution. For more solutions, we can plot a graphical representation of the functions (see Figure 5-1) to determine the approximate intervals where possible solutions fall:

>> fplot('[x * sin (x) - 1/2.0]', [0, 4 * pi])

We can see that there is a solution between 0 and 2, another between 2 and 4, another between 4 and 8, and so on. We can calculate three of them as follows:

>> (('s1=maple('fsolve(x*sin(x)=1/2,x,0..2)')

s1 =
.7408409550954906

>> s2=maple('fsolve(x*sin(x)=1/2,x,2..4)')

s2 =
2.972585490382360

>> s3=maple('fsolve(x*sin(x)=1/2,x,4..8)')

S3 =
6.361859813361645

We repeat the process for the second equation, starting with the plotted graph (see Figure 5-2):

>> subplot(2,1,1)
>> fplot('[2^(x^3),4*2^(3*x)]',[-3,1,-1/4,3/2])
>> subplot(2,1,2)
>> fplot('[2^(x^3),4*2^(3*x)]',[1,3,100,400])

Two areas where there are intersections for different values of the variables x and y have been represented on the same graph. There are possible solutions between –4 and 0, and between 0 and 3. We try to find these solutions:

>> maple('fsolve(2 ^(x^3) = 4 * 2 ^(3*x), x, -4.. 0)')

ans =

-1.00000000000

>> maple('fsolve(2^(x^3)=4*2^(3*x),x,0..3)')

ans =

2.00000000000

We see that x =-1 and x = 2 are exact solutions of the equation.

EXERCISE 5-3

Solve each of the two following logarithmic and surd equations:

x3/2 log(x) = x log(x3/2), sqrt[1-x]+sqrt[1+x] = a

>> maple('fsolve(x^(3/2)*log(x)=x*log(x)^(3/2))')

ans =

1.

We first generate the corresponding graphs (see Figure 5-3) to determine the intervals in which possible solutions are found. This reveals that x = 1 is the only real solution.

>> fplot('[x^(3/2) * log(x), x * log(x^(3/2))]', [0,3,-1,6])

Now, let's solve the surd equation:

>> pretty(sym(solve('sqrt(1-x)+sqrt(1+x)=a','x')))

                                        2     1/2
                            [- 1/2 a (-a  + 4)   ]
                            [                    ]
                            [          2     1/2 ]
                            [1/2 a (-a  + 4)    ]

EXERCISE 5-4

Solve the following two equations:

x5 + 16 x4+ 7 x3+ 17 x2+ 11 x + 5 = 0 and x4 - 1 = 0

In addition, solve the first equation modulo 19 and the second modulo 5.

>> s1=solve('x^5 +16*x^4+7*x^3+17*x^2+11*x+5=0')

[                    -15.61870451719182]
[-.3867059805744952-.3977796861292117*i]
[-.3867059805744952+.3977796861292117*i]
[.1960582391704047-1.000858165543796*i]
[.1960582391704047+1.000858165543796*i]

>> s2=solve('x^4-1=0')

s2 =

[1]
[-1]
[i]
[-i]

Now, we solve the first equation modulo 19:

>> maple('msolve(x^5 +16*x^4+7*x^3+17*x^2+11*x+5=0,19)')

ans =

{x = 1}, {x = 18}, {x = 3,} {x = 7}, {x = 12}

Next, we solve the second equation modulus 5:

>> maple('msolve(x^4-1=0,5)')

ans =

{x = 1}, {x = 2}, {x = 3}, {x = 4}

Because we have two polynomial equations, there is also the option of solving the two equations with the roots command, as shown here:

>> roots([5,11,17,7,16,5])
ans =

  -1.2183 + 1.3164i
  -1.2183 - 1.3164i
   0.2827 + 0.9302i
   0.2827 - 0.9302i
  -0.3289

>> roots([-1,0,0,0,1])

ans =

  -1.0000
   0.0000 + 1.0000i
   0.0000 - 1.0000i
   1.0000

EXERCISE 5-5

Solve the following system of two equations:

cos(x/12) /exp(x2/16) = y

-5/4 + y = sin(x3/2)

>> [x,y] = solve('cos(x/12)/exp(x^2/16) = y','- 5/4 + y = sin(x^(3/2))')

x =

2.412335896593778

y =

.6810946557469383

EXERCISE 5-6

Find the intersection of the hyperbolas of equations x2 - y2= r2 and a2x2- b2y2= a2b2 with the parabola z2 = 2px.

>> [x,y,z] = solve('a^2*x^2-b^2*y^2=a^2*b^2','x^2-y^2=r^2','z^2=2*p*x', 'x,y,z')

x =

[1/2*RootOf((a^2-b^2)*_Z^4+4*b^2*r^2*p^2-4*a^2*b^2*p^2)^2/p]
[1/2*RootOf((a^2-b^2)*_Z^4+4*b^2*r^2*p^2-4*a^2*b^2*p^2)^2/p]

y =

[1/2*(RootOf((a^2-b^2)*_Z^4+4*b^2*r^2*p^2-4*a^2*b^2*p^2)^4-4*r^2*p^2)^(1/2)/p]
[-1/2*(RootOf((a^2-b^2)*_Z^4+4*b^2*r^2*p^2-4*a^2*b^2*p^2)^4-4*r^2*p^2)^(1/2)/p]

z =

[RootOf((a^2-b^2)*_Z^4+4*b^2*r^2*p^2-4*a^2*b^2*p^2)]
[RootOf((a^2-b^2)*_Z^4+4*b^2*r^2*p^2-4*a^2*b^2*p^2)]

Now, we simplify the RootOf expressions in the above solutions:

>> [simple(allvalues(x)), simple(allvalues(y)), simple(allvalues(z))]

ans =

[b*(-r^2+a^2) ^(1/2) /(a^2-b^2) ^(1/2) b]  [a *(b^2-r^2) ^(1/2) /(a^2-b^2) ^(1/2)]  [2 ^(1/2) * b ^(1/2) * p ^(1/2) *(-r^2+a^2) ^(1/4) /(a^2-b^2) ^(1/4)]
[b*(-r^2+a^2) ^(1/2) /(a^2-b^2) ^(1/2) b]  [a *(b^2-r^2) ^(1/2) /(a^2-b^2) ^(1/2)]  [- 2 ^(1/2) * b ^(1/2) * p ^(1/2) *(-r^2+a^2) ^(1/4) /(a^2-b^2) ^(1/4)]
[-b *(-r^2+a^2) ^(1/2) /(a^2-b^2) ^(1/2)]  [a *(b^2-r^2) ^(1/2) /(a^2-b^2) ^(1/2)]  [i * 2 ^(1/2) * b ^(1/2) * p ^(1/2) *(-r^2+a^2) ^(1/4) /(a^2-b^2) ^(1/4)]
[-b*(-r^2+a^2)^(1/2)/(a^2-b^2)^(1/2)]  [a*(b^2-r^2)^(1/2)/(a^2-b^2)^(1/2)]  [-i*2^(1/2)*b^(1/2)*p^(1/2)*(-r^2+a^2)^(1/4)/(a^2-b^2)^(1/4)]
[b*(-r^2+a^2)^(1/2)/(a^2-b^2)^(1/2)]  [-a*(b^2-r^2)^(1/2)/(a^2-b^2)^(1/2)]  [2^(1/2)*b^(1/2)*p^(1/2)*(-r^2+a^2)^(1/4)/(a^2-b^2)^(1/4)]
[b*(-r^2+a^2)^(1/2)/(a^2-b^2)^(1/2)]  [-a*(b^2-r^2)^(1/2)/(a^2-b^2)^(1/2)]  [-2^(1/2)*b^(1/2)*p^(1/2)*(-r^2+a^2)^(1/4)/(a^2-b^2)^(1/4)]
[-b*(-r^2+a^2)^(1/2)/(a^2-b^2)^(1/2)]  [-a*(b^2-r^2)^(1/2)/(a^2-b^2)^(1/2)]  [i*2^(1/2)*b^(1/2)*p^(1/2)*(-r^2+a^2)^(1/4)/(a^2-b^2)^(1/4)]
   [-b*(-r^2+a^2)^(1/2)/(a^2-b^2)^(1/2)]  [-a*(b^2-r^2)^(1/2)/(a^2-b^2)^(1/2)]      [-i*2^(1/2)*b^(1/2)*p^(1/2)*(-r^2+a^2)^(1/4)/(a^2-b^2)^(1/4)]

Each line of this output (a set of three values) is a solution of the system, that is, a point of intersection of the three curves.

EXERCISE 5-7

Solve the inequality x2 + x > 5.

>> maple('solve(x^2+x>5,x)')

ans =

RealRange(-inf,Open(-1/2-1/2*21^(1/2))),RealRange(Open(-1/2+1/2*21^(1/2)),inf)

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset