help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: passing parameters to fzero, fsolve?


From: Jaroslav Hajek
Subject: Re: passing parameters to fzero, fsolve?
Date: Sun, 9 Aug 2009 09:14:01 +0200

On Sun, Aug 9, 2009 at 8:55 AM, Muhali<address@hidden> 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 address@hidden
> 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]