ipartial
Partial derivative of a multivariate, vector-valued function using the complex-step approximation.
Back to Numerical Differentiation Toolbox Contents.
Contents
Syntax
pf = ipartial(f,x0,k) pf = ipartial(f,x0,k,h)
Description
pf = ipartial(f,x0,k) numerically evaluates the partial derivative of with respect to at using the complex-step approximation with a default step size of .
pf = ipartial(f,x0,k,h) numerically evaluates the partial derivative of with respect to at using the complex-step approximation with a user-specified 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 to differentiate with respect to | 1×1 double |
||
h | (OPTIONAL) step size (defaults to ) | 1×1 double |
||
Output | pf | partial derivative of with respect to , evaluated at | m×1 double |
Note
- This function requires 1 evaluation of .
Example #1: Partial derivative of a scalar-valued function.
Approximate the partial derivative of with respect to at at using the ipartial 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 ipartial function,
pf = ipartial(f,[5;1],k)
pf = 67.5378
Calculating the error,
error = pf-5^3*cos(1)
error = 0
Example #2: Partial derivative of a vector-valued function.
Approximate the partial derivative of
with respect to at using the ipartial 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 ipartial function,
x0 = [1;2]; % evaluation point k = 1; % element of x to differentiate with respect to pf = ipartial(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-16 * 0 0.5551