cpartial
Partial derivative of a multivariate, vectorvalued function using the central difference approximation.
Back to Numerical Differentiation Toolbox Contents.
Contents
Syntax
pf = cpartial(f,x0,k) pf = cpartial(f,x0,k,h)
Description
pf = cpartial(f,x0,k) numerically evaluates the partial derivative of with respect to at using the central difference approximation with a default relative step size of , where is the machine zero.
pf = cpartial(f,x0,k,h) numerically evaluates the partial derivative of with respect to at using the central difference approximation with a userspecified relative step size .
Input/Output Parameters
Variable  Symbol  Description  Format  
Input  f  multivariate, vectorvalued function ()  1×1 function_handle 

x0  evaluation point  n×1 double 

k  element of to differentiate with respect to  1×1 double 

h  (OPTIONAL) relative step size  1×1 double 

Output  pf  partial derivative of with respect to , evaluated at  m×1 double 
Note
 This function requires 2 evaluations of .
 If the function is scalarvalued, then .
Example #1: Partial derivative of a scalarvalued function.
Approximate the partial derivative of with respect to at at using the cpartial 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 cpartial function,
pf = cpartial(f,[5;1],k)
pf = 67.5378
Calculating the error,
error = pf5^3*cos(1)
error = 2.2063e09
Example #2: Partial derivative of a vectorvalued function.
Approximate the partial derivative of
with respect to at using the cpartial 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 cpartial function,
x0 = [1;2]; % evaluation point k = 1; % element of x to differentiate with respect to pf = cpartial(f,x0,k) % differentiation
pf = 0.4913 0.3502
Calculating the error,
error = pf[cos(1)*sin(2);sin(1)*cos(2)]
error = 1.0e11 * 0.9040 0.8263