-
Notifications
You must be signed in to change notification settings - Fork 2
/
MatrizLU.pas
137 lines (104 loc) · 2.31 KB
/
MatrizLU.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// -------------------------------------------------------------
// Trabalho Conceito e Linguagens de Programacao
// Integrantes: Andre Peil, Daniel Retzlaff, Marlon Dias
// -------------------------------------------------------------
Program MatrizLU;
Type matriz = Record
a: array[1..100 , 1..100] of real;
upper: array [1..100 , 1..100] of real;
lower: array [1..100 , 1..100] of real;
End;
Var mat: matriz;
i, j, n : integer;
flag: boolean;
Procedure decompLU ();
Var temp: real;
k: integer;
Begin
For i:= 1 to n do
Begin
For j:= 1 to n do
Begin
if (i <= j) then
Begin
temp := 0;
For k := 1 to i do
Begin
temp := temp + (mat.lower[i, k]*mat.upper[k, j]);
End;
mat.upper[i, j] := mat.a[i, j] - temp;
End
Else
Begin
temp := 0;
For k := 1 to j do
Begin
temp := temp + (mat.lower[i, k] * mat.upper[k, j]);
End;
If (mat.upper[j, j] = 0) then
Begin
writeln('Erro... Divisao por Zero');
flag:=true;
exit;
End
Else
Begin
mat.lower[i, j] := (mat.a[i, j] - temp) / mat.upper [j, j];
End;
End;
End;
End;
End;
Begin
Repeat
write('Tamanho da Matriz: ');
readln(n);
if (n > 100) or (n <= 0) then
writeln('erro... valores validos entre 1 e 100.');
Until ((n <= 100) and (n > 0));
writeln('Matriz A: ');
// Leitura da matriz A e inicializacao de matris LU
For i := 1 to n do
Begin
For j := 1 to n do
Begin
write('A [',i, ',',j, ']: ');
readln(mat.a[i, j]);
mat.lower[i, j] := 0;
mat.upper[i, j] := 0;
End;
mat.lower[i, i] := 1;
End;
// Decomposicao LU
flag:=false;
decompLU();
// Impressao das matrizes
if (flag) then
exit;
writeln('');
writeln('Matriz Comp: ');
For i:= 1 to n do
Begin
writeln('');
For j:= 1 to n do
write(mat.a[i,j]:2:1,' ');
End;
writeln('');
writeln('');
writeln('Matriz Low: ');
For i:= 1 to n do
Begin
writeln('');
For j:= 1 to n do
write(mat.lower[i,j]:2:1,' ');
End;
writeln('');
writeln('');
writeln('Matriz Up: ');
For i:= 1 to n do
Begin
writeln('');
For j:= 1 to n do
write(mat.upper[i,j]:2:1,' ');
End;
End.