home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 9
/
MEDIASHARE_09.ISO
/
utility
/
sm22a.zip
/
SYMBMATH.H09
< prev
next >
Wrap
Text File
|
1993-04-15
|
5KB
|
172 lines
7.7 Equations
7.7.1 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. SymbMath is able to find roots of a polynomial, algebraic
equations, systems of equations, differential and integral equations.
Example 7.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.
Input:
eq1=(sqrt(x + 2*k) - sqrt(x - k) === sqrt(k))
eq1^2
expand(last)
last-k-2*x
last/(-2)
last^2
expand(last)
last-x^2+2*k^2
last/k
subs(eq1, x=right(last))
end
Output:
eq1=(sqrt(x + 2*k) - sqrt(x - k) === sqrt(k))
((2*k + x)^0.5 - ((-k) + x)^0.5)^2 === k
2*x + k + (-2)*(2*k + x)^0.5*((-k) + x)^0.5 === k
(-2)*(2*k + x)^0.5*((-k) + x)^0.5 === (-2)*x
(2*k + x)^0.5*((-k) + x)^0.5 === x
(2*k + x)*((-k) + x) === x^2
(-2)*k^2 + k*x + x^2 === x^2
k*x === 2*k^2
x === 2*k
k^0.5 === k^0.5
SymbMath can solve many algebraic equations step by step, as
by hand. This method is useful on teaching, e.g. to show students how
to solve equations.
SymbMath has the built-in function
solve(expr1 === expr2, x)
solve([expr1 === expr2, expr3 === expr4], [x, y])
to 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. Users can get one of roots
from the list, (see 7.9 List, Array, Vector and Matrices).
Users can get the left side of the equation by
left(left_side === right_side)
or the right side by
right(left_side === right_side)
Example 7.7.2. Solve a+b*x+x^2 === 0, save the root to x.
Input:
eq1 = (a+b*x+x^2===0)
solve(eq1, x)
x=right(last)
x[1]
x[2]
end
Output:
eq1 = (a+b*x+x^2 === 0)
x === [-b/2 + sqrt((b/2)^2 - a), -b/2 - sqrt((b/2)^2 - a)]
x = [-b/2 + sqrt((b/2)^2 - a), -b/2 - sqrt((b/2)^2 - a)]
-b/2 + sqrt((b/2)^2 - a)
-b/2 - sqrt((b/2)^2 - a)
Example 7.7.3. Solve x^3+x^2+x+5 === 2*x+6.
Input:
num(solve(x^3+x^2+x+5 === 2*x+6, x))
end
Output:
x === [1, -1, -1]
Function solve() not only solve for a simple variable x
but also for an unknown function, e.g. ln(x).
Example 7.7.4. Solve the equation for ln(x).
Input:
solve(ln(x)^2+5*ln(x) === -6, ln(x))
exp(last)
end
Output:
ln(x) === [-2, -3]
x === [exp(-2), exp(-3)]
Example 7.7.5. Rearrange the equations.
Input:
f = [x+y === 3+a+b, x-y === 1+a-b]
solve(f, [x,y])
solve(f, [a,b])
solve(f, [a,y])
solve(f, [x,b])
end
Output:
f = [x + y === 3 + a + b, x - y === 1 + a - b]
[x === -1/2*(-4 - 2 a), y === -1/2*(-2 - 2 b)]
[a === -1/2*(4 - 2 x), b === -1/2*(2 - 2 y)]
[b === -1/2*(2 - 2 y), x === -1/2*(-4 - 2 a)]
[a === 1/2*(-4 + 2 x), y === 1/2*(2 + 2 b)]
7.7.2 Differential Equations
SymbMath can solve the variables separable differential
equations:
y(x)*d(y(x), x) === f(x)
by integration inte().
Example: 7.7.2.1
Input:
y(x)*d(y(x), x) === sin(x)
inte(last, x)
end
Output:
y(x)*d(y(x), x) === sin(x)
1/2*y(x)^2 === constant - cos(x)
The function
dsolve(d(y)/d(x) === f(x,y), y)
can solve the first order variables separable and linear differential
equations
d(y)/d(x) === h(x)
d(y)/d(x) === g(y)
d(y)/d(x) === g(y)*x
d(y)/d(x) === g(x)*y
d(y)/d(x) === g(x)*y+h(x)
on one step. Notice that d(y)/d(x) must be alone on the left hand
side of the equation. It is recommended to set the switch
expand=on and/or to include 'inte.sm' when solving the complicated
differential equations.
Example 7.7.2.2 Solve d(y)/d(x)=== -sinh(x)*y+sinh(x)*cosh(x).
Input:
dsolve(d(y)/d(x) === -sinh(x)*y+sinh(x)*cosh(x), y)
end
Output:
y === (constant + exp(cosh(x)) - cosh(x)*exp(cosh(x)))*exp(-cosh(x))
Example 7.7.2.3 Solve differential equations. If the result is
a polynomial, then rearrange the equation by solve().
Input:
dsolve(d(y)/d(x) === x/(2+y), y)
solve(last, y)
end
Output:
2*y + 1/2*y^2 === constant + x^2
y === [-2 + sqrt(4 - 2*(-constant - x^2)), -2 - sqrt(4 - 2*(-constant - x^2))]
Example 7.7.2.4. Solve differential equations.
Input:
dsolve(d(y)/d(x) === x*exp(y), y)
dsolve(d(y)/d(x) === y^2+5*y+6, y)
dsolve(d(y)/d(x) === y/x, y)
dsolve(d(y)/d(x) === y*x+1, y)
end
Output:
-exp(-y) === constant + x^2
ln((4 + 2*y)/(6 + 2*y)) === constant + x
y === constant*x*sgn(x)
y === exp(1/2*x^2)*(constant + sqrt(1/2)*sqrt(pi)*erf(sqrt(1/2)*x))