PHYCS 3730/6720 Lab Exercise
Reading and references:
This exercise provides practice with the numpy linear algebra package.
The answer file is Mylab10.txt.
Exercise 1. Solving a linear system
Solve the linear system Ax = b using Python numpy in
interactive mode. Paste your Python session with its solution
into your answer file.
Eqn (1) 2*x1 - x2 + x3 = -1
Eqn (2) 3*x1 + 3*x2 + 9*x3 = 0
Eqn (3) 3*x1 + 3*x2 + 5*x3 = 4
Exercise 2. Check your solution with Python
Continue your interactive Python session from Exercise 1. Check your
answer by multiplying the matrix A by your solution
vector x, subtract the vector b. Print the difference
vector. Then take the Euclidean norm (length) of the difference
vector. That is, calculate d = Ax-b and |d| =
|Ax - b|. Copy the new lines in your interactive session to
your answer file.
Hint. Don't use * when multiplying matrix with
a vector. Use the np.dot function instead. See the notes
linked above.
Exercise 3. Matrix inverse
Continue your interactive Python session from Exercise 2. Compute and
print the inverse of the matrix A (call it Ainv). Then
with Python show that
- Ainv*A = I
- A*Ainv = I
- Ainv*b = x
Copy the new lines in your interactive session to your answer file.