Matlab - eliminación gaussiana

 
Vista:

eliminación gaussiana

Publicado por Fidel Serrano (1 intervención) el 27/09/2013 04:18:28
Hola, tengo un problema para dejar una matriz diagonal. Soy capaz de sacar la matriz triangular superior pero de ahí en adelante tengo algo mal en el código que no sé qué es. Por favor, alguien que me diga que tengo que corregir.

Este es el código que estoy utilizando








row = input('Ingrese número de filas ');
column = input ('Ingrese número de columnas ');



for a = 1 : row
for b = 1 : column

valor = input('Ingrese valor de constante ');
matriz(a , b) = valor;
end
end
disp('La matriz es')
matriz


for c = 1 : row - 1
for f = 1 : column
if(c == f)
if matriz (c , f) == 0 && matriz (c + 1 , f) ~= 0
for a = c : row - 1
for b = 1 : column

arreglo2(b) = matriz(a , b);
arreglo3(b) = matriz(a + 1 , b);
end
end

for a = c : row - 1
for b = 1 : column

matriz(c , b) = arreglo3(b);
matriz(a + 1 , b) = arreglo2(b);
end
end

sprintf('Hubo un cambio entre la fila %d y %d', c, c + 1)
end
for a = c : row - 1
for b = 1 : column

arreglo(b) = matriz(c , b);
arreglo1(b) = matriz(a + 1 , b);
end

d = arreglo(c);
e = arreglo1(c);

for b = 1 : column

arreglo(b) = (arreglo(b)/d)*e;
arreglo1(b) = arreglo1(b) - arreglo(b);
end

for b = 1 : column
matriz(a + 1 , b) = arreglo1(b);
end
end
end
end
end

disp('La matriz con pivote parcial es')
matriz


for c = row : -1 : 1
for f = column : -1 : 1
if(c == f)
if( matriz(c , f) == 0)
continue;


for a = c: -1 : 1
for b = 1 : column

arreglo(b) = matriz(c , b);
arreglo1(b) = matriz (a - 1 , b);
end

d = arreglo(c);
e = arreglo1(c);

for b = 1 : column

arreglo(b) = (arreglo(b)/d)*e;
arreglo1(b) = arreglo1(b) - arreglo(b);
end

for b = 1 : column
matriz (a - 1 , b) = arreglo1(b);

end
end
end
end
end
end



disp('La matriz con pivote total es')
matriz



clear
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de JOSE JEREMIAS CABALLERO
Val: 6.975
Oro
Ha mantenido su posición en Matlab (en relación al último mes)
Gráfica de Matlab

eliminación gaussiana

Publicado por JOSE JEREMIAS CABALLERO (5917 intervenciones) el 28/09/2013 03:31:36
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
row = input('Ingrese número de filas ');
 column = input ('Ingrese número de columnas ');
 
 
 
 for a = 1 : row
 for b = 1 : column
 
 valor = input('Ingrese valor de constante ');
 matriz(a , b) = valor;
 end
 end
 disp('La matriz es')
 matriz
 
 
 for c = 1 : row - 1
 for f = 1 : column
 if(c == f)
 if matriz (c , f) == 0 && matriz (c + 1 , f) ~= 0
 for a = c : row - 1
 for b = 1 : column
 
 arreglo2(b) = matriz(a , b);
 arreglo3(b) = matriz(a + 1 , b);
 end
 end
 
 for a = c : row - 1
 for b = 1 : column
 
 matriz(c , b) = arreglo3(b);
 matriz(a + 1 , b) = arreglo2(b);
 end
 end
 
 sprintf('Hubo un cambio entre la fila %d y %d', c, c + 1)
 end
 for a = c : row - 1
 for b = 1 : column
 
 arreglo(b) = matriz(c , b);
 arreglo1(b) = matriz(a + 1 , b);
 end
 
 d = arreglo(c);
 e = arreglo1(c);
 
 for b = 1 : column
 
 arreglo(b) = (arreglo(b)/d)*e;
 arreglo1(b) = arreglo1(b) - arreglo(b);
 end
 
 for b = 1 : column
 matriz(a + 1 , b) = arreglo1(b);
 end
 end
 end
 end
 end
 
 disp('La matriz con pivote parcial es')
 matriz
 
 
 for c = row : -1 : 1
 for f = column : -1 : 1
 if(c == f)
 if( matriz(c , f) == 0)
 continue;
 
 
 for a = c: -1 : 1
 for b = 1 : column
 
 arreglo(b) = matriz(c , b);
 arreglo1(b) = matriz (a - 1 , b);
 end
 
 d = arreglo(c);
 e = arreglo1(c);
 
 for b = 1 : column
 
 arreglo(b) = (arreglo(b)/d)*e;
 arreglo1(b) = arreglo1(b) - arreglo(b);
 end
 
 for b = 1 : column
 matriz (a - 1 , b) = arreglo1(b);
 
 end
 end
 end
 end
 end
 end
 
 
 
 disp('La matriz con pivote total es')
 matriz
 for j=row:-1:2
     for i=j-1:-1:1
        matriz(i,:)=matriz(i,:)-(matriz(i,j)/matriz(j,j))*matriz(j,:);
     end
 end
matriz
 


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
>> eliminacion_gaussiana1_foro
La matriz es
 
matriz =
 
    0.3400    0.8467    0.2461    0.5815    0.9377
    0.0478    0.0540    0.0206    0.6815    0.5986
    0.1140    0.7962    0.6179    0.0702    0.0693
    0.1360    0.7889    0.0924    0.2379    0.2436
    0.1048    0.8584    0.6982    0.7337    0.6505
 
La matriz con pivote parcial es
 
matriz =
 
    0.3400    0.8467    0.2461    0.5815    0.9377
         0   -0.0650   -0.0140    0.5997    0.4668
         0         0    0.4253    4.5993    3.4320
         0         0         0    5.2679    3.9291
         0         0         0         0    0.1253
 
 
matriz =
 
    0.3400         0         0         0         0
         0   -0.0650         0         0         0
         0         0    0.4253         0         0
         0         0         0    5.2679         0
         0         0         0         0    0.1253
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar