Showing Page:
1/4
b. Solve system (1.2) using your code from part a. Also,
determine whether or not the matrices L and U that you
found approximately satisfy A= LUusing norm(A-
L*U)/norm(A) in Matlab, which finds the matrix 2-norm of
the error matrix A - L * Uand divides it by norm(A). 1. A set
of experiments has found that the specific volume v of
saturated steam in m3/Kg at six dimensionless temperature
T values of 1, 2, 3, 4, 5, and 6 (where 1 represents 10°C in
physical units) is respectively 106.4, 57.79, 32.9, 19.52,
12.03, and 7.67. A fifth-degree polynomial of the form: can
be used to represent volume v as a function of temperature
T. The unknown coefficients x1, X2, X3, x4, xs, and x6 can be
found by solving the following system of linear algebraic
equations obtained by substituting the given data in
equation (1.1): X1 + X2 + X3 +X,+X5 + X6 = 106.4 x1 2x2
22x3 23x424xs +25x6 57.7 x1 3x2 +32x3 +33x4+34xs +35x6
32.9 X1 + 4X2 + 42X3 + 43X4 + 44X5 + 45X6-1952 x1 5x2
52x3 +53x4+5*xs +55x6 12.03 X1 + 6X2 + 62X3 + 63X4 +
64X5 + 65X6-7.67
Solution
The code is as follows:
function[x]=LU_Decompos(A,B)
clc
[m,n]=size(A);
if (m ~= n )
Showing Page:
2/4
disp ( \'LR2 error: Matrix must be square\' );
return;
end;
% Part 2 : Decomposition of matrix into L and U
L=zeros(m,m);
U=zeros(m,m);
for i=1:m
% Finding L
for k=1:i-1
L(i,k)=A(i,k);
for j=1:k-1
L(i,k)= L(i,k)-L(i,j)*U(j,k);
end
L(i,k) = L(i,k)/U(k,k);
end
% Finding U
for k=i:m
U(i,k) = A(i,k);
for j=1:i-1
U(i,k)= U(i,k)-L(i,j)*U(j,k);
end
end
end
for i=1:m
L(i,i)=1;
Showing Page:
3/4
end
% Program shows U and L
U
L
Ly=zeros(m,1); % initiation for y
y(1)=B(1)/L(1,1);
for i=2:m
%y(i)=B(i)-L(i,1)*y(1)-L(i,2)*y(2)-L(i,3)*y(3);
y(i)=-L(i,1)*y(1);
for k=2:i-1
y(i)=y(i)-L(i,k)*y(k);
end;
y(i)=(B(i)+y(i))/L(i,i);
end;
% Now we use this y to solve Ux = y
x=zeros(m,1);
x(m)=y(m)/U(m,m);
i=m-1;
q=0;
while (i~= 0)
x(i)=-U(i,m)*x(m);
q=i+1;
while (q~=m)
x(i)=x(i)-U(i,q)*x(q);
q=q+1;
Showing Page:
4/4
end;
x(i)=(y(i)+x(i))/U(i,i);
i=i-1;
end;
end
For part (b)
clear all
clc
for i=1:6
for j=1:6
A(i,j)=i^(j-1);
end
end
A;
b=[106.4,57.7,32.9,19.52,12.03,7.67]\';
LU_Decompos(A,b)

Unformatted Attachment Preview

Name: Description: ...
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.
Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4