Gradient of a multivariate, scalar-valued function using the complex-step approximation.

## Syntax

g = igradient(f,x0)


## Description

g = igradient(f,x0) numerically evaluates the gradient of with respect to at using the complex-step approximation with a default step size of .

g = igradient(f,x0,h) numerically evaluates the gradient 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 $\inline&space;f(\mathbf{x})$ multivariate, scalar-valued function ($\inline&space;f:\mathbb{R}^{n}\rightarrow\mathbb{R}$) 1×1function_handle x0 $\inline&space;\mathbf{x}_{0}$ evaluation point n×1double h $\inline&space;h$ (OPTIONAL) step size 1×1double Output g $\inline&space;\mathbf{g}(\mathbf{x}_{0})=\nabla f(\mathbf{x}_{0})$ gradient of $\inline&space;f$ with respect to $\inline&space;\mathbf{x}$, evaluated at $\inline&space;\mathbf{x}=\mathbf{x}_{0}$ n×1double

## Note

• This function requires evaluations of .

## Example

Approximate the gradient of at using the igradient function, and compare the result to the true result of

f = @(x) x(1)^5+sin(x(2))^3;
x0 = [5;8];

g =

1.0e+03 *

3.1250
-0.0004



Calculating the error,

error = g-[3125;3*sin(8)^2*cos(8)]

error =

1.0e-12 *

0.4547
0.0001