-
Notifications
You must be signed in to change notification settings - Fork 0
/
funciones.php
118 lines (98 loc) · 1.85 KB
/
funciones.php
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
<?php
function redondear($num,$decimales)
{
$aux = 1;
for($i=0 ;$i < $decimales ;$i++)
{
$aux = $aux*10;
}
$valor = round($num*$aux)/$aux;
return $valor;
}
function esDiagonalDominante($matriz,$fc)
{
for($i=1;$i<=$fc;$i++)
{
$sum = 0;
for($j=1;$j<=$fc;$j++)
{
$sum = $sum + abs($matriz[$i][$j]);
}
if ( abs($matriz[$i][$i]) >= ($sum-abs($matriz[$i][$i])) )
{
} else
{
return false;
}
}
return true;
}
function sePuedeConvertir($matriz,$fc)
{
$i=1;
$k=1;
while($i<=$fc && $k<=$fc)
{
$sum = 0;
for($j=1;$j<=$fc;$j++)
{
$sum = $sum + abs($matriz[$i][$j]);
}
if ( abs($matriz[$i][$k]) >= ($sum-abs($matriz[$i][$k])) )
{
$k++;
$i=0;
} elseif ($i == $fc)
{
return false;
}
$i++;
}
return true;
}
function convertirMatriz($matriz,$fc)
{
for($i=1;$i<=$fc;$i++)
{
$max = $matriz[$i][$i];
for($j=1;$j<=$fc;$j++)
{
if(abs($matriz[$i][$j]) >= abs($max))
{
$max = $matriz[$i][$j];
$imax = $i;
$jmax= $j;
}
}
for($aux=1;$aux<=$fc+1;$aux++)
{
$matrizAux[$jmax][$aux] = $matriz[$imax][$aux];
}
}
return $matrizAux;
}
function obtenerValor($matriz,$i,$fc,$arr,$decimales)
{
//$i representa una fila.
$numerador = $matriz[$i][$fc+1];
for($j=1;$j<=$fc;$j++)
{
$numerador = $numerador - redondear($matriz[$i][$j]*$arr[$j],$decimales);
}
$numerador = $numerador + redondear($matriz[$i][$i]*$arr[$i],$decimales);
return redondear($numerador/$matriz[$i][$i],$decimales);
}
function elevar2($num)
{
return $num*$num;
}
function obtenerNorma2($arr2,$arr,$fc,$decimales)
{
$valor = 0;
for($i=1;$i<=$fc;$i++)
{
$valor = $valor + elevar2(abs($arr2[$i] - $arr[$i]));
}
return redondear(sqrt($valor),$decimales);
}
?>