

Greetings,
I'm trying to solve a system with a function of more than one parameter:
[x,fval] = fsolve(@hello_calc,x_guess,options,z3,Param);
where hello_calc is declared later in the same file:
function [fval]=hello_calc(x,z3,Param)
This works just fine in MATLAB, but in octave I get:
error: evaluating for command near line 40, column 1
error: called from `hello' in file `hello.m'
Can octave fsolve not deal with functions of more than one parameter?
That seems to be suggested by the "man page" for fsolve which comes up
after the error is displayed...
Thanks,
Adam

GPG fingerprint: D54D 1AEE B11C CE9B A02B C5DD 526F 01E8 564E E4B6
Welcome to the best software in the world today cafe!
http://www.take6.com/albums/greatesthits.html
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.orgHow to fund new projects: http://www.octave.org/funding.htmlSubscription information: http://www.octave.org/archive.html


Adam C Powell IV wrote:
>Greetings,
>
>I'm trying to solve a system with a function of more than one parameter:
>
>[x,fval] = fsolve(@hello_calc,x_guess,options,z3,Param);
>
>where hello_calc is declared later in the same file:
>
>function [fval]=hello_calc(x,z3,Param)
>
>This works just fine in MATLAB, but in octave I get:
>
>error: evaluating for command near line 40, column 1
>error: called from `hello' in file `hello.m'
>
>Can octave fsolve not deal with functions of more than one parameter?
>That seems to be suggested by the "man page" for fsolve which comes up
>after the error is displayed...
>
>Thanks,
>Adam
>
>
The syntax with function handles is not supported in the CVS. I wrote a
patch to support it which was a huge hack, which you can find at
http://www.octave.org/mailinglists/octavemaintainers/2004/627together with the explanation of why this is the wrong way to go.. Note
that the changes to "quad" were made. However daspk, dasrt, dassl,
fsolve, lsode and odessa weren't converted as the resulting code is an
ugly hack. The only real solution is to completely dump the existing
mess for these functions and reimplement it removing the underlying
fortran code.... So a workaround with global variables is the only way
this can be done at the moment in octave..
D.

David Bateman [hidden email]
Motorola Labs  Paris +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin +33 1 69 35 77 01 (Fax)
91193 GifSurYvette FRANCE
The information contained in this communication has been classified as:
[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary

Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.orgHow to fund new projects: http://www.octave.org/funding.htmlSubscription information: http://www.octave.org/archive.html


On Tue, 20051018 at 17:17 +0200, David Bateman wrote:
> together with the explanation of why this is the wrong way to go.. Note
> that the changes to "quad" were made. However daspk, dasrt, dassl,
> fsolve, lsode and odessa weren't converted as the resulting code is an
> ugly hack. The only real solution is to completely dump the existing
> mess for these functions and reimplement it removing the underlying
> fortran code.... So a workaround with global variables is the only way
> this can be done at the moment in octave..
Have you guys looked at SciPy for an example? Their fsolve function lets
you include multiple parameters, and according to them, it's just a
simple wrapper around MINPACK.
http://www.scipy.org/documentation/apidocs/scipy/scipy.optimize.minpack.html#fsolve
Joel KonkleParker

Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.orgHow to fund new projects: http://www.octave.org/funding.htmlSubscription information: http://www.octave.org/archive.html


Joel KonkleParker wrote:
>On Tue, 20051018 at 17:17 +0200, David Bateman wrote:
>
>
>>together with the explanation of why this is the wrong way to go.. Note
>>that the changes to "quad" were made. However daspk, dasrt, dassl,
>>fsolve, lsode and odessa weren't converted as the resulting code is an
>>ugly hack. The only real solution is to completely dump the existing
>>mess for these functions and reimplement it removing the underlying
>>fortran code.... So a workaround with global variables is the only way
>>this can be done at the moment in octave..
>>
>>
>
>Have you guys looked at SciPy for an example? Their fsolve function lets
>you include multiple parameters, and according to them, it's just a
>simple wrapper around MINPACK.
>
> http://www.scipy.org/documentation/apidocs/scipy/scipy.optimize.minpack.html#fsolve>
>
>
>
Octave also uses minpack for fsolve. The issue I had was not one of
multiple arguments perse, but how to define a single function in the
same manner as matlab that returns both the function evaluations and the
jacobian. The underlying fortran code wants two seperate functions.
Given permission to be completely matlab incompatiable and allow
multiple argument function handles to be passed to fsolve, etc and force
the user to define the function and its jacobian seperately then yes
something can be done. If you want a completely matlab compatiable
fsolve that calculates the function and the jacobian in a single
function, without the mess of caching the results, then you have to
rewrite the underlying fortran code to accept this...
Cheer
David

David Bateman [hidden email]
Motorola Labs  Paris +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin +33 1 69 35 77 01 (Fax)
91193 GifSurYvette FRANCE
The information contained in this communication has been classified as:
[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary

Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.orgHow to fund new projects: http://www.octave.org/funding.htmlSubscription information: http://www.octave.org/archive.html


On 19Oct2005, David Bateman wrote:
 If you want a completely matlab compatiable
 fsolve that calculates the function and the jacobian in a single
 function, without the mess of caching the results, then you have to
 rewrite the underlying fortran code to accept this...
What is wrong with caching the results, provided that you know that
the function and jacobian subroutines will always be called in pairs,
in the same order (I'm not certain that the minpack routines do this,
but I think they might and it seems it would be worth checking)?
jwe

Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.orgHow to fund new projects: http://www.octave.org/funding.htmlSubscription information: http://www.octave.org/archive.html


On Tue, 20051018 at 17:17 +0200, David Bateman wrote:
> Adam C Powell IV wrote:
>
> >Greetings,
> >
> >I'm trying to solve a system with a function of more than one parameter:
> >
> >[x,fval] = fsolve(@hello_calc,x_guess,options,z3,Param);
> >
> >where hello_calc is declared later in the same file:
> >
> >function [fval]=hello_calc(x,z3,Param)
> >
> >This works just fine in MATLAB, but in octave I get:
> >
> >error: evaluating for command near line 40, column 1
> >error: called from `hello' in file `hello.m'
> >
> >Can octave fsolve not deal with functions of more than one parameter?
> >That seems to be suggested by the "man page" for fsolve which comes up
> >after the error is displayed...
> >
> >Thanks,
> >Adam
> >
> >
>
> The syntax with function handles is not supported in the CVS. I wrote a
> patch to support it which was a huge hack, which you can find at
>
> http://www.octave.org/mailinglists/octavemaintainers/2004/627>
> together with the explanation of why this is the wrong way to go.. Note
> that the changes to "quad" were made. However daspk, dasrt, dassl,
> fsolve, lsode and odessa weren't converted as the resulting code is an
> ugly hack. The only real solution is to completely dump the existing
> mess for these functions and reimplement it removing the underlying
> fortran code.... So a workaround with global variables is the only way
> this can be done at the moment in octave..
First, thanks for letting me know the state of octave in this regard.
I'm having trouble working around this though. How do I declare global
variables? Octave seems to be ignoring them, e.g. in the attached code.
If I try to declare it above the function (commented), octave throws a
different error...
Thanks,
Adam

GPG fingerprint: D54D 1AEE B11C CE9B A02B C5DD 526F 01E8 564E E4B6
Welcome to the best software in the world today cafe!
http://www.take6.com/albums/greatesthits.html


you have to declare them global also inside your function:
function fval=myfunc(x)
global z
fval(1)=x(1)z*x(1)*x(1);
return;
Adam C Powell IV wrote:
> On Tue, 20051018 at 17:17 +0200, David Bateman wrote:
>
>>Adam C Powell IV wrote:
>>
>>
>>>Greetings,
>>>
>>>I'm trying to solve a system with a function of more than one parameter:
>>>
>>>[x,fval] = fsolve(@hello_calc,x_guess,options,z3,Param);
>>>
>>>where hello_calc is declared later in the same file:
>>>
>>>function [fval]=hello_calc(x,z3,Param)
>>>
>>>This works just fine in MATLAB, but in octave I get:
>>>
>>>error: evaluating for command near line 40, column 1
>>>error: called from `hello' in file `hello.m'
>>>
>>>Can octave fsolve not deal with functions of more than one parameter?
>>>That seems to be suggested by the "man page" for fsolve which comes up
>>>after the error is displayed...
>>>
>>>Thanks,
>>>Adam
>>>
>>>
>>
>>The syntax with function handles is not supported in the CVS. I wrote a
>>patch to support it which was a huge hack, which you can find at
>>
>> http://www.octave.org/mailinglists/octavemaintainers/2004/627>>
>>together with the explanation of why this is the wrong way to go.. Note
>>that the changes to "quad" were made. However daspk, dasrt, dassl,
>>fsolve, lsode and odessa weren't converted as the resulting code is an
>>ugly hack. The only real solution is to completely dump the existing
>>mess for these functions and reimplement it removing the underlying
>>fortran code.... So a workaround with global variables is the only way
>>this can be done at the moment in octave..
>
>
> First, thanks for letting me know the state of octave in this regard.
>
> I'm having trouble working around this though. How do I declare global
> variables? Octave seems to be ignoring them, e.g. in the attached code.
>
> If I try to declare it above the function (commented), octave throws a
> different error...
>
> Thanks,
> Adam
>
>
> 
>
> %global z=1;
>
> function iflag_main=mysolver();
> iflag_main=0;
> format long;
> global z=1;
> [x,info] = fsolve("myfunc",[0.9]);
> printf('Result=%f, info=%f\n',x(1),info);
> iflag_main=1;
> return;
>
> function fval=myfunc(x)
> fval(1)=x(1)z*x(1)*x(1);
> return;

Shai Ayal, Ph.D.
Head of Research
BioControl Medical BCM
3 Geron St.
Yehud 56100
ISRAEL
Tel: + 972 3 6322 126 ext 223
Fax: + 972 3 6322 125
email: [hidden email]

Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.orgHow to fund new projects: http://www.octave.org/funding.htmlSubscription information: http://www.octave.org/archive.html


Thanks very much, this and a couple of other tricks got my script
working in octave!
On Thu, 20051027 at 15:28 +0200, Shai Ayal wrote:
> you have to declare them global also inside your function:
>
> function fval=myfunc(x)
> global z
> fval(1)=x(1)z*x(1)*x(1);
> return;
>
> Adam C Powell IV wrote:
> > On Tue, 20051018 at 17:17 +0200, David Bateman wrote:
> >
> >>Adam C Powell IV wrote:
> >>
> >>
> >>>Greetings,
> >>>
> >>>I'm trying to solve a system with a function of more than one parameter:
> >>>
> >>>[x,fval] = fsolve(@hello_calc,x_guess,options,z3,Param);
> >>>
> >>>where hello_calc is declared later in the same file:
> >>>
> >>>function [fval]=hello_calc(x,z3,Param)
> >>>
> >>>This works just fine in MATLAB, but in octave I get:
> >>>
> >>>error: evaluating for command near line 40, column 1
> >>>error: called from `hello' in file `hello.m'
> >>>
> >>>Can octave fsolve not deal with functions of more than one parameter?
> >>>That seems to be suggested by the "man page" for fsolve which comes up
> >>>after the error is displayed...
> >>>
> >>>Thanks,
> >>>Adam
> >>>
> >>>
> >>
> >>The syntax with function handles is not supported in the CVS. I wrote a
> >>patch to support it which was a huge hack, which you can find at
> >>
> >> http://www.octave.org/mailinglists/octavemaintainers/2004/627> >>
> >>together with the explanation of why this is the wrong way to go.. Note
> >>that the changes to "quad" were made. However daspk, dasrt, dassl,
> >>fsolve, lsode and odessa weren't converted as the resulting code is an
> >>ugly hack. The only real solution is to completely dump the existing
> >>mess for these functions and reimplement it removing the underlying
> >>fortran code.... So a workaround with global variables is the only way
> >>this can be done at the moment in octave..
> >
> >
> > First, thanks for letting me know the state of octave in this regard.
> >
> > I'm having trouble working around this though. How do I declare global
> > variables? Octave seems to be ignoring them, e.g. in the attached code.
> >
> > If I try to declare it above the function (commented), octave throws a
> > different error...
> >
> > Thanks,
> > Adam
Adam

GPG fingerprint: D54D 1AEE B11C CE9B A02B C5DD 526F 01E8 564E E4B6
Welcome to the best software in the world today cafe!
http://www.take6.com/albums/greatesthits.html
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.orgHow to fund new projects: http://www.octave.org/funding.htmlSubscription information: http://www.octave.org/archive.html

