Math 128b: Coding Report 2 Winter 2023
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
Numerical Analysis of Solutions to Equations
Winter 2023
Math 128b: Coding Report 2
Due May 5
1 Problems (100 pts)
For this chapter, you will write scripts to compute the solution to the linear equation Ax = b. First, write a script to perform Gaussian elimination without pivoting and a separate script to perform back substitution. Next, write a third function to determine the LU factorization of a matrix and a fourth to solve LUx = b via forward and backwards sovlves (you should re-use your backsovle algorithm in this).
First, apply these scripts to the matrix you studied in problem 3 in the second problem set to confirm their correctness with b = [3, 2, 1]T . Report the factored matrices and the
x you find with each method.
Next, define a (n × n) matrix A = (5^n)I + R where R is a matrix with random entries from the normal distribution centered at 0 with a standard deviation of 1 and I is the identity matrix. Define b as a (n × 1) vector with random entries drawn from the same random distribution. For n = 50, 100, 250, 500, solve the system Ax = b using your code. Then fill in the table below with the residual error ||Ax − b||2 . Please report these errors using scientific notation. Finally, plot the time needed to solve the system vs. n for each method (please include both methods on the same graph). Do not include the time to create the matrix A in your experminets.
Describe the pattern you observe in the errors and wallclock time graph and how that relates to the theory which we’ve developed in class.
Lastly, try a few experiments with the matrix family Aˆ = R (with R defined as above) and write a sentence or two on your observations. You do no need to submit any code or figures for this, but you should explain what you observe and why this happens.
|
GE |
LU |
50 |
|
|
100 |
|
|
250 |
|
|
500 |
|
|
Table 1: Error for ||Ax − b||2 for different sized matrices GE, and LU factorizations
Hint 1:You can time a block of code in Matlab with
t i c ;
### YOUR CODE HERE ###
total _ time = t o c ;
and in python with:
import time
t0 = time . time ( )
### YOUR CODE HERE ###
t 1 = time . time ( )
total_time = t1−t0
Hint 2 To create the random matrices you can do the following in Matlab: A = 5 ∗ sqrt (n)∗ eye (n)+randn (n , n ) ;
and in python as:
import numpy
A = 5 ∗np . sqrt (n) ∗ np . eye (n) + np . random . normal ( s iz e =(n , n ))
Attach all code you wrote to the end of the report after your results.
2 Collaboration
Please use this space to recognize any and all collaborations which assisted you on the completion of this assignment.
3 Academic Integrity
Please copy and sign the following statement of academic integrity:
On my personal integrity as a student and member of the UCD community, I have not given, nor received and unauthorized assistance on this assignment.
2023-05-05