passing parameters to fzero, fsolve?

View: New views
7 Messages — Rating Filter:   Alert me  

passing parameters to fzero, fsolve?

by Muhali :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Is there an easy way to pass parameters to fzero or fsolve?

So far I had used fzero from octave-forge where you can pass parameters, but that seems broken currently (missing fsolve_options function) and I would like to switch to the octave version anyway.

Muhali

Re: passing parameters to fzero, fsolve?

by James Sherman Jr.-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm not quite sure what you're asking here.  Octave forge functions
are just packages that add additional functions on to standard octave,
it doesn't replace any functions as far as I know.

On Fri, Aug 7, 2009 at 8:06 PM, Muhali<muhali@...> wrote:

>
> Is there an easy way to pass parameters to fzero or fsolve?
>
> So far I had used fzero from octave-forge where you can pass parameters, but
> that seems broken currently (missing fsolve_options function) and I would
> like to switch to the octave version anyway.
>
> Muhali
>
> --
> View this message in context: http://www.nabble.com/passing-parameters-to-fzero%2C-fsolve--tp24873660p24873660.html
> Sent from the Octave - General mailing list archive at Nabble.com.
>
> _______________________________________________
> Help-octave mailing list
> Help-octave@...
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
>
_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

Re: passing parameters to fzero, fsolve?

by Jaroslav Hajek-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sat, Aug 8, 2009 at 2:06 AM, Muhali<muhali@...> wrote:
>
> Is there an easy way to pass parameters to fzero or fsolve?
>
> So far I had used fzero from octave-forge where you can pass parameters, but
> that seems broken currently (missing fsolve_options function) and I would
> like to switch to the octave version anyway.
>
> Muhali
>

Type
help fzero
help optimset

cheers

--
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz
_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

Re: passing parameters to fzero, fsolve?

by Muhali :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Jaroslav Hajek-2 wrote:
On Sat, Aug 8, 2009 at 2:06 AM, Muhali<muhali@shaw.ca> wrote:
>
> Is there an easy way to pass parameters to fzero or fsolve?
>
> So far I had used fzero from octave-forge where you can pass parameters, but
> that seems broken currently (missing fsolve_options function) and I would
> like to switch to the octave version anyway.
>
> Muhali
>

Type
help fzero
help optimset
I meant parameters to the function to be optimized, not options for the optimization.

Re: passing parameters to fzero, fsolve?

by James Sherman Jr.-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

It might help if you post what you're currently doing and why you find
what you're currently doing hard/undesirable.  Then, we may be able to
offer some better help.
_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

Re: passing parameters to fzero, fsolve?

by Muhali :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

James Sherman Jr.-2 wrote:
It might help if you post what you're currently doing and why you find
what you're currently doing hard/undesirable.  Then, we may be able to
offer some better help.
ok, here is an example:

octave:1> function y = foo(x, p)
> y = log(x+p) - 1 ;
> endfunction
octave:2> p = 1 ;
octave:3> options.abstol = 1e-2 ;
octave:4> fzero("foo", 1, options)
error: `p' undefined near line 2 column 11
error: evaluating argument list element number 1
error: evaluating argument list element number 1
error: called from:
error:   foo at line 2, column 3
error:   /home/gerd/loc/octave-3.2/share/octave/3.2.2/m/optimization/fzero.m at line 105, column 6
octave:4> fzero("foo", 1, options, p)
error: Invalid call to fzero.  Correct usage is:

 -- Function File: [X, FVAL, INFO, OUTPUT] = fzero (FUN, X0, OPTIONS)


Additional help for built-in functions and operators is
available in the on-line version of the manual.  Use the command
`doc <topic>' to search the manual index.

Help and information about Octave is also available on the WWW
at http://www.octave.org and via the help@octave.org
mailing list.
octave:4> pkg load optim
octave:5> fzero("foo", [-5 5], options, p)
ans = -2.5195

Re: passing parameters to fzero, fsolve?

by Jaroslav Hajek-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sun, Aug 9, 2009 at 8:55 AM, Muhali<muhali@...> wrote:

>
>
> James Sherman Jr.-2 wrote:
>>
>> It might help if you post what you're currently doing and why you find
>> what you're currently doing hard/undesirable.  Then, we may be able to
>> offer some better help.
>>
>
> ok, here is an example:
>
> octave:1> function y = foo(x, p)
>> y = log(x+p) - 1 ;
>> endfunction
> octave:2> p = 1 ;
> octave:3> options.abstol = 1e-2 ;
> octave:4> fzero("foo", 1, options)
> error: `p' undefined near line 2 column 11
> error: evaluating argument list element number 1
> error: evaluating argument list element number 1
> error: called from:
> error:   foo at line 2, column 3
> error:   /home/gerd/loc/octave-3.2/share/octave/3.2.2/m/optimization/fzero.m
> at line 105, column 6
> octave:4> fzero("foo", 1, options, p)
> error: Invalid call to fzero.  Correct usage is:
>
>  -- Function File: [X, FVAL, INFO, OUTPUT] = fzero (FUN, X0, OPTIONS)
>
>
> Additional help for built-in functions and operators is
> available in the on-line version of the manual.  Use the command
> `doc <topic>' to search the manual index.
>
> Help and information about Octave is also available on the WWW
> at http://www.octave.org and via the help@...
> mailing list.
> octave:4> pkg load optim
> octave:5> fzero("foo", [-5 5], options, p)
> ans = -2.5195
>

Octave's fsolve, fzero and fminunc do not support passing additional
arguments this way, and I think it is considered deprecated even by
MathWorks. As of now, I have no intentions to add the support. The
"modern" way is to construct a function handle:

fzero (@(x) foo (x, p), [-5, 5], options)

function handles are more general and powerful tool to accomplish the
goal, and they require no special code support in each function you
need. another possibility is to use global shared variables.

--
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz

_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave