fpartial
Partial derivative of a multivariate, vector-valued function using the forward difference approximation.
Back to Numerical Differentiation Toolbox Contents.
Contents
Syntax
pf = fpartial(f,x0,k) pf = fpartial(f,x0,k,h)
Description
pf = fpartial(f,x0,k) numerically evaluates the partial derivative of
with respect to
at
using the forward difference approximation with a default relative step size of
, where
is the machine zero.
pf = fpartial(f,x0,k,h) numerically evaluates the partial derivative of
with respect to
at
using the forward difference approximation with a user-specified relative step size
.
Input/Output Parameters
| Variable | Symbol | Description | Format | |
| Input | f | multivariate, vector-valued function ( |
1×1 function_handle |
|
| x0 | evaluation point | n×1 double |
||
| k | element of |
1×1 double |
||
| h | (OPTIONAL) relative step size (defaults to |
1×1 double |
||
| Output | pf | partial derivative of |
m×1 double |
Note
- This function requires 2 evaluations of
.
Example #1: Partial derivative of a scalar-valued function.
Approximate the partial derivative of
with respect to
at at
using the fpartial function, and compare the result to the true result of

First, we rewrite this function as
.
f = @(x) x(1)^3*sin(x(2));
Since the second component of
represents
, to approximate the derivative, we use
k = 2;
Approximating the partial derivative using the fpartial function,
pf = fpartial(f,[5;1],k)
pf = 67.5378
Calculating the error,
error = pf-5^3*cos(1)
error = -1.7498e-06
Example #2: Partial derivative of a vector-valued function.
Approximate the partial derivative of

with respect to
at
using the fpartial function, and compare the result to the true result of

Defining the function in MATLAB,
f = @(x) [sin(x(1))*sin(x(2));cos(x(1))*cos(x(2))];
Approximating the partial derivative using the fpartial function,
x0 = [1;2]; % evaluation point k = 1; % element of x to differentiate with respect to pf = fpartial(f,x0,k) % differentiation
pf =
0.4913
0.3502
Calculating the error,
error = pf-[cos(1)*sin(2);-sin(1)*cos(2)]
error =
1.0e-07 *
-0.1347
0.0409