[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Output function
From: |
Juan Pablo Carbajal |
Subject: |
Re: Output function |
Date: |
Tue, 27 Sep 2011 16:39:29 +0200 |
On Tue, Sep 27, 2011 at 4:38 PM, Juan Pablo Carbajal
<address@hidden> wrote:
> On Tue, Sep 27, 2011 at 4:27 PM, c. <address@hidden> wrote:
>>
>> 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
>>
>>
>
> Thank you Carlo,
>
> I want to hide the interpolation from the usage of the function unless
> the user wants to specify how to do the interpolation.
> Fro example, in optimal control problems, the optimal controller
> sometimes is given as data points (direct collocation methods, for
> example). But to use it in an ode simulation one would need an
> interpolating function. Instead of writing the three 2 lines you
> suggest, one could just call data2fun. Is really a wrapper of what you
> are doing.
> Is it better to return an inline of a handle, or is there another way
> (a string?)?
>
>
>
> --
> M. Sc. Juan Pablo Carbajal
> -----
> PhD Student
> University of Zürich
> http://ailab.ifi.uzh.ch/carbajal/
>
typo : Is it better to return an inline or a handle, or is there
another way (a string?)?
--
M. Sc. Juan Pablo Carbajal
-----
PhD Student
University of Zürich
http://ailab.ifi.uzh.ch/carbajal/