Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I need help to solve this code whose a gauss partial pivoting. I have to change it from to a Gauss complete pivoting Here

Hello, I need help to solve this code whose a gauss partial pivoting.

I have to change it from to a Gauss complete pivoting Here is the code :

% Gaussian inversion with pivoting function x=mygausspivot(A,b)

if size(A,1) ~= size(A,2) error('Matrix is not square!)'); end; n=size(A,1); % Matrix triangualisation: for i=1:n % Searching for the pivoting line % disp([ 'Treatment of line i=' num2str(i) ] ); n_max=i; for m=i:n if abs(A(n_max,i)) < abs(A(m,i)) n_max=m; end end % disp([ 'Line with pivoting element n_max=' num2str(n_max) ] ); % exchangement of line i and pivoting line n_max in the matrix A and in the vector b for l=i:n tmp=A(i,l); A(i,l)=A(n_max,l); A(n_max,l)=tmp; end tmp=b(i); b(i)=b(n_max); b(n_max)=tmp;

p=A(i,i); % pivoting element % verification of non-generation of matrix if p==0 disp('Pivoting element is zero (matrix could be degenerated)!!!'); % error('Pivoting element is zero (matrix degenerated?)'); end

for k=i:n A(i,k)=A(i,k)/p; end b(i)=b(i)/p; for j=i+1:n r=A(j,i); for k=i:n A(j,k)=A(j,k)-A(i,k)*r; end b(j)=b(j)-b(i)*r; end end % In this point our matrix is, normally, upper triangular % (with ones on the diaganonal), % and we solving the folowing liniar equation: % 1 a_12 ... a_1N x_1 b_1 % 0 1 ... a_2N * x_2 = b_2 % 0 0 ......... . . % 0 0 ... 1 x_N b_N % x calculation from triangular matrix: x=b; for i=n-1:-1:1 for k=i+1:n x(i)=x(i)-x(k)*A(i,k); end end

% now x containes the solution end

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions