In Matlab Write a Gaussian Elimination Code The program can able solve for \'n\'
ID: 3831345 • Letter: I
Question
In Matlab
Write a Gaussian Elimination Code The program can able solve for 'n' number of unknowns given 'n' equations. Print the final values of the unknowns (3 digits after the decimal point) to the screen in a user friendly format. Notes: Two sets of equations are given below to enable you to test the robustness of the program, but the program must also work for any other 'n', where 'n' is an integer. Write a Gauss Seidel Code Perform the same tasks above for the Gauss Seidel method. Compare your solution by calculating the TRE between your solutions. The solution is considered sufficiently good when the absolute relative error is less than 0.01% Permitted MATLAB Functions (use of other functions will result in a zero grade for the home work):Explanation / Answer
function [L, U]= nopivot lu(A)
[m, n]=size(A);
for k = 1: n 1
A(k + 1: m, k) = A(k + 1: m, k)/A(k, k);
for j = k + 1: n
A(k + 1: m, j) = A(k + 1: m, j) A(k + 1: m, k) A(k, j);
end;
end;
L = eye(m, n) + tril(A, 1);
U = triu(A);
Notice that this allows A to be rectangular (non square) with m n. For
general m and n see www.cse.psu.edu/barlow/cse455/goodfact.m .
In MATLAB it is best to get rid of the loops. The main loop could be
for k = 1: n 1
A(k + 1: m, k) = A(k + 1: m, k)/A(k, k);
A(k + 1: m, k + 1: n) = A(k + 1: m, k + 1: n) A(k + 1: m, k) A(k, k + 1: n);
end;
1
Better (in terms of structure and understandability).
for k = 1: n 1
ii = k + 1: m; % A row vector with row indicies
A(ii, k) = A(ii, k)/A(k, k);
jj = k + 1: n; % Another row vector with column indicies
A(ii, jj) = A(ii, jj) A(ii, jj) A(ii, k) A(k, jj);
end;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.