help-octave
[Top][All Lists]
Advanced

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

Re: problem with fsolve


From: geraint . p . bevan . itar
Subject: Re: problem with fsolve
Date: Tue, 14 Aug 2001 09:02:58 -0500

On Tue, 14 Aug 2001, N.D.vanForeest wrote:

> Hi,
>
> I would like to use fsolve to solve an equation of the type f(x;a)==0,
> where x is the variable that needs to be found, and a is a vector of
> parameters. For instance,
>
> function y = solve_rho(x)
>   y(1) = x(1)*theta +log(1-x(1)*ksi);
> endfunction
>
> Clearly I would like to pass the values of theta and ksi to the
function
> solve_rho, but without declaring them as global. Does anyone know how to
> do this? (As far as I understand the manual does not say anything about
> this.)
>

Hi,

if you don't mind using some global parameters, the simplest way of doing
this (that I know of) is to use a wrapper function to call fsolve:


        ## function to evaluate
        function y = solve_rho(x,theta,ksi)
          y(1) = x(1)*theta + log(1-x(1)*ksi)
        endfunction


        ## wrapper functions
        function f = call_solve_rho(x)
          global fsolve_parameters;
          theta = fsolve_parameters(1);
          ksi   = fsolve_parameters(2);
          f = solve_rho(x,theta,ksi);
        endfunction

        function f = fsolve_par(func,x,parameters)
          global fsolve_parameters;
          fsolve_parameters=parameters;
          f = fsolve(func,x);
        endfunction


        ## function call
        fsolve_par("call_solve_rho",[1],[2.0;3.0])


If you are determined not to use any global variables at all, it will
probably be necessary to edit src/DLD-FUNCTIONS/fsolve.cc.

-- 
Regards,
Geraint



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



reply via email to

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