the mathematics for chemists (i) (fall term, 2004) (fall term, 2005) (fall term, 2006) department of...

Post on 14-Dec-2015

214 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

The Mathematics for Chemists (I)

(Fall Term, 2004)

(Fall Term, 2005)

(Fall Term, 2006)

Department of ChemistryNational Sun Yat-sen University

化學數學(一)

Chapter 3 Vector Algebraand Analysis

• Definition• Scalar (dot) product• Vector (cross) product• Scalar and vector fields• Applications

Content covered in the textbook: Chapter 16

Assignment: pp372-374: 15,17,18,24,25,30,32,35,40,41, 43,47,48,55,58,60

Definition (naïve)

a

B

A

a=AB

Vectors are a class of quantities that require both magnitude and direction fortheir specification.

Initial pointInitial point

Terminal point Terminal point

Unit vector: a vector of unit length.

Null vector: a vector of zero length. (its direction is meaningless.)

aa

a

au

||

^

Examples of Vectors

• Position, velocity, angular velocity, acceleration

• Force, torque, momentum, angular momentum

• Electric and magnetic fields, electric and magnetic dipole moments,

Vector Algebra

Equality:

Addition:

Subtraction:

Scalar multiplication:

a b=

a + b = b + a

( ) a + -b a - b

a

ba+b

a

ba+b

-ba-b

a1.5a

-a-0.5a

a

b

Example

)(2

1)(

2

1

2

1baADOAODOC

1'

2OC OA AC a AB ��������������������������������������������������������

OCbaabaCO )(2

1)(

2

1

Oa

b

A

B D

C C’

Show that the diagonals of a parallelogram bisect each other.

We need to show that the midpoints of OD and AB coincide.

Classroom Exercise

1 1 1( ) ( ) ( )

3 3 3OX OO OA OB 0 a b a + b��������������������������������������������������������

( ) 2OC a + b��������������

OCOX3

2 O

A

B

C

a

b X

Show that the mean of the position vectors of the vertices of a triangle is the position vector of the centroid of the triangle.

'3

2BCBX

B

OA

C

a

b X

C’

C’’''

3

2ACAX

Components and Decomposition

cosaON

( , )x ya aa

x ya a a i j

x

y

i

j

a

axi

ayj

x=(2,3),y=(4.2,-5.6)

θ

a

O N P

Components and Decomposition(in 3D Space)

axi

azk

ayj

( , , )x y z x y za a a a a a a i j k

( , , )x y za a aa

2 2 2x y za a a a

Vector Algebra Restated

Equality:

Addition:

Subtraction:

Scalar multiplication:

( , , )x y za a aa ( , , )x y zb b bb

a = b xx ba yy ba zz ba

( , , )x x y y z za b a b a b a + b

( , , )x y zc ca ca caa

( , , )x x y y z za b a b a b a - b

Example

(2,3,1)a (1, 2,0) b (5,2, 1) c

2 3 ? d a b c

( , , )x y zd d dd

2)51322(32 xxxx cbad

2)2)2(332(32 yyyy cbad

3))1(0312(32 zzzz cbad

(2, 2,3) d

2 2 2 2 2 22 ( 2) 3 17x y zd d d d

The Center of Mass (Gravity)

N

iiN m

Mmmm

M 1221

1)(

1iN1 rrrrR

N

iimM

1

N

iii xm

MX

1

1

N

iii ym

MY

1

1

N

iii zm

MZ

1

1

m1

m4

m2

m3

r1 r2

r3r4

Dipole Moments

r1

r2

r

-q

q

rrrrrμ 2 qqqq )( 121

1 21

( )N

N ii

q q q q

1 2 N iμ r r r r

N

ii

N

i

N

iii Qqqq

11 1

)() Rμ(0)RrRrμ(R ii

N

ii

1

μμμμμ N21

Dependence of reference frame:

Total dipole moment:

If the total charge Q is zero (e.g., in a molecule), then

) μ(R μ(0)

mCD 301033564.31

Electric dipole moments

Symmetry and Dipole Moment

)

( , , )

(0,0,0)

k

k a a a a a a a a a a a a

k

1 2 3 4

1 2 3 4

μ μ μ μ μ

(r r r r

0

The total dipole moment of a tetrahedron:

r1=(a,a,a), r2=(a,-a,-a), r3=(-a,a,-a), r4=(-a,-a,a)

r3r2

r1

r4

Base Vectors

)0,0,1(i )0,1,0(j )1,0,0(k

),,(

),0,0()0,,0()0,0,(

)1,0,0()0,1,0()0,0,1(

zyx

zyx

zyx

zyx

aaa

aaa

aaa

aaa

kjia

axi

azk

ayj

Orthogonal basis:

Nonorthogonal basis:

cbaυ cba

Classroom Exercise

kjia 32 jib 2

?32 bad

ki

jikji

jikjibad

27

)63()264(

)2(3)32(232

Scalar Differentiation of a Vector

)()( ttt aaa

t

ttt

tdt

dtt

)()(lim)(lim

00

aaaa

kjia )()()()( tatatat zyx

kjia

dt

da

dt

da

dt

da

dt

d zyx

A

B

O

a(t)

a(t+Δt)

Δa

dt

da

Parametric Representation of a Curve

kjir )()()()( tztytxt

O

x

y

z

r(t)C

jir )sin()cos()0,sin,cos()( tbtatbtat

tatx cos)( tbty sin)(

0)( tz

a

bt

Position, Velocity, Momentum, AccelerationNewton’s Second Law

Linear momentum:

rr

dt

dkjikji

rυ zyxdt

dz

dt

dy

dt

dx

dt

d

222zyx

)(2

1

2

1 2222zyxmmvT

kji

kji

rυa

2

2

2

2

2

2

2

2

dt

zd

dt

yd

dt

xd

dt

d

dt

d

dt

d

dt

d

dt

d

zyx

dt

dpF

m

x y z

x y z

d dx dy dzm m m m

dt dt dt dt

m m m

p p p

rp υ i j k

i j k

i j k

Speed:

Kinetic energy:

Acceleration:

Velocity:

Newton’s second law:

Classroom Exercise

• Write the expression of momentum in terms of the planar polar coordinates

. . . . .

. . . .

cos sin

cos sin sin cos

( cos sin ) ( sin cos )

r r i r j

v r r i r i r j r j

p mv m r r i m r r j

����������������������������

The Scalar (Dot) Product

cosab bazzyyxx bababa ba

cos2cos))((2)()()( 22222 abbaOBOAOBOAAB

2 2 2 2

2 2 2 2 2 2

2 2

( ) ( ) ( ) ( )

( ) ( ) 2( )

2( )

x x y y z z

x y z x y z x x y y z z

x x y y z z

AB b a b a b a

a a a b b b a b a b a b

a b a b a b

a b

zzyyxx bababaab cos

Proof:

θ a

b

O B

A

ab

AB

Example)1,1,3( a )3,2,1( b

8)3()1(2113 ba

8)1()3(1231 ab abba

cosab

ba

11aa 14bb

154

8cos

86.498702.0

154

8cos 1

0,2

ba 0,

2 ba

0,2

ba

0 bacaba If 0a

cb )( cba

θ a

b

O B

A

θ aO θ a

b

O

b

Classroom exercise

Orthogonal and Coincident

)1,,2( μ )2,2,4( υ

26)2(1)2(420 υμ

aaa 2222 aaa zyx aaa

3

Cartesian Base Vectors

0 ji

0 kj

0 ik

1 ii

1 jj

1 kk

zzyyxx

zzyy

xyzxyxxx

zyxzyx

bababa

baba

babababa

bbbaaa

kkjj

ijkijiii

kjikjiba

)()(

axi

azk

ayj

Orthogonality:

Normalization (unit length):

Force and Work

),,( 121212 zzyyxx 12 rrd

cosFdW dF FFF d

zx x y y z z x yW F d F d F d W W W

110)3(122 dFW

dFdF

d

FFd cos

)1,3,2(),0,1,2( dF

Force and Work: General Case

C

ABW drF(r)

),,( zyx FFFF

),,( dzdydxd rdzFdyFdxF zyx drF

C zyxAB zdFydFdxFW

x

VFx

y

VFy

z

VFz

dVdzz

Vdy

y

Vdx

x

VzdFydFdxF zyx

),,( zyxVV (r)

BA

B

AAB VVdVW

A

B

O

r(t)

r+Δr

Δr

F(r)

F(r+Δr)

Charges in an Electric Field

xEx

yE y

zE z

CCzEyExE zyx Err )()(

qCqqV Err)(

N

iiN qqqqV

121 )()()()( iN21 rrrr

QC

CqqCqqVN

ii

N

iii

N

iii

ErEri111

)(

cosEV Eμ

θμ

E

EF q

Magnetic Moment in a Magnetic Field

x

ABx

y

AB y

z

ABz

CCzByBxB zyx Brr )()(

CqqqV mmm Brr)(

N

iimNmmm qqqqV

1,,2,1, )()()()( iN21 rrrr

, , , ,1 1 1

( )N N N

m i m i m i i m ii i i

m

V q q C q q C

Q C

ir B r B

m B

cosmBV Bm

θm

B

BF mq

HOW DO YOU KNOW THEY ARE PARALLEL WITH EACH OTHER?

The Vector (Cross) Product

baυ sinabυ

a

b

θbsinθ

A new vector can be constructed from two given vectors:

Its magnitude:

Its direction:

bbaυ

abaυ

v

a

b

Right-hand rule:

A

BC

=A

xB

Important properties

baab

0aa

Classroom exercise:

v

a

b

-v

Anti-commutative:

,00aa If the cross product of two vectors is a zero vector,they must be parallel or antiparallel to each other.

cbacba )()(

Nonassociative:

(Proof to be given later)

In Cartesian Basis

kji

ikj

jik 0ii 0jj

0kk

axi

azk

ayj

)()()(

)()(

ijikjk

kkjkikkjjj

ijkijiii

kjikjiba

yzxzzyxyzxyx

zzyzxzzyyy

xyzxyxxx

zyxzyx

babababababa

bababababa

babababa

bbbaaa

jiij

kjiba )()()( xyyxzxxzyzzy babababababa

jkkj kiik

zyx

zyx

bbb

aaa

kji

ba

Example

)1,1,3( a )3,2,1( b

1 ( 3) ( 1) 2 ( 1) 1 3 ( 3) 3 2 1 1

8 5 ( 1,8,5)

a b i j k

i j k

5,8,1 baab

90581 222 ba

Classroom Exercise)3,1,8( a )2,5,4( b

zyx

zyx

bbb

aaa

kji

ba

Calculate the cross product of above two vectors using

Application: Moment of Force (Torque)

FrFr sinT

FrT r

F

O

θ

d

A

An Electric Dipole in an Electric Field

r

E

-q

q

EF q1

EF q2

r1

r2O

EμT EμErErr

FrFrT

21

11

qq )(22

μ

ET

A Magnetic Dipole in a Magnetic Field

r

B

-qm

qm

BF mq1

BF mq2

r1

r2O

BmT BmBrBrr

FrFrT

21

11

mm qq )(22

m

BT

Angular Velocity

r

sinr

rωυ

In a plane:

General case:

r

O

θ

rsinθ

O

r

v

ω

Exercisec)a(bc)b(acba )(

zyx

zyx

bbb

aaa

kji

ba

c)a(bc)b(a

k

j

i

kji

cdcba

kji

kji

bad

cdcba

)]()([

)]()([

)]()([

)()()(

)(

zxxzxzzzyy

yzzyzxyyxx

xyyxyzxxzz

zyx

xyyxzxxzyzzy

xyyxzxxzyzzy

zyx

zyx

babacbabac

babacbabac

babacbabac

ccc

babababababa

babababababa

bbb

aaa

Classroom exercise

Exercise

b)c(ac)ba

k

j

i

kji

dacba

kji

kji

cbd

dacba

(

)]()([

)]()([

)]()([

)()()(

)(

yzzyyzxxzx

zyyxxyzzyz

zxxzzxyyxy

xyyxzxxzyzzy

zyx

xyyxzxxzzyzy

zyx

zyx

cbcbacbcba

cbcbacbcba

cbcbacbcba

cbcbcbcbcbcb

aaa

cbcbcbcbbccb

ccc

bbb

b)c(ac)b(acba )(

c)a(bc)bacba

b)c(ac)bacba

()(

()(

2=| | -( )

c (b c) (c b) c

c b b c c

( ) ( ) [( ) ( ) ( ) ]

( ) ( ) ( )

( ) ( )

x y z y z y z z x x z x y y x

x y z y z y z x x z z x y y x

a a a b c c b b c b c b c b c

a b c c b a b c b c a b c b c

a b c i j k i j k

a b c a c b

( ) ( ) [( ) ] [( ]

( ( ) ( )

a b c d a b c d a c)b (b c)a d

a c) b d (b c) a d

Angular Momentum

prl

rωrωl )(2 mmr

2mrI

rωυ r

p

O

θ

d

Arωp m

)( rωrl m

][(

)(

ω)r(rr)ωr

rωrl

m

m

(moment of inertia)

A special case: ω is perpendicular r:

ωωl Imr 2r

ω

Conservation of Angular Momentum

dt

dprFr

pr

prp

r dt

d

dt

d

dt

d)(

dt

dlT

dt

dpF

mB

T

BmT Bmμ

T dt

d

Bμμ

μm

dt

d

For nuclear spins:

NMR measures how fast a nuclear spin precesses.

If T=0, angular momentum is conserved.

Scalar and Vector Fields

),,()( zyxfff r

),,()( zyxυrυυ

The Gradient of a Scalar Field

kjiz

f

y

f

x

ffgrad

kjizyx

kji

kji

z

f

y

f

x

f

fzyx

ffgrad

The gradient of a scalar field is a vector.

Vector differential operator

The Meaning of the Gradient

),,(),,( dzzdyydxxzyx

dzdydxdzdydxd kjir ),,(

)()( rrr fdfdf

dzz

fdy

y

fdx

x

fdf

dzz

fdy

y

fdx

x

fdzdydx

z

f

y

f

x

f

kjikji

rdfdf

f(r+dr)

f(r)

dr

Gradient is a convenient vector expression ofthe derivative of multi-variable functions.

Example: Gradient232 zyzxV

1

x

V zy

V2

zy

z

V62

kji )62(2 zyzV

Example: Gradient as Force

x

VFx

y

VFy

z

VFz

kjiFz

V

y

V

x

VV

Force is the negative of the gradient of the potential energy.

Example: Gradient as Force

r

qqV

0

21

4

30

21

30

21333

0

21

0

21

4

44

111

4

r

qq

zyxr

qq

r

z

r

y

r

xqq

rzryrx

qqV

r

kjikji

kjiF

r

rr ˆ1 2 1 2

3 20 0

ˆ4 4

q q q q

r r

rF r

12

0

ˆ4

0

q

r

E r

E r E rr

qqV

0

12 4

q1

q2

r

q1

rE

The Divergence of a Vector Field

zyxdiv zyx

υυ

2 2 2

2 2 2

Suppose that vector is the gradient field of a scalar field , thenf

f f fdiv f

x y z x y z

f f f

x y z

υ

υ i j k i j k

2Laplacian operator

002

2

2

2

2

22

z

f

y

f

x

ff Laplace’s Equation

Examples: Divergence

1S

2S

2S

0 B 0/ E

AThe divergence is a measure of flux density:the amount of ‘something’ flowing out of a unit volume per second.

The Curl of a Vector Field

zyx

xyzxyz

zyx

yxxzzyrotcurl

kji

kjiυυυ

fgradifcurl υυ 0

wυυ curlifdiv 00)( f

0)( A

( ) ( ) ( )

( ) ( ) ( )

x y z

y yx xz z

zy yz xz zx yx xy

x y z

f f ff f f f

x y z

f ff ff f

y z z x x y

f f f f f fx y z

f f f

i j k i j k

i j k

i j k

i j k 0

0)( f

0)( AClassroom Exercise

, , , , , ,

, ,

( ) [ ]

0

(using ...)

y yx xz z

z yx y zx z yx x zy y xz x yz

x yz x zy

A AA AA A

x y z y z z x x y

A A A A A A

A A

A i j k i j k

Physical Meaning of curl (rot)

( ) ( ) ( )x y z y z z x x yz y x z y x

x y z

i j k

v ω r i j k

2

y yx xz z

x y z

v vv vv vcurl rot

y z z x x y

x y z

v v v

v v v i j k

i j k

ω

x y z

y z x

z x y

v z y

v x z

v y x

The curl of a velocity field is angular velocity field (x2).

1 1 12 2 2

1 12 2

( ), ( ), ( )y yx xz zv vv vv v

x y zy z z x x y

x y z

x y zv v v

i j k

ω v

Example: Curl

A

0 E

The curl of the velocity filed is a measure of the circulation of fluid around the point.

( )

( )

[( ) (( ) ) ( ) ]

( ) ( ) ( )

( ) ( ) ( ) (

y z z y z x x z x y y x

y z z y z x x z x y y x

y y yx x z zz y x

A B A B A B A B A B A Bx y z

A B A B A B A B A B A Bx y z

A A BA A A AB B B

x y z x y z x

A B A B

A B A B

i j k iA jB k

(

) ( ) ( )

) ( )

yx x z zz y x

BB B B BA A A

y z x y z

A B B A

[( ) ( ) ( ) ]

[ ( ) (

( )

( )

)] [ ( ) ( )] [ ( ) )]

( ( ) (

(

)

y z z y z x x z x y y x

x y y x z x x z y z z y x y y x z x x z y z z y

A B A B A B A B A B A Bx y z

A B A B A B A B A B A B A B A B A B A B A B A By z z x x y

i j k i j kA B

B A A )B B A A B

i j k

You may win 5 points for filling in the details here!

Supplementary (Not Required)

Major Theorems in Integrationa

dF(x)dx

b

dx=F(a)-F(b)

LS

V

S

b a

) ( ( , ) ( , ) )

( )

( ( , , ) ( , , ) ( , , ) )

S L

S

L

Q Pdxdy P x y dx Q x y dy

x y

R Q P R Q Pdydz dxdz dxdy

y z z x x y

P x y z dx Q x y z dy R x y z dz

( )

( )

yx z

V

x y z

S

AA Adxdydz

x y z

A dydz A dxdz A dxdy

( )

( )

y yx xz z

S

x y z

L

B BB BB Bdydz dxdz dxdy

y z z x x y

B dx B dy B dz

( )

( ( , , ) ( , , ) ( , , ) )

V

S

P Q Rdxdydz

x y z

P x y z dydz Q x y z dxdz R x y z dxdy

Green:

Gauss:

Fundamental:

Stokes:

Major Theorems in Integration

( )S L

d d B S B l

( )V S

dV d A A S

LS

V

S

adF(x)

dxb

dx=F(a)-F(b) b a

(D ,M)=( , M) M∂M

The general form:

( )

( ) ( ) ( )

y yx xz z

S

x y z x y z

L L

B BB BB Bdydz dxdz dxdy

y z z x x y

B B B dx dy dz B dx B dy B dz

i j k i j k

( )

( )

yx z

V

x y z

S

AA Adxdydz

x y z

A dydz A dxdz A dxdy

(Stokes’s theorem)

Classroom Exercise?• Find out the result of the following

integration by using Gauss’s theorem:

2 2

2

2 2

2

1 1 12

0 0 0

(2 3 ) (3 2 ) ( 5 )

2 2

[(2 3 ) (3 2 ) ( 5 ) )

( ) (2 2 )

(2 2 ) (2

yx z

S S

V V

xz y z x x y z x y yz

AA Az x yz

x y z

xz y z dydz x x y z dxdz x y yz dxdy d

dV z x yz dxdydz

dz dy z x yz dx dz dy zx

A i j k

A

A S

A

1 13 1

0

0 0

1 1 1 12 1 7

0 60 0 0 0

/ 3 2 ) |

(2 1/ 3 2 ) (2 / 3 ) | (2 1/ 3 )

xx

yy

x xyz

dz dy z yz dz zy y y z dz z z

2 2[(2 3 ) (3 2 ) ( 5 ) )

where is the surface of a cube shown in the diagram.S

xz y z dydz x x y z dxdz x y yz dxdy

S

1

1

1

x

y

z

The Maxwell Equations

0 E

0 B0/ E

B Jt

BE

0 B0/ D

0 0 t EB J

0 D E P E0 / H B M B

Related to the light speed c

Electrostatics Electrodynamics

In a medium:

TOSHIBA
E/D: Eve/DorothyB/H: Bob/HenryMan does not bear babies, woman bears kids (rho).Man is curled by woman and woman by man, in opposite way!J for Jack/Jane, growing from babies rho

Vector Spaces

)0,,0,0,1( 1e

)0,,0,1,0( 2e

)1,,0,0,0( ne

n321 eeeea nn aaaaaaaa 321321 ),,,,(

abba nnbabababa 332211

223

22

21 naaaa aaa

Norm (length):

Inner (scalar) product:

Inner product space

j i

j iijji if 0

if 1ee

n321 eeeeb nn bbbbbbbb 321321 ),,,,(

You as a vector in a high dimensional space

• Name• Gender• Birth date• Birth place• ID• Student ID• Height• Weight • Favorite drink• Favorite music• ….

(1,0,0,0,0,0,0,0, ,0)1e (0,1,0,0,0,0,0,0,0, ,0)2e

(0,0,0,0,0,0,0,0, ,1)ne

3 (0,0,1,0,0,0,0,0, ,0)e 4 (0,0,0,1,0,0,0,0, ,0)e 5 (0,0,0,0,1,0,0,0,..,0)e

6 (0,0,0,0,0,1,0,0, ,0)e 7 (0,0,0,0,0,0,1,0, ,0)e 8 (0,0,0,0,0,0,0,1 ,0)e

( , ,890301, ,12345678, 942020001,175,60, , )Wang Male Taipei b Tea ClassicWang Da - Fu

Operations of Vectors in Fortran

• Array • Loop: Dot/cross product• Gradient• Divergence• Curl• General vector spaces• Subroutine

Dot Product of VectorsWrite a program to calculate the dot product of any two vectors.

C Program for calculating dot product of any two vectorsc

program dotpro1 parameter(n1=3) real a1(n1),a2(n1)1 write(6,*)'Input three components of first vector:' read(5,*)(a1(i),i=1,n1) write(6,*)'Input three components of second vector:' read(5,*)(a2(i),i=1,n1) dot=0. DO 10,I = 1,n1 dot=dot+a1(i)*a2(i) 10 CONTINUE print *,'The dot product is ', dot print *,'Next calculation (0/1)?' read(5,*)i

if(i.eq.1) goto 1 stop

end

Cross Product of VectorsWrite a program to calculate the cross product of any two vectors.

C Program for calculating cross product of any two vectorsc

program crossp1 parameter(n1=3) real a1(n1),a2(n1),crossp(n1)1 write(6,*)'Input three components of first vector:' read(5,*)(a1(i),i=1,n1) write(6,*)'Input three components of second vector:' read(5,*)(a2(i),i=1,n1) CROSSP(1)=a1(2)*a2(3)-a1(3)*a2(2) CROSSP(2)=a1(3)*a2(1)-a1(1)*a2(3) CROSSP(3)=a1(1)*a2(2)-a1(2)*a2(1) print *,'The cross product is \n', (crossp(i),i=1,3) print *,'Next calculation (0/1)?' read(5,*)i

if(i.eq.1) goto 1 stop

end

Cross Product of VectorsWrite a program to calculate the following vector operations.

)( cba b)c(ac)bacba ()(

C Program for calculating cross product of any three vectorsprogram crossp2

parameter(n1=3) real a1(n1),a2(n1),a3(n1),crossp(n1)

real tmp(n1)1 write(6,*)'Input three components of first vector:' read(5,*)(a1(i),i=1,n1) write(6,*)'Input three components of second vector:' read(5,*)(a2(i),i=1,n1) write(6,*)'Input three components of third vector:' read(5,*)(a3(i),i=1,n1) tmp1=0.0

tmp2=0.0 DO 10,I = 1,n1 tmp1=tmp1+a1(i)*a2(i)

tmp2=tmp2+a1(i)*a3(i)10 CONTINUE

do 20 i=1,n1 CROSSP(i)=tmp2*a2(i)-tmp1*a3(i)20 continue print *,'The cross product is \n', (crossp(i),i=1,3) print *,'Next calculation (0/1)?' read(5,*)i

if(i.eq.1) goto 1 stop

end

Gradient of a Scalar Field

kji

kji

z

f

y

f

x

f

fzyx

ffgrad

232)sin( zyzeyxxf x

Write a program to calculate the gradient of a scalar function.

C Program for calculating the gradient of any scalar functionprogram grdt1

parameter(n1=3) real grt(n1)1 write(6,*) 'please input the position (x,y,z):' read(5,*)x,y,z dx=0.001 dy=0.001

dz=0.001 x2=x+dx

y2=y+dyz2=z+dz

f1=x*sin(x+y)+2.0*y*z*exp(x)+3.0*z*z f2=x2*sin(x2+y)+2.0*y*z*exp(x2)+3.0*z*z

fx=(f2-f1)/dx f2=x*sin(x+y2)+2.0*y2*z*exp(x)+3.0*z*z

fy=(f2-f1)/dy f2=x*sin(x+y)+2.0*y*z2*exp(x)+3.0*z2*z2

fz=(f2-f1)/dzgrt(1)=fxgrt(2)=fygrt(3)=fz

print *,'The gradient at (', x,y,z, ') is \n', (grt(i),i=1,3) print *,'Calculating the gradient of next point (0/1)?' read(5,*)i

if(i.eq.1) goto 1 stop

end

The Divergence of a Vector Field

z

v

y

v

x

vdiv zyx

vv

kjiv )62(]cos([2 yzezyxyzzyxxx

Write a program to calculate the divergence of a vector field.

C Program for calculating the divergence of any vector fieldprogram divg1

parameter(n1=3) real vecf(n1)1 write(6,*) 'please input the position (x,y,z):' read(5,*)x1,y1,z1 dx=0.0001 dy=0.0001

dz=0.0001 x2=x1+dx

y2=y1+dyz2=z1+dz

vx1=x1*x1vx2=x2*x2divgx=(vx2-vx1)/dx

vy1=x1*cos(x1+x1*y1+x1*y1*z1)vy2=x1*cos(x1+x1*y2+x1*y2*z2)divgy=(vy2-vy1)/dy

vz1=2.*y1+6.*z1+exp(-y1*z1)vz2=2.*y1+6.*z2+exp(-y1*z2)divgz=(vz2-vz1)/dydivg=divx+divy+divz

print *,'The divergence at (', x,y,z, ') is \n', divg print *,'Calculating the gradient of next point (0/1)?' read(5,*)i

if(i.eq.1) goto 1 stop

end

The Curl of a Vector Field

zyx

xyzxyz

zyx

yxxzzycurl

kji

kjiυυ

kjiv )62(]cos([2 yzezyxyzzyxxx

Write a program to calculate the rot of a vector field.

Using Subroutines(Go to Chapter 2)

Cross Product of VectorsWrite a program to calculate the following vector operations bycalling subroutine for calculating cross product of two vectors.

h)(ge)(dcba )(

)( cba

C Program for calculating cross product of any two vectorsc

program crossp1 parameter(n1=3) real a1(n1),a2(n1),crossp(n1)1 write(6,*)'Input three components of first vector:' read(5,*)(a1(i),i=1,n1) write(6,*)'Input three components of second vector:' read(5,*)(a2(i),i=1,n1) CROSSP(1)=a1(2)*a2(3)-a1(3)*a2(2) CROSSP(2)=a1(3)*a2(1)-a1(1)*a2(3) CROSSP(3)=a1(1)*a2(2)-a1(2)*a2(1) print *,'The cross product is \n', (crossp(i),i=1,3) print *,'Next calculation (0/1)?' read(5,*)i

if(i.eq.1) goto 1 stop

end

C Subroutine for calculating cross C product of any two vectorsC

subroutine(a,b,c,n) real a(n),b(n),c(n)

c(1)=a1(2)*a2(3)-a1(3)*a2(2) c(2)=a1(3)*a2(1)-a1(1)*a2(3) c(3)=a1(1)*a2(2)-a1(2)*a2(1)

returnend

C Program for calculating the crossC product of any number of vectors

program crossp parameter(n=3,n1=3) real a1(n),a2(n),a3(n),TMP1(1),TMP2(N) open(20,file=‘crossp.1’,err=9999) read(20,*)(a1(i),i=1,n) read(20,*)(a2(i),i=1,n) read(20,*)(a3(i),i=1,n) close(20) call vcross(a2,a3,tmp1,n) call vcross(a1,tmp1,tmp2,n) open(30,file=‘crossp.2’,err=9999) write(30,*)(tmp2(i),i=1,n) CLOSE(30)9999 STOP END

C Subroutine for calculating cross C product of any two vectorsC

subroutine(a,b,c,n) real a(n),b(n),c(n) c(1)=a1(2)*a2(3)-a1(3)*a2(2) c(2)=a1(3)*a2(1)-a1(1)*a2(3) c(3)=a1(1)*a2(2)-a1(2)*a2(1) return

end

Cross Product of VectorsWrite a program to calculate the following vector operations bycalling subroutine for calculating cross product of two vectors.

h)(ge)(dcba )(

C Program for calculating the crossC product of any number of vectors program crossp6 parameter(n=3) real a1(n),a2(n),a3(n),a4(n),a5(n),a6(n),a7(n) real TMP1(1),TMP2(N),TMP3(N),TMP4(N)

real TMP5(n),TMP6(n) open(20,file=‘crossp6.1’,err=9999) read(20,*)(a1(i),i=1,n) read(20,*)(a2(i),i=1,n) read(20,*)(a3(i),i=1,n) read(20,*)(a4(i),i=1,n) read(20,*)(a5(i),i=1,n) read(20,*)(a6(i),i=1,n)

read(20,*)(a7(i),i=1,n) close(20) call vcross(a6,a7,tmp1,n) call vcross(a5,a6,tmp2,n) call vcross(a3,a4,tmp3,n) call vcross(tmp1,tmp2,tmp4,n)

call vcross(tmp3,tmp4,tmp5,n) call vcross(a1,tmp5,tmp6,n) open(30,file=‘crossp6.2’,err=9999) write(30,*)(tmp6(i),i=1,n) CLOSE(30)9999 STOP END

C Subroutine for calculating cross C product of any two vectorsC

subroutine(a,b,c,n) real a(n),b(n),c(n) c(1)=a1(2)*a2(3)-a1(3)*a2(2) c(2)=a1(3)*a2(1)-a1(1)*a2(3) c(3)=a1(1)*a2(2)-a1(2)*a2(1) return

end

General Vector Spaces

n321 eeeea nn aaaaaaaa 321321 ),,,,(

n321 eeeeb nn bbbbbbbb 321321 ),,,,(

Write a subroutine to calculate the inner product of two vectors in any dimension.

C Program for calculating dot product of any two vectorsc

program dotpro1 parameter(n1=3) real a1(n1),a2(n1)1 write(6,*)'Input three components of first vector:' read(5,*)(a1(i),i=1,n1) write(6,*)'Input three components of second vector:' read(5,*)(a2(i),i=1,n1) dot=0. DO 10,I = 1,n1 dot=dot+a1(i)*a2(i) 10 CONTINUE print *,'The dot product is ', dot print *,'Next calculation (0/1)?' read(5,*)i

if(i.eq.1) goto 1 stop

end

C subroutine for calculating dot product of any two vectorssubroutine vdot(a,b,n)

real a(n),b(n) dot=0. DO 10,I = 1,n1 dot=dot+a(i)*b(i) 10 CONTINUE return

end

C program for calculating the inner product of two vectors program innerp1 parameter(n=10) do 10 i=1,n a1(i)=i*1.2 a2(i)=-2.*+i*i 10 continue call vdot(a1,a2,dot,n) print *,'The inner product of two vectors is \n', dot

stopend

C subroutine for calculating inner product of any two vectorssubroutine vdot(a,b,dot,n)

real a(n),b(n) dot=0. DO 10,I = 1,n1 dot=dot+a(i)*b(i) 10 CONTINUE return

end

top related