"Teja Muppirala" <teja.muppiralaRemoveThis@mathworks.com> wrote in message <ia6h77$r7k$1@fred.mathworks.com>...
> You could probably just differentiate numerically. But if you wanted to do it analytically, that's not so hard either. The coefficients over each interval are given to you in the coefs field of the spline structure. You can differentiate these very easily. It turns out like this:
>
>
> X = [2.54 5.308 8.022 10.685 13.301 15.87 18.394 20.876 23.316 25.716 28.077];
> Y = [0.006 0.02 0.04 0.06 0.079 0.095 0.107 0.115 0.118 0.117 0.114];
>
> S = spline(X,Y);
>
> % Multiplying the coeffiecients by this matrix M is equivalent to
> % differentiation
> M = diag(3:1:1,1);
>
>
> % First derivative
> S1 = S;
> S1.coefs = S1.coefs*M;
>
>
> % Second derivative
> S2 = S1;
> S2.coefs = S2.coefs*M;
>
> x = linspace(X(1),X(end),1001);
>
> hold all
> plot(X,Y,'o')
> plot(x,ppval(S,x),'r')
> plot(x,ppval(S1,x),'g')
> plot(x,ppval(S2,x),'k')
>
> legend({'Original Data','Spline','First Derivative','Second Derivative'})
Thank you for the response and apologies with the delay in sending this...internet issues.
I am not familiar with numerical differentiations, how would the matrix (M=diag(3:1:1,1)) change is if had X and Y data terms of 1:120?
