home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS - Coast to Coast
/
simteldosarchivecoasttocoast2.iso
/
calculat
/
sm30a.zip
/
NSOLVE.(X)
< prev
next >
Wrap
Text File
|
1993-10-16
|
597b
|
22 lines
# nsolve.sm
# nsolve(cos(x)=x,x,x0) searches for a numeric solution to the
# equation expr1=expr2, starting with x=x0, using Newston's method.
# It only searches for one solution near x0. x0=1 by default.
# nsolve(cos(x)=x, x)
# e.g. nsolve(sin(x)=0,x,3) gives x=3.14, nsolve(sin(x)=0,x,6)
# gives x=6.28.
# See also: solve, dsolve.
nsolve(y_,x_,x0_) := block(numeric:=on,
eq:=left(y)-right(y),
dy:=d(eq ,x),
x:=x0,
jj:=1,
repeat(x:=x-eq/dy, jj:=jj+1, abs(eq)<1e-3 or jj>10),
numeric:=off,
nsolve:=x,
clear(x),
x=nsolve,
local(jj))
nsolve(y_,x_) := nsolve(y,x,1)