[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Calling octave functions from oct-files
From: |
Evan |
Subject: |
Re: Calling octave functions from oct-files |
Date: |
Thu, 17 Jan 2008 23:33:55 +0800 |
On Jan 17, 2008 9:32 PM, Carlo de Falco <address@hidden> wrote:
>
> On 17/gen/08, at 12:06, Carlo de Falco wrote:
>
> > Hi,
> > I am not really sure wether this is of any help,
> > but you could have a look at the source code of the
> > ODE/DAE solver functions which all can take function
> > handles as an input, and then have to evaluate them repeatedly.
> >
> > for example I see (in src/DLD-FUNCTIONS/daspk.cc) things like
> >
> > daspk_fcn = c(0).function_value ();
> >
> > that might be related to what you want to do.
> > c.
>
> Evan,
> actually it seems to me that the attached code does what you intend
> to do.
>
> >> f=@(x) (x+pi)
> f =
>
> @(x) (x + pi)
>
> >> handletest(f,ones(3,1),3)
> ans =
>
> 10.425
> 10.425
> 10.425
>
>
> I would be interested in knowing whether it gives any performance
> improvement
> when applied to your case (I suspect not).
> c.
>
>
I am a newbie in both C++ and oct-file. I don't understand all the
octave functions you used in your attached source (yet). But it seems
that handletest just apply the function several times. How to passing
a function handle has been documented in the manual. What I want to do
is more than that.
For example, f is the function handle passed to the oct-file. I want
to define a NEW function handle
nf = @(x) 1./f(x)
in C++ in the oct-file.
I have tried to do this as follows
if (args(0).is_function_handle ())
{
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;
nf = eval_string(newfcn, true, status, 1)(0);
}
but the integration of nf derived in this way is very slow. In
contrast with this, the integration of f, which is passed to the
oct-file directly, is fast.
Can the method in handletest be used to do things like nf = @(x) 1./f(x) ?
- Calling octave functions from oct-files, Evan, 2008/01/13
- Calling octave functions from oct-files, John W. Eaton, 2008/01/13
- Message not available
- Re: Calling octave functions from oct-files, Evan, 2008/01/17
- Re: Calling octave functions from oct-files, Carlo de Falco, 2008/01/17
- Re: Calling octave functions from oct-files, Carlo de Falco, 2008/01/17
- Re: Calling octave functions from oct-files,
Evan <=
- Re: Calling octave functions from oct-files, Muthiah Annamalai, 2008/01/17
- Re: Calling octave functions from oct-files, Carlo de Falco, 2008/01/18
- Re: Calling octave functions from oct-files, Evan, 2008/01/19
- Re: Calling octave functions from oct-files, kensmith, 2008/01/27