Curve Fitting Toolbox | ![]() ![]() |
Differentiate a fit result object
Syntax
Arguments
fresult |
A fit result object. |
x |
A column vector of values at which fresult is differentiated. |
deriv1 |
A column vector of first derivatives. |
deriv2 |
A column vector of second derivatives. |
Description
deriv1 = differentiate(fitresult,x)
differentiates the fit result object fresult
at the points specified by x
and returns the result to deriv1
. You can generate fresult
with the fit
function or the cfit
function.
[deriv1,deriv2] = differentiate(...)
computes the first derivative deriv1
, and the second derivative deriv2
for the specified fit result object.
Remarks
For library equations with closed forms, analytic derivatives are calculated. For all other equations, the first derivative is calculated using the central difference quotient
where x is the predictor value at which the derivative is calculated, h is a small number, yx+h is fresult
evaluated at x+h, and yx-h is fresult
evaluated at x-h. The second derivative is calculated using the expression
Example
Create a noisy sine wave on the interval [0, 4].
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
.
Plot the data, the fit to the data, and the first derivatives.
See Also
![]() | datastats | disp | ![]() |