From help-request at octave dot org Wed Mar 8 09:49:26 2006 Subject: Re: passing functions handles to functions From: David Bateman To: "Christophe Prud'homme" Cc: help at octave dot org Date: Wed, 08 Mar 2006 16:44:43 +0100 Christophe Prud'homme wrote: > Hi again, > > In octave, you can define function using 'function' and 'inline' > however functions like 'fzero' accepts only functions defined by > 'function' (and not inline) > > for example > --------------------------- > function y = fun(x) > y = x.^2 - 1 + exp(x); > end > > fzero("fun", 1) > --------------------------- > Ok > > but > > -------------------------- > f=inline('x.^2 - 1 + exp(x)') > f = > > f(x) = x.^2 - 1 + exp(x) > > octave:2> argnames(f) > ans = > > { > [1,1] = x > } > > octave:3> fzero('f',1) > error: feval: the symbol `f' is not valid as a function > error: evaluating assignment expression near line 358, column 5 > error: evaluating if command near line 208, column 2 > error: called from `fzero' in file > `/usr/share/octave/site/m/octave-forge/optim/fzero.m' > ------------------------- > > > in matlab inline, and strings can be used. > > is there a general rule in octave regarding passing function handles ? > like you can pass only functions handles of functions defined using > 'function' ? > or does it depend on the function using the function handle like fzero ? > or am I missing something ? > > Best regards > C. > With both octave cvs and 2.1.71 I can do f = at cos; feval(f,0) ans = 1 so feval accepts function handles. fsolve, daspk and a few other things don't for rather complex reason that basically mean all of the underlying fortran code for these function would need to be replaced to make the patched needed to fully implement this not be an enormous kludge.. See the threads http://www.octave.org/mailing-lists/octave-maintainers/2005/869 http://www.octave.org/mailing-lists/octave-maintainers/2005/72 http://www.octave.org/mailing-lists/octave-maintainers/2004/627 D. -- David Bateman David dot Bateman at motorola dot com 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 ------------------------------------------------------------- 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 -------------------------------------------------------------