home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / calculat / sm30a.zip / SYMBMATH.H39 < prev    next >
Text File  |  1993-11-07  |  6KB  |  185 lines

  1.                 4.7    Solving Equations
  2.         4.7.1  Solving Algebraic Equations
  3.  
  4.     The equations can be operated (e.g. +, -, *, /, ^, expand(), 
  5. diff(), inte()). The operation is done on both sides of the equation, 
  6. as by hand. You can find roots of a polynomial, algebraic equations,
  7. systems of equations, differential and integral equations.
  8.     You can get the left side of the equation by
  9.         left(left_side = right_side)
  10. or get the right side by
  11.         right(left_side = right_side)
  12.         You can assign equations to variables.
  13.  
  14.         Example.
  15.  
  16. IN:  eq1:= x + y = 3
  17. IN:  eq2:= x - y = 1
  18. IN:  eq1+eq2
  19. OUT: 2 x = 4
  20. IN:  last/2
  21. OUT: x = 2
  22. IN:  eq1-eq2
  23. OUT: 2 y = 2
  24. IN:  last/2
  25. OUT: y = 1
  26.  
  27.     Example 4.7.1. 
  28.         Solve an equation sqrt(x+2*k) - sqrt(x-k) = sqrt(k),
  29. then check the solution by substituting the root into the equation.
  30.  
  31. IN:  eq1 := sqrt(x + 2*k) - sqrt(x - k) = sqrt(k)
  32. OUT: eq1 := sqrt(x + 2*k) - sqrt(x - k) = sqrt(k)
  33. IN:  eq1^2
  34. OUT: ((2*k + x)^0.5 - ((-k) + x)^0.5)^2 = k
  35. IN:  expand(last)
  36. OUT: 2*x + k + (-2)*(2*k + x)^0.5*((-k) + x)^0.5 = k
  37. IN:  last-k-2*x
  38. OUT: (-2)*(2*k + x)^0.5*((-k) + x)^0.5 = (-2)*x
  39. IN:  last/(-2)
  40. OUT: (2*k + x)^0.5*((-k) + x)^0.5 = x
  41. IN:  last^2
  42. OUT: (2*k + x)*((-k) + x) = x^2
  43. IN:  expand(last)
  44. OUT: (-2)*k^2 + k*x + x^2 = x^2
  45. IN:  last-x^2+2*k^2
  46. OUT: k*x = 2*k^2
  47. IN:  last/k
  48. OUT: x = 2*k
  49. IN:  subs(eq1, x = right(last))
  50. OUT: k^0.5 = k^0.5
  51.  
  52.     You can solve algebraic equations step by step, as above.
  53. This method is useful in teaching, e.g. showing students how to solve
  54. equations.
  55.  
  56.                 4.7.2  Solve()
  57.     The solve() functions
  58.          
  59.         solve(expr1 = expr2, x)
  60.         solve([expr1 = expr2, expr3 = expr4], [x, y])
  61.  
  62. solve a polynomial and systems of linear equations on one step.
  63. It is recommended to set the switch expand:=on when solve the 
  64. complicated equations. All of the real and complex roots of the 
  65. equation will be found by solve(). The function solve() outputs a 
  66. list of roots when there are multi-roots. You can get one of roots 
  67. from the list, (see Chapter 4.9 Arrays, Lists, Vectors and Matrices).
  68.      Shareware version has not this solve() function.
  69.  
  70.     Example 4.7.2. 
  71.         Solve a+b*x+x^2 = 0 for x, save the root to x.
  72.  
  73. IN:  solve(a+b*x+x^2 = 0, x)    # solve or re-arrange the equation for x
  74. OUT: x = [-b/2 + sqrt((b/2)^2 - a),  -b/2 - sqrt((b/2)^2 - a)]
  75. IN:  x := right(last)           # assign two roots to x
  76. OUT: x := [-b/2 + sqrt((b/2)^2 - a),  -b/2 - sqrt((b/2)^2 - a)]
  77. IN:  x[1]                       # the first root
  78. OUT: -b/2 + sqrt((b/2)^2 - a)
  79. IN:  x[2]                       # the second root
  80. OUT: -b/2 - sqrt((b/2)^2 - a)
  81.  
  82.     Example 4.7.3. 
  83.         Solve x^3 + x^2 + x + 5 = 2*x + 6.
  84.  
  85. IN:  num(solve(x^3+x^2+x+5 = 2*x+6, x))
  86. OUT: x = [1, -1, -1]
  87.  
  88.     The function solve() not only solves for a simple variable x
  89. but also solves for an unknown function, e.g. ln(x).
  90.  
  91.     Example 4.7.4. 
  92.         Solve the equation for ln(x).
  93.  
  94. IN:  solve(ln(x)^2+5*ln(x) = -6, ln(x))
  95. OUT: ln(x) = [-2, -3]
  96. IN:  exp(last)
  97. OUT: x = [exp(-2), exp(-3)]
  98.  
  99.     Example 4.7.5. 
  100.         Rearrange the equations.
  101.  
  102. IN:  eq := [x+y = 3+a+b, x-y = 1+a-b]      # assign equations to eq
  103. IN:  solve(eq, [x,y])         # rearrange eq for x and y
  104. OUT: [x = -1/2*(-4 - 2 a), y = -1/2*(-2 - 2 b)]
  105. IN:  solve(eq, [a,b])         # rearrange eq for a and b
  106. OUT: [a = -1/2*(4 - 2 x), b = -1/2*(2 - 2 y)]
  107. IN:  solve(eq, [a,y])         # rearrange eq for a and y
  108. OUT: [b = -1/2*(2 - 2 y), x = -1/2*(-4 - 2 a)]
  109. IN:  solve(eq, [x,b])         # rearrange eq for x and b
  110. OUT: [a = 1/2*(-4 + 2 x), y = 1/2*(2 + 2 b)]
  111.  
  112.                 4.7.3  Polynomial Sovler: PSolve()
  113.         The external function
  114.                 psolve(f(x), x)
  115. solves f(x)=0 for x. It is similar to solve(), but it only can solve
  116. polynomial with order < 3.
  117.  
  118.         4.7.4  Numeric Solver: NSolve()
  119.     The external functions 
  120.                 nsolve(f(x) = x, x)
  121.         nsolve(f(x) = x, x,x0)
  122. numericly solves an algebraic equation with an initial value x0. By
  123. default x0=1. nsolve() only gives one solution near x0, omitting other
  124. solutions.
  125.  
  126.     Example 4.7.4.1. 
  127. IN:  nsolve( cos(x) = x, x)
  128. OUT: x = 0.73911289091
  129. IN:  nsolve( sin(x) = 0, x,0)    # similar to asin( sin(x)=0 )
  130. OUT: x = 0                       # only gives one solution near x0=0
  131. IN:  nsolve( sin(x) = 0, x,3)
  132. OUT: x = 3.14                    # only gives one solution near x0=3
  133.  
  134.         4.7.5  Solving Differential Equations
  135.     You can solve the differential equations:
  136.         y'(x) = f(x)
  137. by integrating the equation.
  138.     y'(x) is the same as d(y(x),x).
  139.     
  140.     Example: 4.7.4.1
  141.         solve y'(x)=sin(x) by integral.
  142. IN:  inte( y'(x) = sin(x), x)
  143. OUT: y(x) = constant - cos(x)
  144.  
  145.                4.7.6  Differential Solver: DSolve()
  146.     The external function 
  147.         dsolve(y'(x) = f(x,y), y(x), x)
  148. can solve the first order variables separable and linear differential 
  149. equations
  150.         y'(x) = h(x)
  151.         y'(x) = f(y(x))
  152.         y'(x) = f(y(x))*x
  153.         y'(x) = g(x)*y(x)
  154.         y'(x) = g(x)*y(x)+h(x)
  155. on one step. Notice that y'(x) must be alone on the left hand
  156. side of the equation. It is recommended to set the switch 
  157. expand:=on when solving the complicated differential equations.
  158.  
  159.     Example 4.7.6.1 
  160.         Solve y'(x) = sin(x) by dsolve().
  161. IN:  dsolve( y'(x) = sin(x), y(x), x)
  162. OUT: y(x) = constant - cos(x)
  163.  
  164.     Example 4.7.6.2 
  165.         Solve differential equations by dsolve(). If the result is a
  166. polynomial, then rearrange the equation by solve().
  167.  
  168. IN:  dsolve(y'(x) = x/(2+y(x)), y(x), x)
  169. OUT: 2*y(x) + 1/2*y(x)^2 = constant + x^2
  170. IN:  solve(last, y(x))
  171. OUT: y(x) = [-2 + sqrt(4 - 2*(-constant - x^2)),
  172.          -2 - sqrt(4 - 2*(-constant - x^2))]
  173.  
  174.     Example 4.7.6.3 
  175.         Solve differential equations by dsolve().
  176.  
  177. IN:  dsolve(y'(x) = x*exp(y(x)), y(x), x)
  178. OUT: -e^(-y(x)) = constant + x^2
  179. IN:  dsolve(y'(x) = y(x)^2+5*y(x)+6, y(x), x)
  180. OUT: ln((4 + 2 y(x))/(6 + 2 y(x))) = constant + x
  181. IN:  dsolve(y'(x) = y(x)/x, y(x), x)
  182. OUT: y(x) = constant x sign(x)
  183. IN:  dsolve(y'(x) = y(x)*x+1, y(x), x)
  184. OUT: y(x) = exp(1/2 x^2) (constant + sqrt(1/2) sqrt(pi) erf(sqrt(1/2) x))
  185.