Python question

Simulation scenario 3. Time and precision of QR decomposition

Run a cycle over a matrix size n from 100 to 1000 with step 100, doing the following operations.

Generate an upper triangular matrix R_true, n by n, by first generating the general random matrix, and then nullifying its lower part by function numpy.triu(). Make the diagonal of R_true positive by taking the abs function of diagonal elements.

Generate an orthogonal matrix Q_true, n by n, by function scipy.stats.ortho_group.rvs().

Compute a product A = Q_true * R_true.

Invert this product by QR-decomposing A: Q_est, R_est = np.linalg.qr(A).

Compute norm_2, abs(det) and cond of matrices A, Q_true, R_true, Q_est, R_est.

Find an error matrix abs(Q_true – Q_est), average its elements in the number avg_q_error.

Find an error matrix abs(R_true – R_est), average its elements in the number avg_r_error.

After the cycle, plot the following values against n, both – on a regular and logarithmic scale: avg_q_error, avg_r_error. Also plot norm_2, abs(det) and cond of matrices A, Q_true, R_true, Q_est, R_est.

On a regular scale, plot the times of computing the product A = Q_true * R_true, and decomposition np.linalg.qr(A).

SAMPLE ASSIGNMENT
Powered by WordPress