Estimating the derivative by differentiating the interpolating cubic polynomial

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);

2 Comments

I know I am required to use this function
How do you know that?

Sign in to comment.

 Accepted Answer

% 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)

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!