[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: |
Fri, 11 Jan 2008 22:36:36 +0800 |
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);
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.
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?