On Tue, 2005-10-18 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/mailing-lists/octave-maintainers/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;