SrnLord
SrnLord

Reputation: 111

{OFF} How can I derivate a spline interpolation function on matlab?

I have lab test data from a battery discharge curve. The data consistes in 22 points of voltage versus time. In matlab I have traced an interpolation curve through spline interpolation, but I wish to make the derivative of this plot, how can I do this?

enter image description here

Code

x = [0; 3600    ;7200   ;10800; 14400;  18000;  21600;  25200   ;28800;...
32400;  36000   ;39600  ;43200  ;46800; 50400   ;54000; 57600;  61200;...
64800   ;68400  ;72000; 74880];
y = [12.75; 12.40;  12.38;  12.34;  12.30;  12.26   ;12.21  ;12.17  ;...
 12.12; 12.07;  12.02   ;11.97  ;11.91  ;11.85; 11.79;  11.72;  11.65;...
 11.56  ;11.46  ;11.35  ;11.17; 10.59];

f = fit( x, y,'cubicinterp')

Upvotes: 1

Views: 50

Answers (1)

StaticBeagle
StaticBeagle

Reputation: 5185

You can use gradient of y/x:

f = fit( x, y,'cubicinterp')
df = gradient(f(x)); % f'x
dx = gradient(x);    % dx

dfx = df ./ dx;
plot(x, y, x, dfx); 

Upvotes: 1

Related Questions