notebook giving examples of grad, div, curl &...

4
Notebook giving examples of Grad, Div, Curl & Laplacian This is the Mathematica 9 version Check vector identity for triple-vector product aa = 8ax, ay, az<; bb = 8bx, by, bz<; cc = 8cx, cy, cz<; doublecross = Cross@aa, Cross@bb, ccDD 8- aybycx - azbzcx + aybxcy + az bx cz, axbycx - axbxcy - azbzcy + azbycz,axbzcx + aybzcy - axbxcz - aybycz< shouldequal = Dot@aa, ccD bb - Dot@aa, bbD cc 8- Hax bx + ay by + az bzL cx + bx Hax cx + ay cy + az czL, - Hax bx + ay by + az bzL cy + by Hax cx + ay cy + az czL, - Hax bx + ay by + az bzL cz + bz Hax cx + ay cy + az czL< It works Note that “.” works the same as Dot[ ] but is sometimes harder to read aa.cc * bb - aa.bb * cc 8- Hax bx + ay by + az bzL cx + bx Hax cx + ay cy + az czL, - Hax bx + ay by + az bzL cy + by Hax cx + ay cy + az czL, - Hax bx + ay by + az bzL cz + bz Hax cx + ay cy + az czL< Expand@doublecross - shouldequalD 80, 0, 0< Grad Simple examples from lecture notes: This is the standard notation for using Grad[]: first argument is the function; second argument indicates the x, y and z variable names Grad@x^2 + y^2 + z^2, 8x, y, z<D 82x,2y,2z< The second argument allows you to use different names if you want: Grad@xx^2 + yy^2 + zz^2, 8xx, yy, zz<D 82xx,2yy,2zz<

Upload: others

Post on 14-Mar-2021

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Notebook giving examples of Grad, Div, Curl & Laplaciancourses.washington.edu/ph227814/227/A13/notes/... · 2014. 7. 29. · Expand@doublecross-shouldequalD 80, 0, 0< Grad Simple

Notebook giving examples of

Grad, Div, Curl & Laplacian

This is the Mathematica 9 version

Check vector identity for triple-vector product

aa = 8ax, ay, az<; bb = 8bx, by, bz<; cc = 8cx, cy, cz<;

doublecross = Cross@aa, Cross@bb, ccDD8-ay by cx - az bz cx + ay bx cy + az bx cz,

ax by cx - ax bx cy - az bz cy + az by cz, ax bz cx + ay bz cy - ax bx cz - ay by cz<

shouldequal = Dot@aa, ccD bb - Dot@aa, bbD cc

8-Hax bx + ay by + az bzL cx + bx Hax cx + ay cy + az czL,-Hax bx + ay by + az bzL cy + by Hax cx + ay cy + az czL,-Hax bx + ay by + az bzL cz + bz Hax cx + ay cy + az czL<

It works

Note that “.” works the same as Dot[ ] but is sometimes harder to read

aa.cc * bb - aa.bb * cc

8-Hax bx + ay by + az bzL cx + bx Hax cx + ay cy + az czL,-Hax bx + ay by + az bzL cy + by Hax cx + ay cy + az czL,-Hax bx + ay by + az bzL cz + bz Hax cx + ay cy + az czL<

Expand@doublecross - shouldequalD80, 0, 0<

Grad

Simple examples from lecture notes:

This is the standard notation for using Grad[]:

first argument is the function;

second argument indicates the x, y and z variable names

Grad@x^2 + y^2 + z^2, 8x, y, z<D82 x, 2 y, 2 z<

The second argument allows you to use different names if you want:

Grad@xx^2 + yy^2 + zz^2, 8xx, yy, zz<D82 xx, 2 yy, 2 zz<

Page 2: Notebook giving examples of Grad, Div, Curl & Laplaciancourses.washington.edu/ph227814/227/A13/notes/... · 2014. 7. 29. · Expand@doublecross-shouldequalD 80, 0, 0< Grad Simple

Another example:

phi = 1 � Sqrt@x^2 + y^2 + z^2D; Grad@phi, 8x, y, z<D

:-x

Hx2 + y2 + z2L3�2, -

y

Hx2 + y2 + z2L3�2, -

z

Hx2 + y2 + z2L3�2>

Sec. 6.6 #2

phi = x^2 - y^2 + 2 x y; Grad@phi, 8x, y, z<D82 x + 2 y, 2 x - 2 y, 0<

Finding direction of maximum decrease (i.e. of most negative directional derivative) at x=y=1.

(Can set z to anything; here z=0.)

FindMinimum@8Grad@phi, 8x, y, z<D.8nx, ny, nz< �. 8x ® 1, y ® 1, z ® 0<,nx^2 + ny^2 + nz^2 � 1<, 8nx, ny, nz<D

9-4., 9nx ® -1., ny ® -4.0525 ´ 10-11

, nz ® -4.0525 ´ 10-11==

FindMinimum find the minimum numerically which is why we get these small things instead of actual

zeros. We can remove this if we want to with the Chop function.

Chop@%D8-4., 8nx ® -1., ny ® 0, nz ® 0<<

Direction is (-1,0,0)

Sec. 6.6 #7

phi = x^2 y + y^2 z + z^2 x; Grad@phi, 8x, y, z<D �. 8x ® 1, y ® 2, z ® -1<85, -3, 2<

Other dimensions

Grad works in any number of dimensions

Grad@x^2 - 3 y^2 - 1 � z + Sin@tD, 8x, y, z, t<D

:2 x, -6 y,1

z2

, Cos@tD>

Div & Curl

Div[ ] and Curl[ ] take a vector as their arguments.

vv = 8x^2 y, y^2 x, x y z<;

Div@vv, 8x, y, z<D5 x y

2 GradDivCurlMath9.nb

Page 3: Notebook giving examples of Grad, Div, Curl & Laplaciancourses.washington.edu/ph227814/227/A13/notes/... · 2014. 7. 29. · Expand@doublecross-shouldequalD 80, 0, 0< Grad Simple

Curl@vv, 8x, y, z<D9x z, -y z, -x

2+ y

2=

Div[ ] works in any number of dimensions in a straightforward way.

(Curl[ ] does too, but that’s more complicated, and we won’t discuss it here.)

Here’s a 2-d divergence.

Div@8x y, Cos@yD<, 8x, y<Dy - Sin@yD

Sec 6.7 #19

rhat = 8x, y, z< � Sqrt@x^2 + y^2 + z^2D;

Note that Simplify is necessary to get the divergence into a nice form:

Div@rhat, 8x, y, z<D

-x2

Hx2 + y2 + z2L3�2-

y2

Hx2 + y2 + z2L3�2-

z2

Hx2 + y2 + z2L3�2+

3

x2 + y2 + z2

Simplify@Div@rhat, 8x, y, z<DD2

x2 + y2 + z2

Laplacian

Laplacian takes a scalar function as its argument

Laplacian@x^2 + y^2 + z^2, 8x, y, z<D6

Sec 6.7 #13

tt = x y Hx^2 + y^2 - 5 z^2L;

Laplacian@tt, 8x, y, z<D2 x y

Check that it agrees with fundamental definition:

Div@Grad@tt, 8x, y, z<D, 8x, y, z<D2 x y

Other coordinate systems

The default is to use Cartesian coordinates for Grad, Div, Curl and Laplacian

But Mathematica can do vector calculus in any coordinate system, with standard ones being defined.

More complicated coordinates can be used by defining a “Coordinate chart” (see Mathematica help).

GradDivCurlMath9.nb 3

Page 4: Notebook giving examples of Grad, Div, Curl & Laplaciancourses.washington.edu/ph227814/227/A13/notes/... · 2014. 7. 29. · Expand@doublecross-shouldequalD 80, 0, 0< Grad Simple

The default is to use Cartesian coordinates for Grad, Div, Curl and Laplacian

But Mathematica can do vector calculus in any coordinate system, with standard ones being defined.

More complicated coordinates can be used by defining a “Coordinate chart” (see Mathematica help).

Spherical Coordinates

This is simpler when working with functions expressed naturally in spherical coordinates.

Note that the three components of the vector are in the r-hat, theta-hat and phi-hat directions, respec-

tively.

Here are some examples (some from above).

Grad@r^2, 8r, Θ, Φ<, "Spherical"D82 r, 0, 0<

Grad@1 � r, 8r, Θ, Φ<, "Spherical"D

:-1

r2

, 0, 0>

rhat = 81, 0, 0<; Div@rhat, 8r, Θ, Φ<, "Spherical"D2

r

Curl@8r, 0, 0<, 8r, Θ, Φ<, "Spherical"D80, 0, 0<

This agrees with the result obtained using Cartesian coordinates above

Laplacian@r^2, 8r, Θ, Φ<, "Spherical"D6

Cylindrical

Same idea as Spherical but with chart “Cylindrical”.

Here are the same examples from above:

Grad@rh^2 + z^2, 8rh, th, z<, "Cylindrical"D82 rh, 0, 2 z<

Grad@1 � Sqrt@rh^2 + z^2D, 8rh, th, z<, "Cylindrical"D

:-rh

Hrh2 + z2L3�2, 0, -

z

Hrh2 + z2L3�2>

rhat = 8rh, 0, z< � Sqrt@rh^2 + z^2D; Simplify@Div@rhat, 8rh, th, z<, "Cylindrical"DD2

rh2

+ z2

Laplacian@rh^2 + z^2, 8rh, th, z<, "Cylindrical"D6

4 GradDivCurlMath9.nb