home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS - Coast to Coast
/
simteldosarchivecoasttocoast2.iso
/
calculat
/
sm30a.zip
/
SYMBMATH.H39
< prev
next >
Wrap
Text File
|
1993-11-07
|
6KB
|
185 lines
4.7 Solving Equations
4.7.1 Solving Algebraic Equations
The equations can be operated (e.g. +, -, *, /, ^, expand(),
diff(), inte()). The operation is done on both sides of the equation,
as by hand. You can find roots of a polynomial, algebraic equations,
systems of equations, differential and integral equations.
You can get the left side of the equation by
left(left_side = right_side)
or get the right side by
right(left_side = right_side)
You can assign equations to variables.
Example.
IN: eq1:= x + y = 3
IN: eq2:= x - y = 1
IN: eq1+eq2
OUT: 2 x = 4
IN: last/2
OUT: x = 2
IN: eq1-eq2
OUT: 2 y = 2
IN: last/2
OUT: y = 1
Example 4.7.1.
Solve an equation sqrt(x+2*k) - sqrt(x-k) = sqrt(k),
then check the solution by substituting the root into the equation.
IN: eq1 := sqrt(x + 2*k) - sqrt(x - k) = sqrt(k)
OUT: eq1 := sqrt(x + 2*k) - sqrt(x - k) = sqrt(k)
IN: eq1^2
OUT: ((2*k + x)^0.5 - ((-k) + x)^0.5)^2 = k
IN: expand(last)
OUT: 2*x + k + (-2)*(2*k + x)^0.5*((-k) + x)^0.5 = k
IN: last-k-2*x
OUT: (-2)*(2*k + x)^0.5*((-k) + x)^0.5 = (-2)*x
IN: last/(-2)
OUT: (2*k + x)^0.5*((-k) + x)^0.5 = x
IN: last^2
OUT: (2*k + x)*((-k) + x) = x^2
IN: expand(last)
OUT: (-2)*k^2 + k*x + x^2 = x^2
IN: last-x^2+2*k^2
OUT: k*x = 2*k^2
IN: last/k
OUT: x = 2*k
IN: subs(eq1, x = right(last))
OUT: k^0.5 = k^0.5
You can solve algebraic equations step by step, as above.
This method is useful in teaching, e.g. showing students how to solve
equations.
4.7.2 Solve()
The solve() functions
solve(expr1 = expr2, x)
solve([expr1 = expr2, expr3 = expr4], [x, y])
solve a polynomial and systems of linear equations on one step.
It is recommended to set the switch expand:=on when solve the
complicated equations. All of the real and complex roots of the
equation will be found by solve(). The function solve() outputs a
list of roots when there are multi-roots. You can get one of roots
from the list, (see Chapter 4.9 Arrays, Lists, Vectors and Matrices).
Shareware version has not this solve() function.
Example 4.7.2.
Solve a+b*x+x^2 = 0 for x, save the root to x.
IN: solve(a+b*x+x^2 = 0, x) # solve or re-arrange the equation for x
OUT: x = [-b/2 + sqrt((b/2)^2 - a), -b/2 - sqrt((b/2)^2 - a)]
IN: x := right(last) # assign two roots to x
OUT: x := [-b/2 + sqrt((b/2)^2 - a), -b/2 - sqrt((b/2)^2 - a)]
IN: x[1] # the first root
OUT: -b/2 + sqrt((b/2)^2 - a)
IN: x[2] # the second root
OUT: -b/2 - sqrt((b/2)^2 - a)
Example 4.7.3.
Solve x^3 + x^2 + x + 5 = 2*x + 6.
IN: num(solve(x^3+x^2+x+5 = 2*x+6, x))
OUT: x = [1, -1, -1]
The function solve() not only solves for a simple variable x
but also solves for an unknown function, e.g. ln(x).
Example 4.7.4.
Solve the equation for ln(x).
IN: solve(ln(x)^2+5*ln(x) = -6, ln(x))
OUT: ln(x) = [-2, -3]
IN: exp(last)
OUT: x = [exp(-2), exp(-3)]
Example 4.7.5.
Rearrange the equations.
IN: eq := [x+y = 3+a+b, x-y = 1+a-b] # assign equations to eq
IN: solve(eq, [x,y]) # rearrange eq for x and y
OUT: [x = -1/2*(-4 - 2 a), y = -1/2*(-2 - 2 b)]
IN: solve(eq, [a,b]) # rearrange eq for a and b
OUT: [a = -1/2*(4 - 2 x), b = -1/2*(2 - 2 y)]
IN: solve(eq, [a,y]) # rearrange eq for a and y
OUT: [b = -1/2*(2 - 2 y), x = -1/2*(-4 - 2 a)]
IN: solve(eq, [x,b]) # rearrange eq for x and b
OUT: [a = 1/2*(-4 + 2 x), y = 1/2*(2 + 2 b)]
4.7.3 Polynomial Sovler: PSolve()
The external function
psolve(f(x), x)
solves f(x)=0 for x. It is similar to solve(), but it only can solve
polynomial with order < 3.
4.7.4 Numeric Solver: NSolve()
The external functions
nsolve(f(x) = x, x)
nsolve(f(x) = x, x,x0)
numericly solves an algebraic equation with an initial value x0. By
default x0=1. nsolve() only gives one solution near x0, omitting other
solutions.
Example 4.7.4.1.
IN: nsolve( cos(x) = x, x)
OUT: x = 0.73911289091
IN: nsolve( sin(x) = 0, x,0) # similar to asin( sin(x)=0 )
OUT: x = 0 # only gives one solution near x0=0
IN: nsolve( sin(x) = 0, x,3)
OUT: x = 3.14 # only gives one solution near x0=3
4.7.5 Solving Differential Equations
You can solve the differential equations:
y'(x) = f(x)
by integrating the equation.
y'(x) is the same as d(y(x),x).
Example: 4.7.4.1
solve y'(x)=sin(x) by integral.
IN: inte( y'(x) = sin(x), x)
OUT: y(x) = constant - cos(x)
4.7.6 Differential Solver: DSolve()
The external function
dsolve(y'(x) = f(x,y), y(x), x)
can solve the first order variables separable and linear differential
equations
y'(x) = h(x)
y'(x) = f(y(x))
y'(x) = f(y(x))*x
y'(x) = g(x)*y(x)
y'(x) = g(x)*y(x)+h(x)
on one step. Notice that y'(x) must be alone on the left hand
side of the equation. It is recommended to set the switch
expand:=on when solving the complicated differential equations.
Example 4.7.6.1
Solve y'(x) = sin(x) by dsolve().
IN: dsolve( y'(x) = sin(x), y(x), x)
OUT: y(x) = constant - cos(x)
Example 4.7.6.2
Solve differential equations by dsolve(). If the result is a
polynomial, then rearrange the equation by solve().
IN: dsolve(y'(x) = x/(2+y(x)), y(x), x)
OUT: 2*y(x) + 1/2*y(x)^2 = constant + x^2
IN: solve(last, y(x))
OUT: y(x) = [-2 + sqrt(4 - 2*(-constant - x^2)),
-2 - sqrt(4 - 2*(-constant - x^2))]
Example 4.7.6.3
Solve differential equations by dsolve().
IN: dsolve(y'(x) = x*exp(y(x)), y(x), x)
OUT: -e^(-y(x)) = constant + x^2
IN: dsolve(y'(x) = y(x)^2+5*y(x)+6, y(x), x)
OUT: ln((4 + 2 y(x))/(6 + 2 y(x))) = constant + x
IN: dsolve(y'(x) = y(x)/x, y(x), x)
OUT: y(x) = constant x sign(x)
IN: dsolve(y'(x) = y(x)*x+1, y(x), x)
OUT: y(x) = exp(1/2 x^2) (constant + sqrt(1/2) sqrt(pi) erf(sqrt(1/2) x))