-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgaussConPivoteo_13-10214.m
48 lines (40 loc) · 1.21 KB
/
gaussConPivoteo_13-10214.m
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
function f = gaussConPivoteo(A, b)
MatExt = [A, b];
[n, ~] = size(A);
for k = 1:n-1
i0 = k;
for i = k+1:n
if abs(MatExt(i0, k)) < abs(MatExt(i, k))
i0 = i;
end
end
for j = 1:n+1
s = MatExt(i0, j);
MatExt(i0, j) = MatExt(k, j);
MatExt(k, j) = s;
end
%Si el pivote es cero, cambiamos filas
if MatExt(i, i) == 0
for j = i+1:n
if MatExt(j,i) ~= 0
for c = i:n
aux = MatExt(i,c);
MatExt(i,c) = MatExt(j,c);
MatExt(j,c) = aux;
end
break
end
end
end
%Si el pivote sigue siendo 0, el Sistema no tiene solucion.
if MatExt(i, i) == 0
break
end
for i = k+1:n
alpha = MatExt(i, k) / MatExt(k, k);
for j = k:n+1
MatExt(i, j) = MatExt(i, j) - alpha*MatExt(k, j);
end
end
end
f = MatExt;