Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a matlab for Gauss elimination using complete pivoting. Below is the code for partial pivoting...so following the same format and method (ie: adding to

Write a matlab for Gauss elimination using complete pivoting.

Below is the code for partial pivoting...so following the same format and method (ie: adding to the existing code), what would be the code for complete pivoting based on the definition provided?

Definition: "Before each row is normalized, it is advantageous to determine the coefficient with the largest absolute value in the column below the pivot element. The rows can then be switched so that the largest element is the pivot element. This is called partial pivoting. If columns as well as rows are searched for the largest element and then switched, the procedure is called complete pivoting"

image text in transcribed

Editable Code:

function x = GaussPivot(A,b)

% GaussPivot: Gauss elimination pivoting

% x = GaussPivot(A,b): Gauss elimination with pivoting.

% input:

% A = coefficient matrix

% b = right hand side vector

% output:

% x = solution vector

[m,n]=size(A);

if m~=n, error('Matrix A must be square'); end

nb=n+1;

Aug=[A b];

% forward elimination

for k = 1:n-1

% partial pivoting

[big,i]=max(abs(Aug(k:n,k)));

ipr=i+k-1;

if ipr~=k

Aug([k,ipr],:)=Aug([ipr,k],:);

end

for i = k+1:n

factor=Aug(i,k)/Aug(k,k);

Aug(i,k:nb)=Aug(i,k:nb)-factor*Aug(k,k:nb);

end

end

% back substitution

x=zeros(n,1);

x(n)=Aug(n,nb)/Aug(n,n);

for i = n-1:-1:1

x(i)=(Aug(i,nb)-Aug(i,i+1:n)*x(i+1:n))/Aug(i,i);

end

function x GaussPivot (A, b) % GaussPivot: Gauss elimination pivoting x Ga u s s Pivot (A, b) : Gauss elimination with pivoting. % input: A = coefficient matrix b = right hand side vector % output: x solution vector [m, n] size (A) If m~=n, error ("Matrix A must be square'); end nb-n+1; Aug- [A b]; % forward elimination for k -1:n-1 % partial pivoting big,i]-max (abs (Aug (k:n,k))) ipr-i+k-1 if ipr-k Aug ( [k, ipr) , : ) =Aug ( [ipr, k] , : ) ; end for i k+1 : n factor=Aug ( , k) /Aug (k, k) ; Aug (i.k:nb)-Aug (i.k:nb)-factor*Aug (k,k:nb ) ; end end % back substitution x= zeros (n, 1) ; x (n) -Aug (n, nb) /Aug (n, n) for i n-1:-1:1 x (i) (Aug (i, nb) -Aug (i,i+1:n)*x (i+1:n))/Aug (i,i); 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 And Expert Systems Applications 23rd International Conference Dexa 2012 Vienna Austria September 2012 Proceedings Part 1 Lncs 7446

Authors: Stephen W. Liddle ,Klaus-Dieter Schewe ,A Min Tjoa ,Xiaofang Zhou

2012th Edition

3642325998, 978-3642325991

More Books

Students also viewed these Databases questions