Question

USING MATLAB/SCILAB: Given the following set of linear equations, solve using LU DECOMPOSITION x1 + 2x2...

USING MATLAB/SCILAB: Given the following set of linear equations, solve using LU DECOMPOSITION x1 + 2x2 - x3 + x4 = 5 -x1 - 2x2 - 3x3 + 2x4 = 7 2x1 + x2 - x3 - 5x4 = -1 x1 + x2 + x3 + x4 = 10 Please show me pictures of the matlab/scilab compiler or copy-paste code and output

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

A = [
1 2 -1 1;
-1 -2 -3 2;
2 1 -1 -5;
1 1 1 1
];
r = [5;7;-1;10];
n = 4;

D=A;d=r;

s=0;
for j=1:n-1
if A(j,j)==0
k=j;
for k=k+1:n
if A(k,j)==0
continue
end
break
end
B=A(j,:); C=r(j);
A(j,:)=A(k,:); r(j)=r(k);
A(k,:)=B; r(k)=C;
end
for i=1+s:n-1
L=A(i+1,j)/A(j,j);
A(i+1,:)=A(i+1,:)-L*A(j,:);
r(i+1)=r(i+1)-L*r(j);
end
s=s+1;
end
%-----------------------------------------------------------------
%Solution of equations
x(n)=r(n)/A(n,n);
for i=n-1:-1:1
sum=0;
for j=i+1:n
sum=sum+A(i,j)*x(j);
end
x(i)=(1/A(i,i))*(r(i)-sum);
end

%------------------------------
%Output
disp('@----------------------------------------------------------@')
disp('Output [A][x]=[b]')
disp('Upper riangular Matrix [B] =');disp(A)
disp('Matrix [b] =');disp(r)
disp('solution of linear equations :');disp(x')

Sample run

Output [A][x]=[b]
Upper riangular Matrix [B] =
   1.00000   2.00000  -1.00000   1.00000
   0.00000  -3.00000   1.00000  -7.00000
   0.00000   0.00000  -4.00000   3.00000
   0.00000   0.00000   0.00000   3.58333
Matrix [b] =
    5.0000
  -11.0000
   12.0000
   13.6667
solution of linear equations :
   11.60465
   -5.27907
   -0.13953
    3.81395
Add a comment
Know the answer?
Add Answer to:
USING MATLAB/SCILAB: Given the following set of linear equations, solve using LU DECOMPOSITION x1 + 2x2...
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