help-octave
[Top][All Lists]
Advanced

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

Re: how to define a function handle in oct-files


From: Evan
Subject: Re: how to define a function handle in oct-files
Date: Sat, 12 Jan 2008 11:50:13 +0800

On Jan 10, 2008 7:50 PM, Muthiah Annamalai <address@hidden> wrote:
> Evan wrote:
> > On Jan 10, 2008 9:24 PM, Evan <address@hidden> wrote:
> >
> > I still don't know if there is any standard method to do this, but
> > after look through the head files of Octave, I figure out a way as
> > follows
> >
> >       octave_value_list f = feval("func2str", args(0), 1);
> >       std::string fcn = f(0).string_value ();
> >       std::string newfcn = "@(x) 1./( (" + fcn + ")(x))";
> >       int status;
> >       octave_value_list nf = eval_string (newfcn, true, status, 1);
> >
> >
> This is self-defeating, as I think you must use the Delauny
> by invoking Fortran, as otherwise you will not gain much
> speed by doing this in an OCT file.

I didn't count on this part to improve the speed. What I want to do
here is just defining a new function handle which can be passed to
quad. I think the speed is improved by rewriting the for loops in my
program. But I don't understand what do you mean by "Delauny". It
seems not mentioned in any head files of Octave.

> > in "parse.h"
> >      extern OCTINTERP_API octave_value_list
> >      eval_string (const std::string&, bool silent, int& parse_status,
> > int hargout);
> > I think "hargout" is a typo for "nargout". I wonder what is
> > "parse_status" for. It seems that it is always zero whether the string
> > is evaluated successfully or not.
> >
> >
> Parse status is to return success (0) or failure of parsing the string.
> > ps. When trying these things, I encounter another thing I don't understand 
> > i.e.
> >
> > octave:1> @(x) 1./( (@(y) 1./y) (x) )
> > ans =
> >
> > @(x) 1 ./ ((@(y) 1 ./ y;
> > ) (x))
> >
> > octave:2> func2str(  @(x) 1./( (@(y) 1./y) (x) )  )
> > ans = @(x) 1 ./ ((@(y) 1 ./ y;
> > ) (x))
> > octave:3>
> >
> > Why there are semicolons in the output?
> >
> Nothing wrong however!

Yes, it gives a correct function handle. I just feel the semicolons
very confusing.


reply via email to

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