Question

In: Advanced Math

4. (Applying LU and LUP decompositions) In this problem, we'll use the LU/LUP decomposition to solve...

4. (Applying LU and LUP decompositions) In this problem, we'll use the LU/LUP decomposition to solve a linear system of equations.

a) For A = [12 -8 13 -1 13;14 11 -5 -5 -7;1 -8 -9 10 8;-11 10 -8 3 8;-11 -8 4 2 -4] find matrices P, L, and U so that PA = LU using Matlab's lu function. Based on your results: did Matlab use pivoting during the lu-computation?

b) For b = [4;-4;-5;3;7] solve Ax = b using the LU decomposition as follows. Solving Ax = b is the same as solving PAx = Pb. (With P from a). Since PA = LU, we need to solve LUx = Pb, and we can split that into two triangular systems as follows: Ly = Pb, and Ux = y. Solve both of these systems using Matlab's linsolve, state x and y explicitly.

c) Compare the quality of the x you found in b to the solution of Ax = b you get from using linsolve. (As in 2d, work with the differences Ax - b).

d) You want so solve Ax = b for various vectors b, so you collect them into a single matrix B. So your goal is to find a matrix X so that AX = B (one column in X for each column in B). Working with P, L, and U from parts a/b we see that this amounts to solving two systems: LY = PB and UX = Y. For B = [18 -7 -14 10 -14 -2 13 12 -15 -15;-15 -14 4 -2 13 -16 15 -3 -15 14;3 12 -10 -17 2 19 -17 17 15 5;-1 -8 6 -11 20 -20 -4 -13 3 -6;-20 1 8 17 -17 11 -10 -10 2 1] solve these two equations using Matlab's linsolve.

First find Y in LY = PB, and then use that to find X in UX = Y. Check that AX - B is close to the zero matrix.

For this last problem, work with format short (or even format compact) so that the matrices don't use up too much screenspace.

Solutions

Expert Solution


%%Matlab code for solving linear system
clear all
close all

%A matrix
A = [12 -8 13 -1 13;14 11 -5 -5 -7;1 -8 -9 10 8;-11 10 -8 3 8;-11 -8 4 2 -4];
fprintf('A matrix is \n')
disp(vpa(A,3))

%LU of A
[L,U,P] = lu(A);
fprintf('L*U for A= ')
disp(vpa(L*U,3))
fprintf('Yes partial pivoting done for LU decomposition.\n')

%b vector
b = [4;-4;-5;3;7];
fprintf('b vector is \n')
disp(b)

%Ly=Pb
%Solution using linsolve
y=linsolve(L,P*b);
fprintf('Solution using linsolve for Ly=Pb for y= \n')
disp(y)
%Ux=y
%Solution using linsolve
x=linsolve(U,y);
fprintf('Solution using linsolve for Ux=y for x= \n')
disp(x)

%solution using linsolve for Ax=b
%Solution using linsolve
xx=linsolve(A,b);
fprintf('Solution using linsolve for Ax=b for xx= \n')
disp(xx)

%error in Ax=b and LU
err1=A*x-b;
fprintf('Error in LU solution\n')
disp(err1)

err2=A*xx-b;
fprintf('Error in Ax=b solution\n')
disp(err2)

%B matrix
B = [18 -7 -14 10 -14 -2 13 12 -15 -15;...
    -15 -14 4 -2 13 -16 15 -3 -15 14;...
    3 12 -10 -17 2 19 -17 17 15 5;...
    -1 -8 6 -11 20 -20 -4 -13 3 -6;...
    -20 1 8 17 -17 11 -10 -10 2 1] ;
fprintf('B matrix is\n')
disp(vpa(B,3))
%Ly=Pb
%Solution using linsolve
Y=linsolve(L,P*B);
fprintf('Solution using linsolve for LY=PB for Y= \n')
disp(vpa(Y,3))
%Ux=y
%Solution using linsolve
X=linsolve(U,Y);
fprintf('Solution using linsolve for UX=Y for X= \n')
disp(vpa(X,3))

%solution using linsolve for Ax=b
%Solution using linsolve
XX=linsolve(A,B);
fprintf('Solution using linsolve for AX=B for XX= \n')
disp(vpa(XX,3))

%error in Ax=b and LU
err1=A*X-B;
fprintf('Error in LU solution\n')
disp(vpa(err1,3))

%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%


Related Solutions

Q: (LU decomposition) Find the LU decomposition of A = [-3 2 5 1; 12 -4...
Q: (LU decomposition) Find the LU decomposition of A = [-3 2 5 1; 12 -4 -20 -2; -6 0 15 1; -9 6 35 4]. You can use the compact method which works within a single matrix or you can build L and U separately. State L and U explicitly, and verify (in Matlab) that A = L*U. Hint: Matlab's built-in lu function isn't useful, since it pivots.
Use LU decomposition to solve the following system of equations (show your work). Do not use...
Use LU decomposition to solve the following system of equations (show your work). Do not use a pivoting strategy, and check your results by using the matrix inverse to show that [A][A]-1= [I]. 8x+ 2y−z=10 - 2x+4y+z=5 3x−y+ 6z=7
LU Decomposition Method?
7 2 -3 x1 -12 2 5 -3 x2 = -20 1 5 -6 x3 -26 LU Decomposition Method?
This is a question answered by R. **In this problem, we'll use simulation to think about...
This is a question answered by R. **In this problem, we'll use simulation to think about survey sampling. Suppose I want to plan a survey to learn what percentage of students prefer coffee to tea.** a. **Let *X* be the number of students in my sample that prefer coffee. If I survey *n* students, and the true proportion of students that prefer coffee is *p*, then we can model *X* as a Binomial(*n*, *p*) random variable. If I survey ten...
LU Decomposition (i). Prove that for n equal to 2 or 3 there is a non-singular...
LU Decomposition (i). Prove that for n equal to 2 or 3 there is a non-singular square (n by n) matrix which has no LU decomposition with L unit lower triangular and U upper triangular. (In fact, this is true for any integer ≥ 2.) (ii). We will see that all non-singular square matrices do have an LUP decomposition (some time soon in class). Here P is a permutation matrix, also defined in Appendix D and used in Chapter 28....
Find the inverse for [A] for the following equation using LU Decomposition 8x1 + 4x2 -x3...
Find the inverse for [A] for the following equation using LU Decomposition 8x1 + 4x2 -x3 = 11 -2x1 + 5x2 + x3 = 4 2x1 - x2 + 6x3 = 7
Find [A]^-1 for the following equation using LU Decomposition and {x}. 3x1 - 2x2 + x3...
Find [A]^-1 for the following equation using LU Decomposition and {x}. 3x1 - 2x2 + x3 = -10 2x1 + 6x2 - 4x3 = 44 -x1 - 2x2 + 5x3 = -26
A manager is applying the Transportation Model of linear programming to solve an aggregate planning problem....
A manager is applying the Transportation Model of linear programming to solve an aggregate planning problem. Demand in period 1 is 100 units, and in period 2, demand is 150 units. The manager has 125 hours of regular employment available for $10/hour each period. In addition, 50 hours of overtime are available for $15/hour each period. Holding costs are $2 per unit each period. a. How many hours of regular employment should be used in period 1? (Assume demand must...
Write a MATLAB function function = myMatrixInveesion(....) to calculate matrix inversion by implementing LU decomposition, forward...
Write a MATLAB function function = myMatrixInveesion(....) to calculate matrix inversion by implementing LU decomposition, forward and backward substitution procedures. Do NOT use the built-in "lu" or "inv" commands in your code. You will need to employ Nested Loops. Thank you! function_____ = myMatrixInversion(_____)
Use the Laplace transform to solve the given initial value problem. y(4) − 4y''' + 6y''...
Use the Laplace transform to solve the given initial value problem. y(4) − 4y''' + 6y'' − 4y' + y = 0; y(0) = 1, y'(0) = 0, y''(0) = 0, y'''(0) = 1
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT