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: Muthiah Annamalai
Subject: Re: how to define a function handle in oct-files
Date: Thu, 10 Jan 2008 05:50:46 -0600
User-agent: Thunderbird 2.0.0.6 (X11/20071022)

Evan wrote:
On Jan 10, 2008 9:24 PM, Evan <address@hidden> wrote:
I want to define a function like the following in an oct-file

function y=fun(f)
  g=@(x) 1./f(x);
  y=quad(g, 0, 1);
endfunction

what should I write for the sentence "g=@(x) 1./f(x);"?
thanks in advance


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.
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!
-Muthu



reply via email to

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