10) a) Continue the previous problem by writing a MATLAB code to solve Gaussian
ID: 3911863 • Letter: 1
Question
10) a) Continue the previous problem by writing a MATLAB code to solve Gaussian elimination with PARTIAL pivoting by modifying the faster Gaussian elimination with no pivoting code. Verify that the code is working correctly by using matrices for which partial pivoting occurs at least twice. Note: I know that MATLAB does Gaussian elimination for you, but everyone should have to write such a code once in their lives to make sure they thoroughly understand it b) Write a MATLAB code to solve Gaussian elimination with FULL pivoting by modifying the partial pivoting code.Explanation / Answer
clc,close all,clear all; disp('Solution of N-equation "[A][X]=[r]"') nn=input ('Enter number of Equations :'); aa=input ('Enter Matrix [A]:'); rr=input ('Enter Matrix [r]:'); %create upper triangular matrix s=0; for j=1:nn-1 if A(j,j)==0 k=j; for k=k+1:nn if A(k,j)==0 continue end break end B=aa(j,:); C=rr(j); aa(j,:)=aa(k,:); rr(j)=rr(k); aa(k,:)=B; r(k)=C; end for i=1+s:n-1 L=aa(i+1,j)/aa(j,j); aa(i+1,:)=aa(i+1,:)-L*aa(j,:); rr(i+1)=rr(i+1)-L*rr(j); end s=s+1; end %Solution of equations x(n)=rr(n)/a(n,n); for i=n-1:-1:1 sum=0; for j=i+1:n sum=sum+aa(i,j)*x(j); end x(i)=(1/aa(i,i))*(rr(i)-sum); end %------------------------------ %Checking with matlab functions p=inv(D)*d; %------------------------------ %Output disp('------------------------------------------------------') disp('Output [B][x]=[b]') disp('Upper riangular Matrix [B] =');disp(a) disp('Matrix [b] =');disp(rr) disp('solution of linear equations :');disp(x') disp('solve with matlab functions(for checking):');disp(p)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.