|
|
|
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  |
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  |
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  |
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.
|
|
|