Using MATLAB, develop an M-file to determine LU factorization of a square matrix
ID: 3576272 • Letter: U
Question
Using MATLAB, develop an M-file to determine LU factorization of a square matrix with partial pivoting. That is, develop a function called mylu that is passed the square matrix [A] and returns the triangular matrices [L] and [U] and the permutation P. You are not to use MATLAB built-in function lu in your codes. Test your function by using it to solve a system of equations listed below in part 3. Confirm that your function is working properly by verifying that [L][U] = P[A] and by using the MATLAB built-in function lu. Using MATLAB, develop an M-file to determine matrix inverse based on the LU factorization method above. That is, develop a function called myinv that is passed the square matrix [A] and utilizing codes of part 1 above to return the inversed matrix. You are not to use MATLAB built-in function inv or left-division in your codes. Test your function by using it to solve a system of equations listed below in part 3. Confirm that your function is working properly by verifying that [A][A]^-1 = [1] and by using the MATLAB built-in function inv. Using MATLAB, develop an M-file for the Gauss-Seidel Method to solve the system of equations listed below until the percent relative error falls below Es = 5%. X_1 + x_2 + 5x_3 = 21.5 - 3x_1 - 6x_2 + 2x_3 = 61.5 10x_1 + 2x_2 = x_3 = 27Explanation / Answer
3)
%3) Gauss seidal method
close all
clear all
clc
format('long','g');
i = 1;
x2(i) = 0;
x3(i) = 1;
error_x3(i) = 9999;
while error_x3(i) >= 5
x1(i+1) = -21.5 - x2(i) - 5 * x3(i);
x2(i+1) = (61.5 - 3 * x1(i+1) + 2 * x3(i))/6;
x3(i+1) = -27 + (10 * x1(i+1)) + (2 * x2(i+1));
error_x1(i+1) = abs((x1(i+1) - x1(i))/x1(i+1)) * 100;
error_x2(i+1) = abs((x2(i+1) - x2(i))/x2(i+1)) * 100;
error_x3(i+1) = abs((x3(i+1) - x3(i))/x3(i+1)) * 100;
i = i + 1;
end
disp(' x1 error(%)');
disp([x1',error_x1']);
disp(' x2 error(%)');
disp([x2',error_x2']);
disp(' x3 error(%)');
disp([x3',error_x3']);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.