[Top][All Lists]

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

Re: Passing parameters to fsolve function - new syntax?

From: Michael Kopp
Subject: Re: Passing parameters to fsolve function - new syntax?
Date: Wed, 05 Oct 2005 12:30:23 +0200
User-agent: Mozilla Thunderbird 1.0 (X11/20041206)


I have a function f(x,a,b,c), which I would like solve for variable x, so that f(x,a,b,c)=0, where a,b,c are parameters, which are known at the time of solving.

However, current fsolve function in Octave only supports one-variable functions. I suppose there is a work-around to declare specific global variables and then giving values to those variables before calling the fsolve function, but this doesn't seem to be a clean way of organizing this.

The fsolve FIX in the octave-forge package seems to expand this functionality, but I'm not able to compile it. Also, the status of this FIX seems to be unclear, as in the development mailing list message

Paul Kienzle, in May, 2005:

I have no interest in maintaining this function.  I am removing it from
the build system for now, and will purge it completely if nobody steps
forward to update it.

IIRC, the purpose of this function is to pass extra arguments to
fsolve, but we can do this now with the new syntax:

    @(x) f(x,a,b,c)

- Paul

I was having the same problem. Actually, the message by Paul Kienzle was in
response to a question I posted on this mailing list last May. Below, I
attach my original message, which shows how I was able to compile
by outcommenting some of the code. Probably, this destroys the possibility
of passing options to the function, but for my current purposes, it works fine.

I have also found another ugly work-around for the standard fsolve, using
sprintf. It goes like this:

function y = f(x,a)
    y = 2*x + a;

a = 2;
str=sprintf('function y = g(x); y = f(x,%g); endfunction',a);

Now, here is my message from 10 May 2005:


I was just trying to compile from octave_forge/FIXES
(a link to the file can be found here:

I used the command "mkoctfile" on a PC with Suse Linux 9.1. My
version of gcc is 3.3.3.

I got the following error message:

********************************************************************** error: cannot convert `double (NLEqn_options::*)() const' to
`double (NLEqn_options::*)()' in initialization

The relevant code from seems to be

  const char *keyword;
  const char *kw_tok[MAX_TOKENS + 1];
  int min_len[MAX_TOKENS + 1];
  int min_toks_to_match;
  d_set_opt_mf d_set_fcn;
  d_get_opt_mf d_get_fcn;

static NLEQN_OPTIONS fsolve_option_table [] =
  { "tolerance",
    { "tolerance", 0, },
    { 1, 0, }, 1,
    &NLEqn_options::tolerance, },   // here is the problem

  { 0,
    { 0, 0, },
    { 0, 0, }, 0,
    0, 0, },

The problem is in the line &NLEqn_options::tolerance. If I outcomment this,
the rest compiles fine. From
I get the following information:

NLEqn_options Class Reference
Public Member Functions
     NLEqn_options (void)
     NLEqn_options (const NLEqn_options &opt)
NLEqn_options &     operator= (const NLEqn_options &opt)
     ~NLEqn_options (void)
void     init (void)
void     copy (const NLEqn_options &opt)
void     set_options (const NLEqn_options &opt)
void     set_default_options (void)
void     set_tolerance (double val)
double     tolerance (void) const

So the tolerance function is indeed declared with const. Unfortunately, my
rudimentary knowledge of C++ does not allow me to find a workaround other
than outcommenting the entire line. Does anyone have a better solution?


Hope this helps,


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]