Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
35 views4 pages

Lu Decomposition

The document describes a MATLAB script for solving a system of linear equations represented as [A][X]=[r]. It includes user inputs for the number of equations, matrix A, and matrix r, and performs LU decomposition to find the solution vector x. The output displays the solutions for different sets of equations provided by the user.

Uploaded by

Lugabaluga
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views4 pages

Lu Decomposition

The document describes a MATLAB script for solving a system of linear equations represented as [A][X]=[r]. It includes user inputs for the number of equations, matrix A, and matrix r, and performs LU decomposition to find the solution vector x. The output displays the solutions for different sets of equations provided by the user.

Uploaded by

Lugabaluga
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

>> disp('Solution of N-equation "[A][X]=[r]"')

n=input ('Enter number of Equations :');


A=input ('Enter Matrix [A]:');
r=input ('Enter Matrix [r]:');
[L,U] = lu(A)
x=U\(L\r);
disp('Solutions are:(x1,x2,x3,...xn)');
disp (x);
Solution of N-equation "[A][X]=[r]"
Enter number of Equations :3
Enter Matrix [A]:[5 6 9; 5 4 8; 2 1 6]
Enter Matrix [r]:[5;6;5]
L=
1.0000
0
0
1.0000 1.0000
0
0.4000 0.7000 1.0000
U=
5.0000 6.0000 9.0000
0 -2.0000 -1.0000
0
0 3.1000
Solutions are:(x1,x2,x3,...xn)
0.7097
-0.8710
0.7419
>>
>> disp('Solution of N-equation "[A][X]=[r]"')
n=input ('Enter number of Equations :');
A=input ('Enter Matrix [A]:');
r=input ('Enter Matrix [r]:');
[L,U] = lu(A)
x=U\(L\r);
disp('Solutions are:(x1,x2,x3,...xn)');
disp (x);
Solution of N-equation "[A][X]=[r]"
Enter number of Equations :3
Enter Matrix [A]:[5 6 9; 5 4 8; 2 1 6]
Enter Matrix [r]:[5;6;5]
L=
1.0000

1.0000 1.0000
0
0.4000 0.7000 1.0000
U=
5.0000 6.0000 9.0000
0 -2.0000 -1.0000
0
0 3.1000
Solutions are:(x1,x2,x3,...xn)
0.7097
-0.8710
0.7419
>>
>> disp('Solution of N-equation "[A][X]=[r]"')
n=input ('Enter number of Equations :');
A=input ('Enter Matrix [A]:');
r=input ('Enter Matrix [r]:');
[L,U] = lu(A)
x=U\(L\r);
disp('Solutions are:(x1,x2,x3,...xn)');
disp (x);
Solution of N-equation "[A][X]=[r]"
Enter number of Equations :6
Enter Matrix [A]:[0.7460 -0.4516 0.0100 -0.0080 0.0100 -0.0080;0.4516 0.7460 0.0080 0.0100
0.0080 0.0100;0.0100 -0.0080 0.7787 -0.5205 0.0100 -0.0080;0.0080 0.0100 0.5205 0.7787
0.0080 0.0100;0.0100 -0.0080 0.0100 -0.0080 0.8080 -0.6040;0.0080 0.0100 0.0080 0.0100
0.6040 0.8080]
Enter Matrix [r]:[120; 0; -60; -103.9; -60; 103.9]
L=
1.0000
0.6054
0.0134
0.0107
0.0134
0.0107

0
1.0000
-0.0019
0.0146
-0.0019
0.0146

0
0
0
0
1.0000
0
0
0
0.6684 1.0000
0
0
0.0127 -0.0011 1.0000
0
0.0101 0.0134 0.7474 1.0000

U=
0.7460 -0.4516 0.0100 -0.0080 0.0100 -0.0080
0 1.0194 0.0019 0.0148 0.0019 0.0148
0
0 0.7786 -0.5204 0.0099 -0.0079
0
0
0 1.1264 0.0013 0.0151
0
0
0
0 0.8077 -0.6037
0
0
0
0
0 1.2590
Solutions are:(x1,x2,x3,...xn)
119.3331
-71.9734
-116.6607
-57.4316
13.9398
119.7439
>>

>> disp('Solution of N-equation "[A][X]=[r]"')


n=input ('Enter number of Equations :');
A=input ('Enter Matrix [A]:');
r=input ('Enter Matrix [r]:');
[L,U] = lu(A)
x=U\(L\r);
disp('Solutions are:(x1,x2,x3,...xn)');
disp (x);
Solution of N-equation "[A][X]=[r]"
Enter number of Equations :6
Enter Matrix [A]:[0.7460 -0.4516 0.0100 -0.0080 0.0100 -0.0080;0.4516 0.7460 0.0080 0.0100
0.0080 0.0100;0.0100 -0.0080 0.7787 -0.5205 0.0100 -0.0080;0.0080 0.0100 0.5205 0.7787
0.0080 0.0100;0.0100 -0.0080 0.0100 -0.0080 0.8080 -0.6040;0.0080 0.0100 0.0080 0.0100
0.6040 0.8080]
Enter Matrix [r]:[120; 0; -60; -103.9; -60; 103.9]
L=
1.0000
0
0
0
0
0
0.6054 1.0000
0
0
0
0
0.0134 -0.0019 1.0000
0
0
0

0.0107 0.0146 0.6684 1.0000


0
0
0.0134 -0.0019 0.0127 -0.0011 1.0000
0
0.0107 0.0146 0.0101 0.0134 0.7474 1.0000
U=
0.7460 -0.4516 0.0100 -0.0080 0.0100 -0.0080
0 1.0194 0.0019 0.0148 0.0019 0.0148
0
0 0.7786 -0.5204 0.0099 -0.0079
0
0
0 1.1264 0.0013 0.0151
0
0
0
0 0.8077 -0.6037
0
0
0
0
0 1.2590
Solutions are:(x1,x2,x3,...xn)
119.3331
-71.9734
-116.6607
-57.4316
13.9398
119.7439
>>

You might also like