modai_prct12 0.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.travis.yml +6 -0
  4. data/Gemfile +9 -0
  5. data/Guardfile +346 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +31 -0
  8. data/Rakefile +6 -0
  9. data/documentacion/classes/MatrizAbstracta.html +144 -0
  10. data/documentacion/classes/MatrizAbstracta.src/M000032.html +21 -0
  11. data/documentacion/classes/MatrizDSL.html +212 -0
  12. data/documentacion/classes/MatrizDSL.src/M000028.html +36 -0
  13. data/documentacion/classes/MatrizDSL.src/M000029.html +20 -0
  14. data/documentacion/classes/MatrizDSL.src/M000030.html +27 -0
  15. data/documentacion/classes/MatrizDSL.src/M000031.html +40 -0
  16. data/documentacion/classes/MatrizDensa.html +345 -0
  17. data/documentacion/classes/MatrizDensa.src/M000016.html +18 -0
  18. data/documentacion/classes/MatrizDensa.src/M000017.html +37 -0
  19. data/documentacion/classes/MatrizDensa.src/M000018.html +27 -0
  20. data/documentacion/classes/MatrizDensa.src/M000019.html +44 -0
  21. data/documentacion/classes/MatrizDensa.src/M000020.html +41 -0
  22. data/documentacion/classes/MatrizDensa.src/M000021.html +29 -0
  23. data/documentacion/classes/MatrizDensa.src/M000022.html +37 -0
  24. data/documentacion/classes/MatrizDensa.src/M000023.html +28 -0
  25. data/documentacion/classes/MatrizDensa.src/M000024.html +28 -0
  26. data/documentacion/classes/MatrizDensa.src/M000025.html +35 -0
  27. data/documentacion/classes/MatrizDensa.src/M000026.html +18 -0
  28. data/documentacion/classes/MatrizDensa.src/M000027.html +37 -0
  29. data/documentacion/classes/MatrizDispersa.html +314 -0
  30. data/documentacion/classes/MatrizDispersa.src/M000033.html +22 -0
  31. data/documentacion/classes/MatrizDispersa.src/M000034.html +49 -0
  32. data/documentacion/classes/MatrizDispersa.src/M000035.html +33 -0
  33. data/documentacion/classes/MatrizDispersa.src/M000036.html +64 -0
  34. data/documentacion/classes/MatrizDispersa.src/M000037.html +66 -0
  35. data/documentacion/classes/MatrizDispersa.src/M000038.html +53 -0
  36. data/documentacion/classes/MatrizDispersa.src/M000039.html +31 -0
  37. data/documentacion/classes/MatrizDispersa.src/M000040.html +31 -0
  38. data/documentacion/classes/MatrizDispersa.src/M000041.html +35 -0
  39. data/documentacion/classes/MatrizDispersa.src/M000042.html +18 -0
  40. data/documentacion/classes/ModaiPrct12.html +147 -0
  41. data/documentacion/classes/Racional.html +380 -0
  42. data/documentacion/classes/Racional.src/M000002.html +24 -0
  43. data/documentacion/classes/Racional.src/M000003.html +18 -0
  44. data/documentacion/classes/Racional.src/M000004.html +22 -0
  45. data/documentacion/classes/Racional.src/M000005.html +18 -0
  46. data/documentacion/classes/Racional.src/M000006.html +18 -0
  47. data/documentacion/classes/Racional.src/M000007.html +18 -0
  48. data/documentacion/classes/Racional.src/M000008.html +18 -0
  49. data/documentacion/classes/Racional.src/M000009.html +23 -0
  50. data/documentacion/classes/Racional.src/M000010.html +23 -0
  51. data/documentacion/classes/Racional.src/M000011.html +23 -0
  52. data/documentacion/classes/Racional.src/M000012.html +23 -0
  53. data/documentacion/classes/Racional.src/M000013.html +23 -0
  54. data/documentacion/classes/Racional.src/M000014.html +19 -0
  55. data/documentacion/classes/Racional.src/M000015.html +18 -0
  56. data/documentacion/created.rid +1 -0
  57. data/documentacion/files/lib/modai_prct12/gcd_rb.html +132 -0
  58. data/documentacion/files/lib/modai_prct12/gcd_rb.src/M000001.html +22 -0
  59. data/documentacion/files/lib/modai_prct12/matrizAbstracta_rb.html +108 -0
  60. data/documentacion/files/lib/modai_prct12/matrizDSL_rb.html +105 -0
  61. data/documentacion/files/lib/modai_prct12/matrizDensa_rb.html +105 -0
  62. data/documentacion/files/lib/modai_prct12/matrizDispersa_rb.html +106 -0
  63. data/documentacion/files/lib/modai_prct12/racional_rb.html +114 -0
  64. data/documentacion/files/lib/modai_prct12/version_rb.html +101 -0
  65. data/documentacion/files/lib/modai_prct12_rb.html +112 -0
  66. data/documentacion/files/spec/modai_prct12_spec_rb.html +116 -0
  67. data/documentacion/files/spec/spec_helper_rb.html +114 -0
  68. data/documentacion/fr_class_index.html +32 -0
  69. data/documentacion/fr_file_index.html +36 -0
  70. data/documentacion/fr_method_index.html +68 -0
  71. data/documentacion/index.html +24 -0
  72. data/documentacion/rdoc-style.css +208 -0
  73. data/lib/modai_prct12.rb +26 -0
  74. data/lib/modai_prct12/gcd.rb +9 -0
  75. data/lib/modai_prct12/matrizAbstracta.rb +30 -0
  76. data/lib/modai_prct12/matrizDSL.rb +120 -0
  77. data/lib/modai_prct12/matrizDensa.rb +232 -0
  78. data/lib/modai_prct12/matrizDispersa.rb +280 -0
  79. data/lib/modai_prct12/racional.rb +121 -0
  80. data/lib/modai_prct12/version.rb +3 -0
  81. data/modai_prct12.gemspec +23 -0
  82. data/spec/modai_prct12_spec.rb +251 -0
  83. data/spec/spec_helper.rb +17 -0
  84. metadata +157 -0
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
5
+
6
+ <!--
7
+
8
+ RDoc Documentation
9
+
10
+ -->
11
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
12
+ <head>
13
+ <title>RDoc Documentation</title>
14
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
15
+ </head>
16
+ <frameset rows="20%, 80%">
17
+ <frameset cols="25%,35%,45%">
18
+ <frame src="fr_file_index.html" title="Files" name="Files" />
19
+ <frame src="fr_class_index.html" name="Classes" />
20
+ <frame src="fr_method_index.html" name="Methods" />
21
+ </frameset>
22
+ <frame src="files/lib/modai_prct12/racional_rb.html" name="docwin" />
23
+ </frameset>
24
+ </html>
@@ -0,0 +1,208 @@
1
+
2
+ body {
3
+ font-family: Verdana,Arial,Helvetica,sans-serif;
4
+ font-size: 90%;
5
+ margin: 0;
6
+ margin-left: 40px;
7
+ padding: 0;
8
+ background: white;
9
+ }
10
+
11
+ h1,h2,h3,h4 { margin: 0; color: #efefef; background: transparent; }
12
+ h1 { font-size: 150%; }
13
+ h2,h3,h4 { margin-top: 1em; }
14
+
15
+ a { background: #eef; color: #039; text-decoration: none; }
16
+ a:hover { background: #039; color: #eef; }
17
+
18
+ /* Override the base stylesheet's Anchor inside a table cell */
19
+ td > a {
20
+ background: transparent;
21
+ color: #039;
22
+ text-decoration: none;
23
+ }
24
+
25
+ /* and inside a section title */
26
+ .section-title > a {
27
+ background: transparent;
28
+ color: #eee;
29
+ text-decoration: none;
30
+ }
31
+
32
+ /* === Structural elements =================================== */
33
+
34
+ div#index {
35
+ margin: 0;
36
+ margin-left: -40px;
37
+ padding: 0;
38
+ font-size: 90%;
39
+ }
40
+
41
+
42
+ div#index a {
43
+ margin-left: 0.7em;
44
+ }
45
+
46
+ div#index .section-bar {
47
+ margin-left: 0px;
48
+ padding-left: 0.7em;
49
+ background: #ccc;
50
+ font-size: small;
51
+ }
52
+
53
+
54
+ div#classHeader, div#fileHeader {
55
+ width: auto;
56
+ color: white;
57
+ padding: 0.5em 1.5em 0.5em 1.5em;
58
+ margin: 0;
59
+ margin-left: -40px;
60
+ border-bottom: 3px solid #006;
61
+ }
62
+
63
+ div#classHeader a, div#fileHeader a {
64
+ background: inherit;
65
+ color: white;
66
+ }
67
+
68
+ div#classHeader td, div#fileHeader td {
69
+ background: inherit;
70
+ color: white;
71
+ }
72
+
73
+
74
+ div#fileHeader {
75
+ background: #057;
76
+ }
77
+
78
+ div#classHeader {
79
+ background: #048;
80
+ }
81
+
82
+
83
+ .class-name-in-header {
84
+ font-size: 180%;
85
+ font-weight: bold;
86
+ }
87
+
88
+
89
+ div#bodyContent {
90
+ padding: 0 1.5em 0 1.5em;
91
+ }
92
+
93
+ div#description {
94
+ padding: 0.5em 1.5em;
95
+ background: #efefef;
96
+ border: 1px dotted #999;
97
+ }
98
+
99
+ div#description h1,h2,h3,h4,h5,h6 {
100
+ color: #125;;
101
+ background: transparent;
102
+ }
103
+
104
+ div#validator-badges {
105
+ text-align: center;
106
+ }
107
+ div#validator-badges img { border: 0; }
108
+
109
+ div#copyright {
110
+ color: #333;
111
+ background: #efefef;
112
+ font: 0.75em sans-serif;
113
+ margin-top: 5em;
114
+ margin-bottom: 0;
115
+ padding: 0.5em 2em;
116
+ }
117
+
118
+
119
+ /* === Classes =================================== */
120
+
121
+ table.header-table {
122
+ color: white;
123
+ font-size: small;
124
+ }
125
+
126
+ .type-note {
127
+ font-size: small;
128
+ color: #DEDEDE;
129
+ }
130
+
131
+ .xxsection-bar {
132
+ background: #eee;
133
+ color: #333;
134
+ padding: 3px;
135
+ }
136
+
137
+ .section-bar {
138
+ color: #333;
139
+ border-bottom: 1px solid #999;
140
+ margin-left: -20px;
141
+ }
142
+
143
+
144
+ .section-title {
145
+ background: #79a;
146
+ color: #eee;
147
+ padding: 3px;
148
+ margin-top: 2em;
149
+ margin-left: -30px;
150
+ border: 1px solid #999;
151
+ }
152
+
153
+ .top-aligned-row { vertical-align: top }
154
+ .bottom-aligned-row { vertical-align: bottom }
155
+
156
+ /* --- Context section classes ----------------------- */
157
+
158
+ .context-row { }
159
+ .context-item-name { font-family: monospace; font-weight: bold; color: black; }
160
+ .context-item-value { font-size: small; color: #448; }
161
+ .context-item-desc { color: #333; padding-left: 2em; }
162
+
163
+ /* --- Method classes -------------------------- */
164
+ .method-detail {
165
+ background: #efefef;
166
+ padding: 0;
167
+ margin-top: 0.5em;
168
+ margin-bottom: 1em;
169
+ border: 1px dotted #ccc;
170
+ }
171
+ .method-heading {
172
+ color: black;
173
+ background: #ccc;
174
+ border-bottom: 1px solid #666;
175
+ padding: 0.2em 0.5em 0 0.5em;
176
+ }
177
+ .method-signature { color: black; background: inherit; }
178
+ .method-name { font-weight: bold; }
179
+ .method-args { font-style: italic; }
180
+ .method-description { padding: 0 0.5em 0 0.5em; }
181
+
182
+ /* --- Source code sections -------------------- */
183
+
184
+ a.source-toggle { font-size: 90%; }
185
+ div.method-source-code {
186
+ background: #262626;
187
+ color: #ffdead;
188
+ margin: 1em;
189
+ padding: 0.5em;
190
+ border: 1px dashed #999;
191
+ overflow: hidden;
192
+ }
193
+
194
+ div.method-source-code pre { color: #ffdead; overflow: hidden; }
195
+
196
+ /* --- Ruby keyword styles --------------------- */
197
+
198
+ .standalone-code { background: #221111; color: #ffdead; overflow: hidden; }
199
+
200
+ .ruby-constant { color: #7fffd4; background: transparent; }
201
+ .ruby-keyword { color: #00ffff; background: transparent; }
202
+ .ruby-ivar { color: #eedd82; background: transparent; }
203
+ .ruby-operator { color: #00ffee; background: transparent; }
204
+ .ruby-identifier { color: #ffdead; background: transparent; }
205
+ .ruby-node { color: #ffa07a; background: transparent; }
206
+ .ruby-comment { color: #b22222; font-weight: bold; background: transparent; }
207
+ .ruby-regexp { color: #ffa07a; background: transparent; }
208
+ .ruby-value { color: #7fffd4; background: transparent; }
@@ -0,0 +1,26 @@
1
+ require "./lib/modai_prct12/version"
2
+ require "./lib/modai_prct12/matrizAbstracta.rb"
3
+ require "./lib/modai_prct12/matrizDispersa.rb"
4
+ require "./lib/modai_prct12/matrizDensa.rb"
5
+ require "./lib/modai_prct12/matrizDSL.rb"
6
+
7
+ # = ejemplo_rdoc.rb
8
+ #
9
+ #Autor:: Dailos Herrera Bencomo and Mahrach Mohammed
10
+ # Web:: https://github.com/alu0100036862/prct12
11
+ #
12
+ # == MATRIZ## Con est clase pretendemos:
13
+ # - Poder trabajar con matrices de numeros interos y racionales.
14
+ # - Poder realizar operaciones entre diferentes tipo matrices y de diferentes argumentos.
15
+ # - Establecer relaciones de herencia entre las clases de tipo matrices partiendo de la ## === Clase Matriz abstracta
16
+ # - y hacer dos ejemplo de herencia en ste caso ## === Clase Matriz Dispersa y ## === Clase Matriz Densa
17
+ #
18
+ # Definición de las clases _Matriz_ _MatrizDensa_ y _MatrizDispersa_compuesta por la definición de
19
+ # * metodo initialize# * que heredarán las cvlases hijas y sobreescribir cuando es necesario
20
+ #
21
+ #
22
+ # - *rdoc*
23
+ module ModaiPrct12
24
+ # Your code goes here...
25
+ end
26
+
@@ -0,0 +1,9 @@
1
+ #=Calcula el maximo comun divisor de dos números
2
+
3
+ def gcd(u, v)
4
+ u, v = u.abs, v.abs
5
+ while v > 0
6
+ u, v = v, u % v
7
+ end
8
+ u
9
+ end
@@ -0,0 +1,30 @@
1
+
2
+ require './lib/modai_prct12/racional.rb'
3
+ # = ejemplo_rdoc.rb
4
+ #
5
+ #Autor:: Dailos Herrera Bencomo and Mahrach Mohammed
6
+ # Web:: https://github.com/alu0100036862/prct12
7
+ #
8
+ # == MATRIZ## Con est clase pretendemos:
9
+ # - Poder trabajar con matrices de numeros interos y racionales.
10
+ # - Poder realizar operaciones entre diferentes tipo matrices y de diferentes argumentos.
11
+ # - Establecer relaciones de herencia entre las clases de tipo matrices partiendo de la ## === Clase Matriz abstracta
12
+ # - y hacer dos ejemplo de herencia en ste caso ## === Clase Matriz Dispersa y ## === Clase Matriz Densa
13
+ #
14
+ # Definición de las clases _Matriz_ _MatrizDensa_ y _MatrizDispersa_compuesta por la definición de
15
+ # * metodo initialize# * que heredarán las cvlases hijas y sobreescribir cuando es necesario
16
+ #
17
+ #
18
+ # - *rdoc*
19
+
20
+ #= Clase abstracta para herencia común de matrices densa y dispersa
21
+ class MatrizAbstracta
22
+ $tope = 9999999999.9
23
+ # Inicialización
24
+ def initialize(matriz)
25
+ @matriz = matriz
26
+ @filas = matriz[0].size
27
+ @columnas = matriz[0].size
28
+
29
+ end
30
+ end
@@ -0,0 +1,120 @@
1
+ #= Clase de Matriz DSL
2
+ class MatrizDSL < MatrizAbstracta
3
+
4
+ #== Inicialización
5
+ def initialize(operacion)
6
+
7
+ @op_texto = operacion.to_s
8
+
9
+ # Por defecto la operación será & para devolver error
10
+ case @op_texto
11
+
12
+ when "suma"
13
+ @op = "+"
14
+ when "resta"
15
+ @op = "-"
16
+ when "producto"
17
+ @op = "*"
18
+ else
19
+ @op = "&"
20
+ end
21
+
22
+ @matA = nil
23
+ @matB = nil
24
+
25
+ end
26
+
27
+ attr_reader :matrizA, :matrizB
28
+
29
+ #== Asignamos la opción de matriz
30
+ def option(opc)
31
+
32
+ @claseMat = opc
33
+
34
+ end
35
+
36
+ #== Definimos el operando
37
+ def operand(other)
38
+
39
+
40
+ if(@matA == nil)
41
+ @matA = other
42
+ else
43
+ @matB = other
44
+ end
45
+
46
+ execute
47
+
48
+ end
49
+
50
+ #== Definimos la función de ejecución de la operación
51
+ def execute
52
+
53
+ # Comprobamos la validez de la operación
54
+ if @op = "&"
55
+ puts "La Operacion no es valida"
56
+ return 0
57
+ end
58
+
59
+ # Mostramos las matrices
60
+ if @matA != nil and @matB != nil
61
+
62
+ @matrizA = "Matriz" + @claseMat.to_s + ".new(@matA)"
63
+ puts "Matriz A: #{@matA}"
64
+
65
+ @matrizB = "Matriz" + @claseMat.to_s + ".new(@matB)"
66
+ puts "Matriz B: #{@matB}"
67
+
68
+ resultado = @matrizA.to_s + "." + @op.to_s + "(" + " " + @matrizB.to_s + ")"
69
+ puts "Resultado de la operacion ( " + @op_texto.to_s + " ): "
70
+ resultado = eval(resultado)
71
+ # puts "Resultado de la operacion ( " + @op_texto.to_s + " ): #{resultado}"
72
+
73
+ end
74
+
75
+ end
76
+
77
+ end
78
+
79
+ # SUMA DENSA
80
+ x = MatrizDSL.new("suma")
81
+ x.option "Densa"
82
+
83
+ x.operand [[1,2],[3,4]]
84
+ x.operand [[221,2],[3,4]]
85
+
86
+ # RESTA DENSA
87
+ y = MatrizDSL.new("resta")
88
+ y.option "Densa"
89
+
90
+ y.operand [[1,2],[3,4]]
91
+ y.operand [[221,2],[3,4]]
92
+
93
+ # PRODUCTO DENSA
94
+ z = MatrizDSL.new("producto")
95
+ z.option "Densa"
96
+
97
+ z.operand [[1,2],[3,4]]
98
+ z.operand [[221,2],[3,4]]
99
+
100
+ # SUMA DISPERSA
101
+ x = MatrizDSL.new("suma")
102
+ x.option "Dispersa"
103
+
104
+ x.operand [[1,2],[3,4]]
105
+ x.operand [[221,2],[3,4]]
106
+
107
+ # RESTA DISPERSA
108
+ y = MatrizDSL.new("resta")
109
+ y.option "Dispersa"
110
+
111
+ y.operand [[1,2],[3,4]]
112
+ y.operand [[221,2],[3,4]]
113
+
114
+
115
+ # PRODUCTO DISPERSA
116
+ z = MatrizDSL.new("producto")
117
+ z.option "Dispersa"
118
+
119
+ z.operand [[1,2],[3,4]]
120
+ z.operand [[221,2],[3,4]]
@@ -0,0 +1,232 @@
1
+ #= Clase de Matriz densa
2
+ class MatrizDensa < MatrizAbstracta
3
+
4
+ #== Inicialización
5
+ def initialize(matriz)
6
+ super
7
+ end
8
+
9
+ attr_reader :matriz, :filas, :columnas
10
+
11
+ #== Convertimos a string
12
+ def to_s
13
+
14
+ fil = 0
15
+ print "["
16
+ while fil < filas
17
+
18
+ col = 0
19
+ while col < columnas
20
+
21
+ print "#{matriz[fil][col].to_s}"
22
+ if (col + 1) < columnas then print ", " end
23
+ col += 1
24
+
25
+ end
26
+
27
+ if (fil + 1) < filas then print ", " end
28
+ fil += 1
29
+
30
+ end
31
+ print "]"
32
+
33
+ end
34
+
35
+ #== Matriz en punto flotante
36
+ def to_f
37
+
38
+ flotante = Array.new(matriz.size - 1)
39
+ for i in 0...matriz.size
40
+ flotante[i] = Array.new(matriz[i].size - 1)
41
+ for j in 0...matriz[i].size
42
+ flotante[i][j] = (matriz[i][j]).to_f
43
+ end
44
+ end
45
+ MatrizDensa.new(flotante)
46
+
47
+ end
48
+
49
+ #== Suma de matrices
50
+ def +(o)
51
+
52
+ if o.instance_of? MatrizDispersa
53
+ other = to_densa(o)
54
+ else
55
+ other = o
56
+ end
57
+
58
+ suma = Array.new(matriz.size - 1)
59
+
60
+ 0.upto(matriz.size - 1) do |i|
61
+ suma[i] = Array.new(matriz[i].size - 1)
62
+
63
+ # 0.upto(matriz[i].size - 1) do |j|
64
+
65
+ j = 0
66
+ (0...(matriz[i].size)).collect {
67
+
68
+ suma[i][j] = matriz[i][j] + other.matriz[i][j]
69
+ j += 1
70
+
71
+ }
72
+
73
+ # end
74
+
75
+ end
76
+ MatrizDensa.new(suma)
77
+
78
+ end
79
+
80
+ #== Suma de matrices densa con dispersa (sobreescribimos el operador / como prueba)
81
+ def /(o)
82
+
83
+ suma = Array.new(matriz.size - 1)
84
+
85
+ 0.upto(matriz.size - 1) do |i|
86
+ suma[i] = Array.new(matriz[i].size - 1)
87
+
88
+ 0.upto(matriz[i].size - 1) do |j|
89
+
90
+ suma[i][j] = matriz[i][j]
91
+
92
+ #=== comprobamos el hash
93
+ if (o.matriz[i] != nil)
94
+
95
+ #=== hay datos en el has para la columna
96
+ if o.matriz[i].has_key?(j)
97
+ suma[i][j] = matriz[i][j] + o.matriz[i][j]
98
+ end
99
+
100
+ end
101
+
102
+ end
103
+ end
104
+ MatrizDensa.new(suma)
105
+
106
+ end
107
+
108
+
109
+ #== Resta de matrices
110
+ def -(o)
111
+
112
+ resta = Array.new(matriz.size - 1)
113
+
114
+ 0.upto(matriz.size - 1) do |i|
115
+ resta[i] = Array.new(matriz[i].size - 1)
116
+
117
+ 0.upto(matriz[i].size - 1) do |j|
118
+ resta[i][j] = matriz[i][j] - o.matriz[i][j]
119
+ end
120
+ end
121
+ MatrizDensa.new(resta)
122
+
123
+ end
124
+
125
+ #== Multiplicación de matrices
126
+ def *(o)
127
+
128
+ prod = Array.new(matriz.size - 1,0)
129
+
130
+ 0.upto(matriz[0].size - 1) do |i|
131
+ prod[i] = Array.new(o.matriz.size,0)
132
+
133
+ (o.matriz.size).times do |j|
134
+
135
+ pos = 0
136
+ # 0.upto(matriz.size - 1) do |pos|
137
+ (0...(matriz.size)).collect {
138
+ prod[i][j] = prod[i][j] + (matriz[i][pos] * o.matriz[pos][j])
139
+ pos += 1
140
+ }
141
+ # end
142
+
143
+ end
144
+ end
145
+ MatrizDensa.new(prod)
146
+
147
+ end
148
+
149
+ #== Máximo de matriz
150
+ def max
151
+
152
+ maximo = 0.to_f
153
+ for i in 0...matriz.size
154
+ for j in 0...matriz[i].size
155
+ if matriz[i][j].to_f > maximo
156
+ maximo = matriz[i][j].to_f
157
+ end
158
+ end
159
+ end
160
+ maximo
161
+
162
+ end
163
+
164
+ #== Minimo de matriz
165
+ def min
166
+
167
+ minimo = $tope
168
+ for i in 0...matriz.size
169
+ for j in 0...matriz[i].size
170
+ if matriz[i][j].to_f < minimo
171
+ minimo = matriz[i][j].to_f
172
+ end
173
+ end
174
+ end
175
+ minimo
176
+
177
+ end
178
+
179
+ #== Pasamos de Dispersa a Densa
180
+ def to_densa(o)
181
+
182
+ densa = Array.new(o.matriz.size - 1)
183
+ for i in 0...o.matriz.size
184
+ densa[i] = Array.new(o.matriz.size - 1)
185
+ for j in 0...o.matriz.size
186
+ densa[i][j] = 0.to_f
187
+ if o.matriz[i] != nil
188
+ o.matriz[i].each do |key, value|
189
+ if key = j
190
+ densa[i][j] = o.matriz[i][key].to_f
191
+ end
192
+ end
193
+ end
194
+ end
195
+ end
196
+
197
+ MatrizDensa.new(densa)
198
+
199
+ end
200
+
201
+ #== El metodo coerce para onvierte el valor especificado en el tipo especificado.
202
+ def coerce(other)
203
+ return self, other
204
+ end
205
+
206
+
207
+ #== Devolvemos la posición del primer elemento cuyo cuadrado es mayor a 6
208
+ def encontrar
209
+
210
+ valor = "["
211
+
212
+ 0.upto(matriz.size - 1) do |i|
213
+
214
+ (matriz[i].size).times do |j|
215
+
216
+ if (yield(matriz[i][j]))
217
+
218
+ valor += "[#{i},#{j}]"
219
+
220
+ end
221
+
222
+ end
223
+ end
224
+
225
+ valor += "]"
226
+
227
+ valor
228
+
229
+ end
230
+
231
+ end
232
+