help-octave
[Top][All Lists]
Advanced

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

Re: Output function


From: c.
Subject: Re: Output function
Date: Tue, 27 Sep 2011 16:27:03 +0200

On 27 Sep 2011, at 16:09, Juan Pablo Carbajal wrote:

> Hi all,
> 
> I want to generate a function that retruns a function. Example
> t=linspace(0,1,100);
> y = sin(2*pi*t);
> func = data2fun(t,y)
> 
> where data2func looks like
> 
> function f = data2fun (t, y)
> pp = spline (t, y);
> f = @(t_) ppval (pp, t_);
> end

why do you need a function to return the function? 
I think this does what you want:

fun_gen = @(x, t, y) ppval (spline (t, y), x);
fun = @(x) fun_gen(x, t, y);

but maybe the following is more efficient as it does not recompute the 
polynomial every time:


fun_gen = @(pp, y) ppval (pp, x);
pp = spline (t, y);
fun = @(x) fun_gen(pp, y);


> Is there a better way to do it?
> 
> Thanks
> 
> -- 
> M. Sc. Juan Pablo Carbajal
> -----
> PhD Student
> University of Zürich
> http://ailab.ifi.uzh.ch/carbajal/
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://mailman.cae.wisc.edu/listinfo/help-octave



reply via email to

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