# differentiate

Differentiate `cfit`

or `sfit`

object

## Syntax

## Description

**Note**

Use these syntaxes for `sfit`

objects.

`[`

differentiates the surface `fx`

, `fy`

] = differentiate(`FO`

, `X`

, `Y`

)`FO`

at the points specified by `X`

and `Y`

and returns the result in `fx`

and `fy`

.

`FO`

is a surface fit (`sfit`

) object generated by the `fit`

function.

`X`

and `Y`

must be double-precision arrays and the same size and shape as each other.

All return arguments are the same size and shape as `X`

and `Y`

.

If `FO`

represents the surface $$z=f(x,y)$$, then `FX`

contains the derivatives with respect to *x*, that is, $$\frac{df}{dx}$$, and `FY`

contains the derivatives with respect to *y*, that is, $$\frac{df}{dy}$$.

`[`

computes the first and second derivatives of the surface fit object `fx`

, `fy`

, `fxx`

, `fxy`

, `fyy`

] = differentiate(`FO`

, ...)`FO`

.

`fxx`

contains the second derivatives with respect to `x`

, that is, $$\frac{{\partial}^{2}f}{\partial {x}^{2}}$$.

`fxy`

contains the mixed second derivatives, that is, $$\frac{{\partial}^{2}f}{\partial x\partial y}$$.

`fyy`

contains the second derivatives with respect to `y`

, that is, $$\frac{{\partial}^{2}f}{\partial {y}^{2}}$$.

## Examples

## Input Arguments

## Output Arguments

## Tips

For library models with closed forms, the toolbox calculates derivatives analytically. For all other models, the toolbox calculates the first derivative using the centered difference quotient

$$\frac{df}{dx}=\frac{f(x+\Delta x)-f(x-\Delta x)}{2\Delta x}$$

where *x* is the value at which the toolbox calculates the derivative, $$\Delta x$$ is a small number (on the order of the cube root of `eps`

), $$f(x+\Delta x)$$ is `fun`

evaluated at $$x+\Delta x$$, and $$f(x-x\Delta )$$ is `fun`

evaluated at $$x-\Delta x$$.

The toolbox calculates the second derivative using the expression

$$\frac{{d}^{2}f}{d{x}^{2}}=\frac{f(x+\Delta x)+f(x-\Delta x)-2f(x)}{{(\Delta x)}^{2}}$$

The toolbox calculates the mixed derivative for surfaces using the expression

$$\frac{{\partial}^{2}f}{\partial x\partial y}(x,y)=\frac{f(x+\Delta x,y+\Delta y)-f(x-\Delta x,y+\Delta y)-f(x+\Delta x,y-\Delta y)+f(x-\Delta x,y-\Delta y)}{4\Delta x\Delta y}$$

## Version History

**Introduced before R2006a**