home *** CD-ROM | disk | FTP | other *** search
/ PC Open 13 / pcopen13.iso / Zip / SM34A.ZIP / LIBRARY / NSOLVE.LI < prev    next >
Encoding:
Text File  |  1997-05-24  |  859 b   |  30 lines

  1. # nsolve()
  2. # nsolve(cos(x)=x,x,x0,n) 
  3. # It numerically solves the equation with initial x0 and iteration n,
  4. # using Newston's method. By default n=5, you can increase the n value
  5. # if you want more close to exact solution.
  6. # It only gives one root near x0 if equation has multi roots.
  7.  
  8. # nsolve(cos(x)=x, x)
  9. # It numerically solves equation with default initial x0=0.5 and n=5.
  10.  
  11. # nsolve(cos(x)=x, x,x0)
  12. # It numerically solves the equation with initial x0 and n=5.
  13.  
  14. # See also: solve, dsolve.
  15. # e.g. nsolve(sin(x)=0, x,3) gives 3.14.
  16.  
  17. nsolve(y_,x_,x0_, delta_, n_) := block(numeric:=on,
  18.     eq:=left(y)-right(y),
  19.     dy:=d(eq,x),
  20.     x:=x0,
  21.     j:=0,
  22.     repeat(x:=x-eq/dy, p:=|eq|, j:=j+1, j>n or p<delta),
  23.     numeric:=off,
  24.     nsolve:=x,
  25.     clear(x),
  26.     x=nsolve)
  27.  
  28. nsolve(y_,x_,x0_) := nsolve(y,x,x0,1e-4,5)   
  29. nsolve(y_,x_) := nsolve(y,x,0.5,1e-4,5)
  30.