Multiple parameters for ZEROFCN [message #78899] |
Mon, 02 January 2012 14:41  |
Rick Walton
Messages: 3 Registered: November 2011
|
Junior Member |
|
|
I would like to find the root of a function f(x) that depends on the
values from an array. Using th IMSL function ZEROFCN appears to only
allow a single parameter to be defined, which is x. But I would like
to vary one of the constants in the function but when I try to use a
userdefined expression for this it causes an error. To demonstrate
what I`m trying to acheive see the function and code below. If anyone
has a simple solution to this I would really appreciate the help.
Thanks in advance.
FUNCTION f, x, y
RETURN, ((sinh((1.4 +x-0.25)/(0.4))/(sinh((x-0.25)/0.4)))-y
END
;array containing data for constant y
Y=fltarr(252)
;new file to input zeros
zero=fltarr(252)
;function to determine zeros in f(x)
FOR i=0, 251 DO BEGIN
zero(i)=ZEROFCN("f", y(i))
|
|
|
Re: Multiple parameters for ZEROFCN [message #78985 is a reply to message #78899] |
Sun, 15 January 2012 07:57  |
wlandsman
Messages: 743 Registered: June 2000
|
Senior Member |
|
|
I give an example of using common blocks to pass parameters below. Since IDL does not have the PV_WAVE ZEROFCN function, I substituted ZBRENT just to have a function that works for me.
Note that another limitation of the built-in IMSL/Numerical Recipes functions in IDL is that the user-supplied function must return a *scalar* value. So be careful that your extra Y parameter is also a scalar. --Wayne
FUNCTION f, x
common fparam, y
RETURN, X^3 + y
END
pro test
common fparam,y
FOR i = 0, 9 DO BEGIN
Y = i
print, Zbrent(-5,5,func_name="F")
ENDFOR
END
|
|
|