[TOC]

gradient

Numerical derivatives

Introduction

It approximates the partial derivatives for of a function of variables. If is in the interior, it uses the central difference:

If is at the left boundary, it uses the one-sided difference:

If is at the right boundary, it uses the one-sided difference:

Usage

D1 = gradient(F)

D1 = gradient(F, h)

[D1, D2, ..., DN] = gradient(F)

[D1, D2, ..., DN] = gradient(F, h)

[D1, D2, ..., DN] = gradient(F, h1, h2, ..., hN)

Examples

Input
[X1,X2,X3]=ndgrid(-1:0.6:0.8);
F=X1+X2+X3;
[D1,D2,D3]=gradient(F,0.6)
Output
D1(:, :, 1) = 

1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000

D1(:, :, 2) = 

1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000

D1(:, :, 3) = 

1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000

D1(:, :, 4) = 

1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000

D2(:, :, 1) = 

1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000

D2(:, :, 2) = 

1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000

D2(:, :, 3) = 

1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000

D2(:, :, 4) = 

1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000

D3(:, :, 1) = 

1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000

D3(:, :, 2) = 

1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000

D3(:, :, 3) = 

1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000

D3(:, :, 4) = 

1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000
1.000   1.000   1.000   1.000