[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Passing parameters to fsolve function - new syntax?
From: |
Michael Creel |
Subject: |
Re: Passing parameters to fsolve function - new syntax? |
Date: |
Wed, 05 Oct 2005 13:34:48 +0000 |
User-agent: |
Mozilla Thunderbird 1.0.6 (X11/20050912) |
Aivo Jürgenson wrote:
Hello,
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 http://sourceforge.net/mailarchive/message.php?msg_id=11922522:
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
Could somebody explain this new syntax? I would be happy to use this
new and official way of passing extra arguments to fsolve, but I'm not
been able to find any examples of doing it.
Aivo Jürgenson, address@hidden
You might find bfgsmin in octave-forge to be useful. It will minimize
wrt any one of multiple arguments, and the argument minimization is done
over may be a vector rather than a scalar. Running the following code
1; # this is a script
function y = myfunc(x, otherargs)
a = otherargs{1};
b = otherargs{2};
c = otherargs{3};
y = a + b*x + c*x2;
endfunction
function obj_value = findroot(x, f, otherargs)
e = feval(f, x, otherargs); obj_value = e'*e;
endfunction
a = 0;
b = 1;
c = 0.5;
otherargs = {a, b, c};
x = 5;
control = {20, 1, 1, 1};
x = bfgsmin("findroot", {x, "myfunc", otherargs}, control);
x
leads to the output
======================================================
BFGSMIN final results
Used numeric gradient
------------------------------------------------------
STRONG CONVERGENCE
Function conv 1 Param conv 1 Gradient conv 1
------------------------------------------------------
Objective function value 1.38809e-13
Stepsize 1.0007
8 iterations
------------------------------------------------------
param gradient change
0.0000 0.0000 -0.0000
x = 3.7257e-07
octave:7>
It is possible to set the convergence tolerance to be tighter, if
needed. HTH, Michael
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------