octave-maintainers
[Top][All Lists]
Advanced

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

Re: Bi variate to mono variate functions


From: David Bateman
Subject: Re: Bi variate to mono variate functions
Date: Thu, 30 Mar 2006 16:04:27 +0200
User-agent: Mozilla Thunderbird 1.0.6-7.5.20060mdk (X11/20050322)

John W. Eaton wrote:

>On 29-Mar-2006, David Bateman wrote:
>
>| There is currently no way to do this, though funnily I just implemented
>| it with the attached patch I'm working on in another thread about
>| importing octave-forge changes into octave. So if you want to rebuild
>| octave the you have the patch :-)
>
>Currently, the inputs to quad are
>
>  quad (f, a, b, tol, sing)
>
>with tol and sing optional, and sing not even allowed if the integral
>is indefinite.  If you add parameters following this, you will
>force users who want to use parameters to specify tol and sing, so
>there needs to be another way to tell quad to use default values for
>these parameters.  Perhaps [] as placeholders could mean "use the
>default value".
>  
>
This is what I did in the patch I sent

>But in any case, this is apparently not compatible with Matlab now.
>(I'm not sure, but I thought Matlab's quad function used to allow
>optional additional parameters to quad; if so, then that has changed.)
>
>  
>
No since they allow this

function y = myfun2(x,c),  y = 1./(x.^3-2*x-c); endfunction
Q = quad(@(x)myfun2(x,5),0,2);

In fact I forgot, but so do we, as this is the only place where the pain
of adding anonymous function handles to functions that require user
defined functions wasn't too large.. However, for fsolve, dasrt, daspk,
dassl and lsode this is a real pain as we've been into a number of
times. The problem is the jacobian and constraint functions of these and
how to pass them. Matlab uses optimset('Jacobian') to start that the
same user function returns a jacobian for example. Thinking about this
maybe we could easily allow something like the following to work

function y = myfun(x), y = ...; endfunction
function y = myjac(x), y = ...; endfunction
y = fsolve({@(x)myfun(x),@(x)myjac(x)}, ...);

where we force the user to pass seperate functions for the function and
the jacobian. Its not completely compatiable with matlab, but it'll be a
hell of a lot better especially if the user doesn't define the jacobian
or constraint functions for dasrt, etc and we can easily pass fixed
arguments like

function y = myfun(x,a), y = ...; endfunction
function y = myjac(x,a), y = ...; endfunction
y = fsolve({@(x)myfun(x,5),@(x)myjac(x,5)}, ...);

if you think the above is a reasonable compromise to the current issue,
I'm willing to take a shoot at coding it.

>So I'm not sure that we need this feature now.  Instead, perhaps we
>should make it possible to use an anonymous function to pass
>parameters in a Matlab-compatible way.  For example, Octave (2.9.x)
>can do the following:
>
>  function f (x, p)
>    ...
>  endfunction
>
>  quad (@(x) f(x, 1), a, b)
>  
>
see above this was introduce about 18 months ago..

>but not
>
>  p = ...;
>
>  quad (@(x) f(x, p), a, b)
>
>To make the latter case work may require some significant changes to
>Octave as it means anonymous functions must be able to find values for
>unbound parameters in the context where they are defined (and we first
>need to understand precisely what the rules are for looking up these
>values -- is it done when the function is defined, or when it is used?).
>  
>
I'm not sure I see what you mean. Matlab can do this either.

octave:2> function y = myfun2(x,c),  y = 1./(x.^3-2*x-c); endfunction
octave:3> p = 5;
octave:4> Q = quad(@(x)myfun2(x,5),0,2)
Q = -0.46050
octave:5> Q = quad(@(x)myfun2(x,p),0,2)
error: `p' undefined near line 5 column 23
error: evaluating argument list element number 2
error: called from `?unknown?'
error: quad: evaluation of user-supplied function failed
error: evaluating assignment expression near line 5, column 3



>>  Q = quad(@(x)myfun2(x,5),0,2)

Q =

   -0.4605

>> Q = quad(@(x)myfun2(x,p),0,2)
??? Undefined function or variable 'p'.

Error in ==> @(x)myfun2(x,p)


Error in ==> quad at 63
y = f(x, varargin{:});


>I think this discussion should be moved to the maintainers list.
>
>  
>
done.

>jwe
>
>  
>


-- 
David Bateman                                address@hidden
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary



reply via email to

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