comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Solving nonlinear equations
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Solving nonlinear equations [message #36836 is a reply to message #36835] Sat, 01 November 2003 15:03 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
Thierry Savin <savin@mit.edu> writes:
> Hi all,
>
> Is it possible to create a function called let's say "solvef":
>
> IDL> x=solvef(a,'f')
>
> that returns x the solution of f(x,a)=0 ?

Either MPFIT or TNMIN from my web page can do this kind of job. Both
are designed to be function minimizers. MPFIT will minimize the
square of any function [ in fact the sum of squares of N functions ].
Although people don't normally think of it as so, MPFIT is actually an
equation solver, in addition to a least squares solver.

Your set of fixed parameters, A, would normally passed using
FUNCTARGS. Your notation of X (the varying parameter) and A (the
fixed parameters) are actually reversed from the notation used in
MPFIT or MPFITFUN, where P is the varying parameter and X are the
fixed parameters. Example:

function fx, a, x
return, a(0)+a(1)*x+a(2)*x^2
end


print, mpfitfun('fx', [-2d,10d,4d], [0,0,0], 10, [0d], /quiet)
0.18614066

[ Not sure why an uncertainty estimate of 10 is needed though, hmmm. ]
Or, one can define a new function which is the square of the desired
function, and use TNMIN:

function fffsq, x, a=a
return, ( a(0)+a(1)*x+a(2)*x^2)^2
end

print, tnmin('fffsq', [0d], functargs={a:[-2d,10d,4d]},/autoderiv, /quiet)
0.18614066


Both of these numbers are close to the exact value.

Craig


--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: On G4 Mac Re: path_sep() or where() crashing my idlde?
Next Topic: Re: using VOXEL_PROJ to obtain "thick slice"

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Mon Apr 27 18:57:34 PDT 2026

Total time taken to generate the page: 0.95687 seconds