Using MATLAB Solve for X1 X2 X3 1In MATLAB using the inverse

Using MATLAB

Solve for X1, X2, X3

1)In MATLAB (using the inverse of the A Matrix)

2)In MATLAB (using the \"\\\" command)

Now rewrite as AX=B

Given the system of linear equations 4x1 8x3 54 2x1 7x2 3x3 116 1x1 4x2 9x3 80

Solution

Let X=[x1,x2,x3]

1.)

Matlab code :

A=[4 1 8;2 7 3;1 4 9];
B=[54 116 80]\';
X=inv(A)*B

Output :

X =

6.0000
14.0000
2.0000

2.)

Matlab code :

A=[4 1 8;2 7 3;1 4 9];
B=[54 116 80]\';
X=A\\B

Output :

X =

6.0000
14.0000
2.0000

a.)

Matlab code to create U :

A=[4 1 8;2 7 3;1 4 9];
B=[54 116 80]\';

a=[A,B];
[m,n]=size(a);
for i=1:n-2
for j=i+1:m
d=(a(j,i)/a(i,i));
for k=1:n
a(j,k)=a(j,k)-d*a(i,k);
end
end
end
U=a(:,1:n-1)
Y=a(:,n)

Output:

U =

4.0000 1.0000 8.0000
0 6.5000 -1.0000
0 0.0000 7.5769

Y =

54.0000
89.0000
15.1538

b.)

Using backward substitution, we get

7.5769 x3= 15.1538 gives x3=2

6.5000x2 -1.0000x3=89.0000 gives us x2=14

4.0000x1 +1.0000 x2 + 8.0000x3=54.0000 gives us x1=6

c.)

Matlab code:

[L, U]=lu(A)

Y=L\\B

Output:

L =

1.0000 0 0
0.5000 1.0000 0
0.2500 0.5769 1.0000


U =

4.0000 1.0000 8.0000
0 6.5000 -1.0000
0 0 7.5769

This is the same U that we got in part a.)

Y=

54.0000
89.0000
15.1538

d.)

Matlab code:

X=U\\Y

Output :

X =

6.0000
14.0000
2.0000

Using MATLAB Solve for X1, X2, X3 1)In MATLAB (using the inverse of the A Matrix) 2)In MATLAB (using the \
Using MATLAB Solve for X1, X2, X3 1)In MATLAB (using the inverse of the A Matrix) 2)In MATLAB (using the \
Using MATLAB Solve for X1, X2, X3 1)In MATLAB (using the inverse of the A Matrix) 2)In MATLAB (using the \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site