home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / e / e031 / 3.ddi / MATHZIP2 / STARTUP / NSOLVE.M < prev    next >
Encoding:
Text File  |  1991-09-23  |  1003 b   |  39 lines

  1.  
  2.  
  3. Begin["System`"]
  4.  
  5. Unprotect[ NSolve]
  6.  
  7. Clear[ NSolve]
  8.  
  9. NSolve::usage =
  10. "NSolve[eqns, vars] attempts to solve numerically an equation or set of
  11. equations for the variables vars. NSolve[eqns, vars, elims] attempts to solve
  12. numerically the equations for vars, eliminating the variables elims."
  13.  
  14. Begin["`Private`"]
  15.  
  16. Options[NSolve] = {WorkingPrecision -> $MachinePrecision};
  17.  
  18. NSolve[args__, opts___Rule] :=
  19.     Module[{wprec, answer, arglist = {args}},
  20.     answer /;
  21.         (wprec = WorkingPrecision /. {opts};
  22.         If[!IntegerQ[wprec],
  23.         If[Length[arglist] == 3 && IntegerQ[arglist[[3]]],
  24.             wprec = arglist[[3]],
  25.             (* else *)
  26.             wprec = WorkingPrecision /. Options[NSolve]
  27.             ]
  28.         ];
  29.         If[Length[arglist] == 3 && IntegerQ[arglist[[3]]],
  30.         arglist = Take[arglist, 2]];
  31.         answer = Solve[Sequence @@ arglist,
  32.         WorkingPrecision -> wprec, opts];
  33.         Head[answer] =!= Solve)
  34.         ] /; FreeQ[{args}, Rule]
  35.  
  36. Protect[NSolve]
  37. End[ ]    (* `Private` *)
  38. End[ ]    (* System` *)
  39.