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

Home » Public Forums » archive » Re: Function Maximum
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: Function Maximum [message #35474 is a reply to message #35470] Thu, 19 June 2003 14:06 Go to previous messageGo to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
Kate wrote:
>
> If I have a function definition, say it is
>
> FUNCTION MYGAMMA, X, P
> RETURN, P[0]*(X^P[1])*EXP(-1*X/P[2])
> END
>
> Where P holds my fit parameters that are already determined.
>
> If I want to find a local maximum in a certain range is it possible to
> do this with an existing written IDL function?

How about something like:

maxY = MAX( mygamma(X,P) )

?

You already have your P's and your X's define the range in which the maximum is sought. If
you need the X-value of the maximum, then

maxY = MAX( mygamma(X,P), maxXLoc )
maxX = X[maxXLoc]

If you don't want to carry around a bunch of X-vectors, then why not do something like:

FUNCTION FINDMAX, Xr, P, UserFunction
X1 = DOUBLE(Xr[0]) ; The beginning of the range
X2 = DOUBLE(Xr[1]) ; The end of the range
dX = DOUBLE(Xr[2]) ; The resolution within the range

; Compute the ordinate vector
nX = LONG( (X2-X1)/dX ) + 1.5d0 )
X = ( DINDGEN( nX ) / DOUBLE( nX-1 ) ) * ( X2-X1 ) + X1

; Find the maximum value of your user function
Y = CALL_FUNCTION( UserFunction, X, DOUBLE(P) )
maxY = MAX( Y, maxXLoc )
maxX = X[ maxXLoc ]

; Return the coordinate of the local max
RETURN, [ maxX, maxY ]

END

where the Xr input defines the function range [x1,x2] and the resolution at which the
function is calculated (Sort of like a loop triplet.)

Otherwise maybe you could use something like the FX_ROOT function to find the roots of the
first derivative of your function (via DERIV or your own calculated derivative) and use
the second derivative to determine if it's a max or min.

paulv

--
Paul van Delst
CIMSS @ NOAA/NCEP/EMC
Ph: (301)763-8000 x7748
Fax:(301)763-8545
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: recording macros
Next Topic: Return of the GIF?

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

Current Time: Wed Oct 08 17:50:13 PDT 2025

Total time taken to generate the page: 0.00443 seconds