% % Naive Gauss elimination: % % Input matrix A and vector b for the system Ax=b. % % Within matlab call function as follows: % % >> [U,B,x]=GaussNaive(A,b,trace) % % The output is the upper echelon U (and % associated vector B) obtained using naive % gauss elimination. % % If trace==1 then the routine pauses after % every row operation and prints out the current % U. % % The vector x is the solution of Ax=b obtained % by backsubstitution of: % % Ux=B % function [U,B,x]=GaussNaive(A,b,trace) U=A; B=b; n=length(B); if trace ==1 U pause end; for k=1:(n-1) for i=(k+1):n xmult=U(i,k)/U(k,k); U(i,k)=0; for j=(k+1):n U(i,j)=U(i,j)-xmult*U(k,j); end; B(i)=B(i)-xmult*B(k); if trace==1 U pause end; end; end; % y(n)=B(n)/U(n,n); for i=(n-1):(-1):1 s=B(i); for j=(i+1):n s=s-U(i,j)*y(j); end; y(i)=s/U(i,i); end; x=y'; % %