Estimating the derivative by differentiating the interpolating cubic polynomial

12 views (last 30 days)
Good afternoon guys,
I'm having a bit of trouble understanding how I would go about estimating the derivative of a function using this technique.
I'm given some function values (x), and I know I am required to use this function:
p = spline(x,fx);

Accepted Answer

Bruno Luong
Bruno Luong on 24 Oct 2018
Edited: Bruno Luong on 24 Oct 2018
% Dummy test data
x=cumsum(rand(1,7));
y=rand(size(x));
ppf=spline(x,y);
% Derivative
ppdf = ppf;
ppdf.order=ppdf.order-1;
ppdf.coefs=ppdf.coefs(:,1:end-1).*(ppdf.order:-1:1);
% Check
close all
xi=linspace(min(x),max(x));
yi=ppval(ppf,xi);
plot(x,y,'o',xi,yi,'b');
xlabel('x');
ylabel('f(x)');
yyaxis right
dyidx=ppval(ppdf,xi);
plot(xi,dyidx,'r');
ylabel('df/dx(x)');
grid on

More Answers (0)

Community Treasure Hunt

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

Start Hunting!