474 Appendix
14. Use index notation to show that the Laplacian in Cartesian coordinates of any vector field u(x) satisfies
∇
2 u = ∇(∇ · u) − ∇ × ∇ × u.
15. Show that at any point in a spherical coordinate system, the spherical basis vectors (ê r , ê θ , ê φ ) form an orthonormal set.
16. Use Eqn A.7.6 to derive the angular distance ∆ between the locations of an earthquake and a seismic station as given in Eqn A.7.7.
Computer problems
The solutions may be useful for other problems in this and other
chapters.
C-1. Find the largest integer your computer allows by starting with
“2,” “2 × 2,” “2 × 2 × 2,” and doing successive multiplication by
2. What happens when you exceed this number? Do the same for
floating point numbers using “10.0” instead of “2” in both single
and double precision. Does double precision allow larger floating
point numbers?
C-2. Find when your computer starts to show round-off error by starting with “10.0” and doing successive multiplications by 10.0. At
each step, add 1.0 to the result and subtract the two numbers.
When does the difference become zero? Do the same in double
precision.
C-3. Write subroutines to do the following operations on an input
vector in three dimensions:
(a) Find the magnitude of a vector.
(b) Find the sum of two vectors.
(c) Find the scalar product of two vectors.
(d) Find the vector product of two vectors.
Your subroutines should include comment lines explaining the
purpose of the routine and the various inputs and outputs.
C-4. Write a subroutine using the necessary subroutines from problem
C-3 to find the angle between two vectors.
C-5. Use the solutions to problems C-3 and C-4 to find the magnitude,
sum, scalar product, and vector product of the vectors (1, 4, 2)
and (2, 3, 1), and the angle between the two vectors.
C-6. (a) Write a subroutine to multiply an n × m matrix by an melement vector.
(b) Write a subroutine to multiply an n × m matrix by an m × r
matrix.
(c) Write a subroutine to find the determinant of a 3 × 3 matrix.
C-7. (a) Write a subroutine that uses Gaussian elimination with
partial pivoting to solve the system of equations Ax = b. The
routine should take an arbitrary 3 × 3 matrix A and 3-element
vector b as inputs. The program should test the solution by
multiplying Ax and subtracting b from the result. The subroutines from C-6 may be helpful.
(b) Use the subroutine to solve
10
7 0
3
2 6
5
1 5
7
4
6
1
2
3
−
−
−
⎛
⎝
⎜
⎜
⎜
⎞
⎠
⎟
⎟
⎟
⎛
⎝
⎜
⎜
⎜
⎞
⎠
⎟
⎟
⎟
=
⎛
⎝
⎜
⎜
⎜
⎞
⎠
⎟
⎟
⎟
.
x
x
x
C-8. (a) Write functions that return the values of the δ ij and ε ijk symbols given the indices as arguments. Test the functions and
show that they give the correct values.
(b) Write a program that uses these two functions to prove the
identity
ε ijk ε ist = δ js δ kt − δ jt δ ks
by testing all possible combinations of indices.
1 Beyer (1984).
C-9. (a) Write a subroutine to invert a 3 × 3 matrix using elementary
row operations. The subroutine should first check to see if
the matrix is singular. It should test the result by multiplying
by the original matrix.
(b) Use this routine to invert
1
1
1
3
1
2
2
2
3
−
−
−
⎛
⎝
⎜
⎜
⎞
⎠
⎟
⎟
.
C-10. (a) Write a program to solve a 3 × 3 system of equations Ax = b
using the matrix inversion routine from the previous problem. The program should test the solution by multiplying Ax
and subtracting b from the result. The subroutines from C-6
may be helpful.
(b) Use the program to solve the system of equations in C-7.
C-11. (a) Write a subroutine to find the roots of a general cubic equation using the method given below.
1
A cubic equation y 3 + py 2 + qy + r = 0 may be converted to
x
3 + ax + b = 0
by defining
y = x − p/3, a = (3q − p
2
)/3, b = (2p
3 − 9pq + 27r)/27.
If p, q, and r are real, the quantity
c = b
2 /4 + a
3 /27
characterizes the roots: if c > 0, there is one real root and two
conjugate imaginary roots; if c = 0, there are three real roots,
of which two are equal; and if c < 0, there are three real and
unequal roots. Using
A = (−b/2 + c
1/2 )
1/3
, B = (−b/2 − c
1/2 )
1/3 ,
the values of x given by
x = A + B, [−(A + B) + (A− B) −3]/2,
−[(A + B) + (A − B) −3]/2
are the roots.
The subroutine requires complex arithmetic and should
test the roots by substituting back into the equation.
(b) Use the result to solve
y 3 − 8y 2 + 19y − 12 = 0.
C-12. (a) Write a subroutine to find the eigenvalues and eigenvectors
of a real, symmetric 3 × 3 matrix, using the results of C-11.
The program should check that the eigenvectors and eigenvalues satisfy their definition. Be careful to avoid dividing by
zero.
(b) Use this subroutine to find the eigenvalues and eigenvectors of
1 2 3
2 4 5
3 5 6
⎛
⎝
⎜
⎜
⎞
⎠
⎟
⎟
.
Précédent

- 489/515

Suivant