Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Math 104B

Computational Homework 1

Winter, 2023

Due: Tuesday, March 7th by the start of the class.  Make sure all your codes have a preamble which describes purpose of the code, all the input variables, the expected output, your name, and the date of the last time you modified it. Export the Jupyter notebook as a pdf and upload a scanned copy on Gradescope.

1.   (a) Write a Python program called “Jacobi”which takes as inputs a matrix A, a vector b, the initial guess vector x, the tolerance TOL, and an integer max iterations. Your program should perform n iterations of the Jacobi Iteration method. As a stopping criteria, use the condition

x(n) x(n1)

< TOL.

(b) Consider the linear systems

x1 + 2x2 − 2x3 = 7

x1 +  x2 +  x3 = 2

2x1 + 2x2 +  x3 = 5

and

2x1 −  x2 +  x3 = −1

2x1 + 2x2 + 2x3 = 4

−x1 −  x2 + 2x3 = −5

Use your program to approximate the solution the systems with x(0)  = 0 and tolerance within 10 5  in the ∞-norm.

(c) For which system does the Jacobi method give a good approximation within 25 iterations? Justify your answer by looking at ρ(Tj) for each system.

2.  Repeat Problem 1 using the Gauss-Seidel Method.