The POLYDER function is meant to be used to differentiate polynomials, and not piece-wise polynomials, such as splines.
If you have Spline Toolbox, you can use FNDER function to find the derivative of a spline:
pp=spline(x,y);
p_der=fnder(pp,1);
y_prime=ppval(p_der,x);
For more information on the FNDER function, please refer to the documentation by executing the following in the MATLAB command prompt:
If you do not have access to the Spline Toolbox, you can use UNMKPP function to break down your polynomial and then use MKPP function to assemble a new polynomial that will be a derivative of the first polynomial as in the following example:
x = 0:10;
y = (x-5).^3+3*3+x+5;
xx = linspace(0,10,20);
pp = spline(x,y);
figure
plot(x,y,'o',xx,ppval(pp,xx))
hold on
[breaks,coefs,l,k,d] = unmkpp(pp);
pp2 = mkpp(breaks,repmat(k-1:-1:1,d*l,1).*coefs(:,1:k-1),d);
plot(xx,ppval(pp2,xx),'-r')
[breaks,coefs,l,k,d] = unmkpp(pp2);
pp3 = mkpp(breaks,repmat(k-1:-1:1,d*l,1).*coefs(:,1:k-1),d);
plot(xx,ppval(pp3,xx),'-g')
For more information on the UNMKPP and MKPP functions please refer to the documentation by executing the following in the MATLAB command prompt:
Best Answer