0% found this document useful (0 votes)
53 views

(FX, FY, FZ,... ) GRADIENT (F,... ) : Distance Between Grid Points in X, Y, Z, Direction

The document defines the gradient operator for calculating the numerical gradient of a matrix F. The gradient operator [FX,FY,FZ,...] returns a matrix where each element corresponds to the partial derivative of F in the respective direction (x, y, z, etc.). For example, FX corresponds to the partial derivative of F with respect to x (dF/dx).

Uploaded by

Arindam Sen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

(FX, FY, FZ,... ) GRADIENT (F,... ) : Distance Between Grid Points in X, Y, Z, Direction

The document defines the gradient operator for calculating the numerical gradient of a matrix F. The gradient operator [FX,FY,FZ,...] returns a matrix where each element corresponds to the partial derivative of F in the respective direction (x, y, z, etc.). For example, FX corresponds to the partial derivative of F with respect to x (dF/dx).

Uploaded by

Arindam Sen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 14

[FX,FY,FZ,...] = GRADIENT(F,...

Distance between grid


points in X,Y,Z,…
direction

[FX,FY,FZ,…] is numerical gradient of matrix F

FX corresponds to dF/dx, the differences in the x (column) direction


[x,y] = meshgrid(-2:.2:2, -2:.2:2);
z = x .* exp(-x.^2 - y.^2);
[px,py] = gradient(z,.2,.2);
contour(z),hold on, quiver(px,py), hold off
y

(1,5) (2,5) (3,5) (4,5) (5,5)


[x,y] = meshgrid(-2:1:2, -2:1:2)

Create a mesh on the domain (1,4) (2,4) (3,4) (4,4) (5,4)


of the function z.
(1,3) (2,3) (3,3) (4,3) (5,3)
x
Examples:
(1,2) (2,2) (3,2) (4,2) (5,2)
x(4,5)=1
y(4,5)=2
x(2,2)=-1 (1,1) (2,1) (3,1) (4,1) (5,1)
y(2,5)=2
[x,y] = meshgrid(-2:.2:2, -2:.2:2);
z=x.*exp(-x.^2-y.^2)
z = x .* exp(-x.^2 - y.^2);
[px,py] = gradient(z,.2,.2);
contour(z),hold on, quiver(px,py), hold off
Element by element operation

 2  1   1 4    2  4 
 . *      y
 3 5   3  2   9  10 
 2  1   1 4    5 10 
  *      (1,5) (2,5) (3,5) (4,5) (5,5)
 3 5   3  2   12 2 
(1,4) (2,4) (3,4) (4,4) (5,4)
X(4,5)=1
Y(4,5)=2
(1,3) (2,3) (3,3) (4,3) (5,3)
Z(4,5)=1*exp(-1^2-2^2)=exp(-5)=0.0067 x

(1,2) (2,2) (3,2) (4,2) (5,2)


-0.0007 -0.0067 0 0.0067 0.0007
-0.0135 -0.1353 0 0.1353 0.0135
-0.0366 -0.3679 0 0.3679 0.0366 (1,1) (2,1) (3,1) (4,1) (5,1)
-0.0135 -0.1353 0 0.1353 0.0135
-0.0007 -0.0067 0 0.0067 0.0007
-0.0007 -0.0067 0 0.0067 0.0007 [x,y] = meshgrid(-2:.2:2, -2:.2:2);
-0.0135 -0.1353 0 0.1353 0.0135
-0.0366 -0.3679 0 0.3679 0.0366
z = x .* exp(-x.^2 - y.^2);
-0.0135 -0.1353 0 0.1353 0.0135 [px,py] = gradient(z,.2,.2);
-0.0007 -0.0067 0 0.0067 0.0007 contour(z),hold on, quiver(px,py), hold off

[px,py]=gradient(z,1,1)
y

px = (1,5) (2,5) (3,5) (4,5) (5,5)


-0.0061 0.0003 0.0067 0.0003 -0.0061
-0.1219 0.0067 0.1353 0.0067 -0.1219 (1,4) (2,4) (3,4) (4,4) (5,4)
-0.3312 0.0183 0.3679 0.0183 -0.3312
-0.1219 0.0067 0.1353 0.0067 -0.1219
-0.0061 0.0003 0.0067 0.0003 -0.0061 (1,3) (2,3) (3,3) (4,3) (5,3)
x
py =
-0.0128 -0.1286 0 0.1286 0.0128 (1,2) (2,2) (3,2) (4,2) (5,2)
-0.0180 -0.1806 0 0.1806 0.0180
0 0 0 0 0
(1,1) (2,1) (3,1) (4,1) (5,1)
0.0180 0.1806 0 -0.1806 -0.0180
0.0128 0.1286 0 -0.1286 -0.0128
CONTOUR(Z) is a contour plot of matrix Z
treating the values in Z as heights above a [x,y] = meshgrid(-2:.2:2, -2:.2:2);
plane. A contour plot are the level curves z = x .* exp(-x.^2 - y.^2);
of Z for some values V. The values V are [px,py] = gradient(z,.2,.2);
chosen automatically.
contour(z),hold on, quiver(px,py), hold off

px =
-0.0061 0.0003 0.0067 0.0003 -0.0061 5
-0.1219 0.0067 0.1353 0.0067 -0.1219
4.5
-0.3312 0.0183 0.3679 0.0183 -0.3312
4
-0.1219 0.0067 0.1353 0.0067 -0.1219
-0.0061 0.0003 0.0067 0.0003 -0.0061 3.5

py = 3

-0.0128 -0.1286 0 0.1286 0.0128 2.5

-0.0180 -0.1806 0 0.1806 0.0180 2

0 0 0 0 0 1.5

0.0180 0.1806 0 -0.1806 -0.0180 1


0.0128 0.1286 0 -0.1286 -0.0128 1 1.5 2 2.5 3 3.5 4 4.5 5

z = x .* exp(-x.^2 - y.^2);
[x,y] = meshgrid(-2:.2:2, -2:.2:2);
z = x .* exp(-x.^2 - y.^2);
[px,py] = gradient(z,.2,.2);
contour(z),hold on, quiver(px,py), hold off

HOLD ON holds the current plot


and all axis properties so that 5

subsequent graphing commands 4.5


add to the existing graph.
4

HOLD OFF returns to the default 3.5


mode whereby PLOT commands
erase the previous plots and 3

reset all axis properties before 2.5


drawing new plots.
2

1.5

1
1 1.5 2 2.5 3 3.5 4 4.5 5
DIV = DIVERGENCE(X,Y,Z,U,V,W) computes the divergence of a 3-D vector field
U,V,W. The arrays X,Y,Z define the coordinates for U,V,W and must be monotonic
and 3-D plaid (as if produced by MESHGRID).

load wind
div = divergence(x,y,z,u,v,w);
slice(x,y,z,div,[90 134],[59],[0]); shading interp
daspect([1 1 1])
camlight
load wind
div = divergence(x,y,z,u,v,w);
slice(x,y,z,div,[90 134],[59],[0]); shading interp
daspect([1 1 1])
camlight

Slice at (90,59,0)
Wind is an array of (41,35,15).

Origin: (70.2,17.5,0)
20
End: (134.3, 60, 16)
15

10

5
z
0

y -5
x 60
140
40
120
20 100
80
0 60
load wind
div = divergence(x,y,z,u,v,w);
slice(x,y,z,div,[90 134],[59],[0]); shading interp
daspect([1 1 1])
camlight

20 20

15
15

10
10
5
5
0
0
-5
-5 60
60 140
40
140 120
40 100
120 20
80
20 100
0 60
80
0 60
load wind
div = divergence(x,y,z,u,v,w);
slice(x,y,z,div,[90 134],[59],[0]); shading interp
daspect([1 1 1])
camlight

20 20

15
10
10
0
5
-10
0
-20
-5
60 60 140
140 120
40
120 40
20 100 100
80 20
0 60 80
0 60
load wind
div = divergence(x,y,z,u,v,w);
slice(x,y,z,div,[90 134],[59],[0]); shading interp
daspect([1 1 1])
camlight

4
20

2
10

0 0

-10
-2
-20
60 140
-4
120
40
100
20 -6
80
0 60
[CURLX, CURLY, CURLZ, CAV] = CURL(X,Y,Z,U,V,W) computes the
curl and angular velocity perpendicular to the flow (in radians per
time unit) of a 3D vector field U,V,W. The arrays X,Y,Z define the
coordinates for U,V,W and must be monotonic and 3D plaid (as if
produced by MESHGRID).

Ω
  
v   R

 1 
  v
2
load wind
cav = curl(x,y,z,u,v,w);
slice(x,y,z,cav,[90 134],[59],[0]); 15
10
shading interp 5

daspect([1 1 1]); axis tight 0


130
120
colormap hot(16) 50
40 100
110

camlight 30
80
90

20
L = DEL2(U), when U is a matrix, is a discrete approximation of 0.25*del^2
u = (d^2u/dx^2 + d^2/dy^2)/4. The matrix L is the same size as U, with
each element equal to the difference between an element of U and the
average of its four neighbors.

You might also like