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

Home » Public Forums » archive » Re: Passing more than an initial guess to a function used by NEWTON
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Passing more than an initial guess to a function used by NEWTON [message #75327] Fri, 25 February 2011 07:49
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
Yes, I always use common blocks in those situations.
Re: Passing more than an initial guess to a function used by NEWTON [message #75347 is a reply to message #75327] Thu, 24 February 2011 13:29 Go to previous message
fgg is currently offline  fgg
Messages: 67
Registered: April 2010
Member
Common blocks! Thanks for introducing me to it, Wayne. That will do it for now:

pro my_procedure
common share, c1
...
c1 = 3
x_guess = 2
result = newton(x_guess, 'my_function', itmax=100)
print, result
...
end

---------

function my_function, x
common share
return, x^2 + 5*x - c1
end
Re: Passing more than an initial guess to a function used by NEWTON [message #75348 is a reply to message #75347] Thu, 24 February 2011 13:10 Go to previous message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On Feb 24, 5:47 pm, wlandsman <wlands...@gmail.com> wrote:
> Or if one could use the _EXTRA facilty to pass parameters to the function..

Yes, that would probably be the most elegant simple way to pass the
arguments.
Re: Passing more than an initial guess to a function used by NEWTON [message #75350 is a reply to message #75348] Thu, 24 February 2011 12:47 Go to previous message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
>
> I encountered this issue in the past, and would be interested in a way
> better than system or global variables. It would be so easy if
> newton() had something like the uvalues used by widgets, or it called
> a method on an object.

Or if one could use the _EXTRA facilty to pass parameters to the function..

The problem is that these Numerical Recipes routines are written with great fidelity to the original 1992 C code, and so they don't take advantage of IDL capabilities that would make them easier to use.

Meanwhile, one must live with common blocks. --Wayne
Re: Passing more than an initial guess to a function used by NEWTON [message #75351 is a reply to message #75350] Thu, 24 February 2011 12:42 Go to previous message
fgg is currently offline  fgg
Messages: 67
Registered: April 2010
Member
Btw, the solution I came up with was to write an external "my_function.pro" file from within "my_procedure", before calling NEWTON. Something like this:

openw, outunit, '/.../my_function.pro', /get_lun
printf, outunit, 'function my_function, x'
printf, outunit, 'c1 = ', c1
printf, outunit, 'return, x^2 + 5*x - c1'
printf, outunit, 'end
close, outunit & free_lun, outunit'

But this just doesn't feel right... and I run into another problem, as you can see from my previous post:

https://groups.google.com/forum/?fromgroups#!topic/comp.lang .idl-pvwave/iuPqWCO_usI

Thanks again,
fgg
Re: Passing more than an initial guess to a function used by NEWTON [message #75353 is a reply to message #75351] Thu, 24 February 2011 12:32 Go to previous message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On Feb 24, 5:13 pm, fgg <fabioguimaraesgoncal...@gmail.com> wrote:
> I'd like to solve an equation from within a procedure using Newton's method. e.g.
>
> pro my_procedure
> ...
> c1 = 3
> x_guess = 2
> result = newton(x_guess, 'my_function', itmax=100)
> print, result
> ...
> end
>
> ... but I'd like to pass to my_function (i.e. the equation to be solved by NEWTON) not only the initial guess, x_guess, but also a few constants that are being defined within my_procedure (e.g., c1). Is that possible? Here's an example of my_function:
>
> function my_function, x
>       return, x^2 + 5*x - c1
> end

I encountered this issue in the past, and would be interested in a way
better than system or global variables. It would be so easy if
newton() had something like the uvalues used by widgets, or it called
a method on an object.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: scripted object graphics question
Next Topic: Re: License manager troubles

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

Current Time: Fri Oct 10 03:40:33 PDT 2025

Total time taken to generate the page: 0.64006 seconds