User`s guide
differentiate
4-95
Example Create a noisy sine wave on the interval [0, 4π].
rand('state',0);
x = linspace(0,4*pi,200)';
y = sin(x) + (rand(size(x))-0.5)*0.2;
Create a custom fit type, and fit the data using reasonable starting values.
ftype = fittype('a*sin(b*x)');
fopts = fitoptions('Method','Nonlinear','start',[1 1]);
fit1 = fit(x,y,ftype,fopts);
Calculate the first derivative for each value of x.
deriv1 = differentiate(fit1,x);
Plot the data, the fit to the data, and the first derivatives.
plot(fit1,'k-',x,y,'b.');hold on
plot(x,deriv1,'ro')
legend('data','fitted curve','derivatives')
See Also cfit, fit, integrate
0 2 4 6 8 10 12 14
−1.5
−1
−0.5
0
0.5
1
1.5
x
y
data
fitted curve
derivatives