cubic spline function

7 views (last 30 days)
Kayne
Kayne on 18 Sep 2011
Hi,
I am having trouble using the Cubic Spline function.
I have to find the max value for y and what it corrospondes to in x. The data that has been given is
x = [0.6,0.7,0,8,0,9,1.0,1.1,1.2,1.3,1.4]';
y = [107,110,112,113.5,114,112,109,104,97]';
I have then used the follow code becuase I want to know the maximun y and what it corrospondes to x
yi = interp1(x, y,0.6:0.01:1.4,'spline')'
Now looking though the variable editor screen in Matlab I can see that 114.0904 is the max value but I am not sure how to extract this using matlab. The code I have been using is below.
x = [0.6,0.7,0,8,0,9,1.0,1.1,1.2,1.3,1.4]';
y = [107,110,112,113.5,114,112,109,104,97]';
yi = interp1(x, y,0.6:0.01:1.4,'spline')'
y1=(0.6:0.01:1.4)';
ans = max(yi)
Now this gives me the answer 114.0904 but now I am not sure for what value of x this is?
Any help would be appriciated
Thanks

Answers (1)

Andrei Bobrov
Andrei Bobrov on 18 Sep 2011
use functions from Curve Fitting Toolbox
x = [0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3,1.4]';
y = [107,110,112,113.5,114,112,109,104,97]';
pp = interp1(x,y,'spline','pp');
dpp = fnder(pp);
maxy = fnval(pp,fzero(@(k)fnval(dpp,k),mean(x)));

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!