[Top][All Lists]

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

Re: Trouble with fsolve

From: Shai Ayal
Subject: Re: Trouble with fsolve
Date: Thu, 27 Oct 2005 15:28:39 +0200
User-agent: Mozilla Thunderbird 1.0 (X11/20041206)

you have to declare them global also inside your function:

function fval=myfunc(x)
 global z

Adam C Powell IV wrote:
On Tue, 2005-10-18 at 17:17 +0200, David Bateman wrote:

Adam C Powell IV wrote:


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


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

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



%global z=1;

function iflag_main=mysolver();
format long;
global z=1;
[x,info] = fsolve("myfunc",[0.9]);
printf('Result=%f, info=%f\n',x(1),info);

function fval=myfunc(x)

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

Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

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