Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Title : Matlab code for gauss partial pivoting to gauss complete pivoting. Hello, I need help to change my matlab program from my gauss partial

Title : Matlab code for gauss partial pivoting to gauss complete pivoting. Hello, I need help to change my matlab program from my gauss partial pivoting to gauss complete pivoting. I know that Partial pivoting is the interchanging of rows and complete pivoting is the interchanging of both rows and columns in order to place a particularly "good" element in the diagonal position prior to a particular operation.

Here is the code for partial pivoting :

% 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

Database Horse Betting The Road To Absolute Horse Racing 2

Authors: NAKAGAWA,YUKIO

1st Edition

B0CFZN219G, 979-8856410593

More Books

Students also viewed these Databases questions

Question

How do information systems relate to operations management?

Answered: 1 week ago