Question: Implement in Matlab the following functions (2 points each). In the first three functions, you are not allowed to use the lu function and the
Implement in Matlab the following functions (2 points each). In the first three functions, you are not allowed to use the lu function and the backslash operator.
function [L, U, P] = lu_pp(A)
%[L,U,P] = lu_pp(A) computes a unit lower triangular matrix L, %an upper triangular matrix U, and a permutation matrix P such
that %P*A = L*U.
%The LU factorization is computed using partial pivoting.
function [L, U, P] = lu_spp(A)
%[L,U,P] = lu_spp(A) computes a unit lower triangular matrix L, %an upper triangular matrix U, and a permutation matrix P such
that %P*A = L*U.
%The LU factorization is computed using scaled partial pivoting .
function x = lu_solve(L,U,b)
%Solves LUx=b by solving Ly=b and then Ux=y.
%L is unit lower triangular, U is upper triangular
function [xm, xpp, xspp] = solve_all(A,b)
%Solves a linear system A*x = b using Matlabs lu and %lu_pp and lu_spp.
%Returns
%xm = A\b
%xpp solution computed using lu_pp and lu_solve
%xspp solution computed using lu_spp and lu_sovle
For this problem, we will investigate the errors in the computed solutions by solve_all. As a reference solution, we use a vector of ones. That is, for a given matrix A, if x = (1,1,...,1)T, we compute b = Ax and then solve Ax = b. If x is the computed solution, the error is x x and the residual is b Ax.
Produce numerical results. (10 points) Discuss the accuracy of the computed solutions.
In particular:
How does it relate to the condition number of the matrix and the residual?
How do your results (with partial and scaled partial pivoting) compare to Matlabs?
Gauss elimination with partial pivoting usually produces small residuals. If some residuals are not very small, can you explain why?
Can scaled partial pivoting improve the accuracy of the computed solution?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
