Question: Matlab Question. Required Sample code below. %VeryNaiveGaussJordanElimination.m % This code uses an inefficient naive Gauss-Jordan elimination solve AX = B % It presumes no row
Matlab Question. Required Sample code below.

%VeryNaiveGaussJordanElimination.m
% This code uses an inefficient naive Gauss-Jordan elimination solve AX = B
% It presumes no row switching is required and the solution is unique
[m,n] = size(A);
if (rank(A) ~= n)
'matrix A is invalid for this code'
return
end
Aug = [A B];
for col_j = 1:n %For each column where there will be a leading 1
%Create leading 1 in row i, col_j: Row i = Row i/a(i,i)
row_i = col_j; %True for this type of coefficient matrix only
Aug(row_i,:) = Aug(row_i,:)/Aug(row_i,col_j);
%Create zeros above and below leading 1: Row ii = - Row ii (ii,j) Row i + Row ii
for row_ii = 1:m
if row_ii ~= row_i
Aug(row_ii,:) = -Aug(row_ii, col_j)*Aug(row_i,:) + Aug(row_ii,:);
end
end
end
X = Aug(:,n+1)
NEW CODE
Ngauussel.m
function ngaussel(A,b)
% Solve the system Ax=b using naive gaussian elimination
n=length(b);
x=zeros(n,1);
fprintf(' ');
disp(' The augmented matrix is')
augm =[A b]
for k=1:n-1
for i=k+1:n
m=A(i,k)/A(k,k);
for j=k+1:n
A(i,j)=A(i,j)-m*A(k,j);
end
A(i,k)=m;
b(i)=b(i)-m*b(k);
end
end
x(n)=b(n)/A(n,n);
for i=n-1:-1:1
S=b(i);
for j=i+1:n
S=S-A(i,j)*x(j);
end
x(i)=S/A(i,i);
end
% Print the results
fprintf(' ');
disp(' The transformed upper triangular augmented matrix C is =')
fprintf(' ');
for i=1:n
for j=1:n
if (j
end
end
C=[A b]
fprintf(' ');
disp(' Back substitution gives the vector solution')
x
Question 4: Naive Elimination 16 points a Very Naive Gauss JordanElimination.m is inefficient because it performs unnecessary operations. For example, defining cols (col j+1): (n +1), and replacing Line 16 with the two lines of code Aug row i,cols) /Aug row i,col j) Aug (row i r cols) Aug (row i r col j results in the same new row i that is calculated using col j fewer divisions. Provide two lines of code to replace Line 21 that similarly reduce the unnecessary operations performed at that line Here you can assume that cols has already been defined. b) VeryNaiveGaussJordanElimination.m can easily be modified such that it implements Gaussian Elimination i.e. forward only by replacing Lines 19-23 with the code for row ii row i 1 m. Aug row i, Aug row ii, Aug (row ii Aug (row ii Col J end Complete the code below such that it implements the matrix form of Back Substitution discussed in class on the matrix Aug that results from the Gaussian Elimination above for col j col row l for ii Aug row ii col j *Auq row i Aug (row ii, Aug (row ii, end end c Most Gaussian Elimination codes do not create leading 1s during the forward step. Instead they divide the row by the pivot value in the Back Substitution step. State the Line number of the textbook's ngaussel.m where the division occurs d) Many Back Substitution codes do not use the approach we did in class, in which one variable is eliminated from all-but-one equation at each step. Instead they eliminate all-but-one variable from one equation at each step. (i) Fill in the blanks: This alternative approach is the same as going row by row, from the to the State creating zeros where (ii) Lines 20 24 in the textbook's ngaussel.m calculate x(i) using a for loop. Write a 24 of GaussNaivem produces the identical calculation for x(i) as in (ii) using multiplication of two matrices instead of the inner for loop. Defining this matrix product as CD, state the sizes of both matrices, and clearly indicate what are the elements cij and dij
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
