Question

(Use MATLAB) Use Gaussian elimination with backward substitution to solve the following linear sy...

(Use MATLAB) Use Gaussian elimination with backward substitution to solve the following linear system. For this problem you will have to do scaled partial pivoting. The matrix A and the vector b are in the Matlab code shown below

A=[3 -13 9 3;-6 4 1 -18;6 -2 2 4;12 -8 6 10];
display(A);
b=[-19;-34;16;26];
display(b);

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the required MATLAB script as the following:

%==================================================

clear all;
clc;

% Given data
A=[3 -13 9 3;-6 4 1 -18;6 -2 2 4;12 -8 6 10];
display(A);
b=[-19;-34;16;26];
display(b);


% Preliminary calculation
n=length(A(:,1));
A=[A,b];
x=zeros(n,1);
flag=0;
NROW=1:n;


for i=1:n-1
    if flag==0
        M=max(abs(A(NROW(i:n),i)));
        if M==0
            flag=1;
        else
            I=find(abs(A(NROW(i:n),i))==M);
            p=I(1)+i-1;
            if p>i
                NCOPY=NROW(i);
                NROW(i)=NROW(p);
                NROW(p)=NCOPY;
            end
        end
        if flag==0
            for j=i+1:n
                m=A(NROW(j),i)/A(NROW(i),i);
                A(NROW(j),i:n+1)=A(NROW(j),i:n+1)-m*A(NROW(i),i:n+1);
                clear m;
            end
        end
    end
end
if flag==0
   if A(NROW(n),n)==0
      flag=1;
   end
end
if flag==0
    x(n,1)=A(NROW(n),n+1)/A(NROW(n),n);
    for i=n-1:-1:1
        x(i,1)=(A(NROW(i),n+1)-sum(x(i+1:n,1)'.*A(NROW(i),i+1:n)))/A(NROW(i),i);
    end
else
    x='no unique solution may exist';
end
display('The solution is: ');
display(x);

%==================================================

output:

A- 3 13 9 3 1 18 6 2 24 12 8 6 10 -6 4 -19 -34 LES 26 The solution is: 3.0000 L. -2.0000 L.

Add a comment
Know the answer?
Add Answer to:
(Use MATLAB) Use Gaussian elimination with backward substitution to solve the following linear sy...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT