prct09 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +0 -0
- data/Gemfile +0 -0
- data/Guarfile +0 -0
- data/LICENSE.txt +0 -0
- data/README.md +0 -0
- data/Rakefile +0 -0
- data/bin/prct09 +0 -0
- data/doc/classes/Fraccion.html +365 -0
- data/doc/classes/Fraccion.src/M000024.html +19 -0
- data/doc/classes/Fraccion.src/M000025.html +18 -0
- data/doc/classes/Fraccion.src/M000026.html +18 -0
- data/doc/classes/Fraccion.src/M000027.html +20 -0
- data/doc/classes/Fraccion.src/M000028.html +18 -0
- data/doc/classes/Fraccion.src/M000029.html +18 -0
- data/doc/classes/Fraccion.src/M000030.html +18 -0
- data/doc/classes/Fraccion.src/M000031.html +18 -0
- data/doc/classes/Fraccion.src/M000032.html +18 -0
- data/doc/classes/Fraccion.src/M000033.html +18 -0
- data/doc/classes/Fraccion.src/M000034.html +30 -0
- data/doc/classes/Fraccion.src/M000035.html +18 -0
- data/doc/classes/Fraccion.src/M000036.html +18 -0
- data/doc/classes/Matriz.html +282 -0
- data/doc/classes/Matriz.src/M000015.html +20 -0
- data/doc/classes/Matriz.src/M000016.html +20 -0
- data/doc/classes/Matriz.src/M000017.html +17 -0
- data/doc/classes/Matriz.src/M000018.html +17 -0
- data/doc/classes/Matriz.src/M000019.html +17 -0
- data/doc/classes/Matriz.src/M000020.html +25 -0
- data/doc/classes/Matriz.src/M000021.html +32 -0
- data/doc/classes/Matriz.src/M000022.html +17 -0
- data/doc/classes/Matriz.src/M000023.html +17 -0
- data/doc/classes/Matriz_densa.html +199 -0
- data/doc/classes/Matriz_densa.src/M000010.html +42 -0
- data/doc/classes/Matriz_densa.src/M000011.html +42 -0
- data/doc/classes/Matriz_densa.src/M000012.html +44 -0
- data/doc/classes/Matriz_densa.src/M000013.html +29 -0
- data/doc/classes/Matriz_densa.src/M000014.html +29 -0
- data/doc/classes/Matriz_dispersa.html +269 -0
- data/doc/classes/Matriz_dispersa.src/M000002.html +29 -0
- data/doc/classes/Matriz_dispersa.src/M000003.html +34 -0
- data/doc/classes/Matriz_dispersa.src/M000004.html +52 -0
- data/doc/classes/Matriz_dispersa.src/M000005.html +52 -0
- data/doc/classes/Matriz_dispersa.src/M000006.html +48 -0
- data/doc/classes/Matriz_dispersa.src/M000007.html +29 -0
- data/doc/classes/Matriz_dispersa.src/M000008.html +31 -0
- data/doc/classes/Matriz_dispersa.src/M000009.html +31 -0
- data/doc/classes/Prct09.html +122 -0
- data/doc/classes/Test_Matriz.html +191 -0
- data/doc/classes/Test_Matriz.src/M000037.html +21 -0
- data/doc/classes/Test_Matriz.src/M000038.html +30 -0
- data/doc/classes/Test_Matriz.src/M000039.html +24 -0
- data/doc/classes/Test_Matriz.src/M000040.html +32 -0
- data/doc/created.rid +14 -0
- data/doc/files/lib/Fraccion_rb.html +101 -0
- data/doc/files/lib/Matriz_densa_rb.html +109 -0
- data/doc/files/lib/Matriz_dispersa_rb.html +109 -0
- data/doc/files/lib/Matriz_rb.html +108 -0
- data/doc/files/lib/mcd_rb.html +136 -0
- data/doc/files/lib/mcd_rb.src/M000001.html +22 -0
- data/doc/files/lib/prct09/version_rb.html +101 -0
- data/doc/files/lib/prct09_rb.html +108 -0
- data/doc/files/spec/Matriz_spec_rb.html +117 -0
- data/doc/files/test/tc_matriz_rb.html +112 -0
- data/doc/fr_class_index.html +32 -0
- data/doc/fr_file_index.html +35 -0
- data/doc/fr_method_index.html +66 -0
- data/doc/index.html +150 -0
- data/doc/rdoc-style.css +208 -0
- data/lib/Fraccion.rb +20 -14
- data/lib/Matriz.rb +13 -45
- data/lib/Matriz_densa.rb +30 -25
- data/lib/Matriz_dispersa.rb +40 -32
- data/lib/prct09/version.rb +1 -1
- data/lib/prct09.rb +0 -0
- data/prct09-0.0.1.gem +0 -0
- data/prct09.gemspec +0 -0
- data/spec/Matriz_spec.rb +21 -9
- data/test/tc_matriz.rb +5 -4
- metadata +64 -4
- data/.gitignore +0 -18
- data/lib/mcd.rb +0 -9
data/doc/rdoc-style.css
ADDED
@@ -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; }
|
data/lib/Fraccion.rb
CHANGED
@@ -3,7 +3,7 @@ class Fraccion
|
|
3
3
|
attr_reader :n, :d
|
4
4
|
|
5
5
|
include Comparable
|
6
|
-
|
6
|
+
#Calcula el máximo comun divisor de una fraccion
|
7
7
|
def mcd(a,b)
|
8
8
|
d = a.abs, b.abs
|
9
9
|
while d.min != 0
|
@@ -13,49 +13,55 @@ class Fraccion
|
|
13
13
|
end
|
14
14
|
private :mcd
|
15
15
|
|
16
|
-
#
|
16
|
+
#Constructor de la clase Fraccion
|
17
17
|
def initialize(n, d)
|
18
18
|
@n = n / mcd(n,d)
|
19
19
|
@d = d / mcd(n,d)
|
20
20
|
end
|
21
21
|
|
22
|
-
#
|
22
|
+
#Pasa a string el objeto Fraccion
|
23
23
|
def imprimirFraccion
|
24
24
|
"#{@n}/#{@d}"
|
25
25
|
end
|
26
26
|
|
27
|
-
#
|
27
|
+
#Pasa a flotante el objeto Fraccion
|
28
28
|
def imprimirFlotante
|
29
29
|
@n.to_f/@d.to_f
|
30
30
|
end
|
31
|
+
|
32
|
+
def coerce(other)
|
33
|
+
if (other.is_a?(Numeric))
|
34
|
+
[Fraccion.new(other.to_i,1),self]
|
35
|
+
end
|
36
|
+
end
|
31
37
|
|
32
|
-
|
33
|
-
|
38
|
+
|
39
|
+
#Sobrecarga del operador + para operar con fracciones
|
34
40
|
def + (other)
|
35
41
|
Fraccion.new(@n* other.d + other.n*@d, @d * other.d)
|
36
42
|
end
|
37
|
-
|
43
|
+
#Sobrecarga del operador - para operar con fracciones
|
38
44
|
def - (other)
|
39
45
|
Fraccion.new(@n* other.d - other.n*@d, @d * other.d)
|
40
46
|
end
|
41
|
-
|
47
|
+
#Sobrecarga del operador * para operar con fracciones
|
42
48
|
def * (other)
|
43
49
|
Fraccion.new(@n* other.n, @d * other.d)
|
44
50
|
end
|
45
|
-
|
51
|
+
#Sobrecarga del operador / para operar con fracciones
|
46
52
|
def / (other)
|
47
53
|
Fraccion.new(@n* other.d, @d * other.n)
|
48
54
|
end
|
49
|
-
|
55
|
+
#Sobrecarga del operador % para operar con fracciones
|
50
56
|
def % (other)
|
51
57
|
Fraccion.new((imprimirFlotante % other.imprimirFlotante*1000).to_i, 1000)
|
52
58
|
end
|
53
|
-
|
59
|
+
#Sobrecarga del <=> para poder comparar fracciones (==, <=, >=, ...)
|
54
60
|
def <=> (other)
|
55
61
|
imprimirFlotante <=> other.imprimirFlotante
|
56
62
|
end
|
57
63
|
|
58
|
-
#valor absoluto
|
64
|
+
#Calcula el valor absoluto
|
59
65
|
def abs
|
60
66
|
if (@n < 0) ^ (@d < 0)
|
61
67
|
if @n < 0
|
@@ -73,13 +79,13 @@ class Fraccion
|
|
73
79
|
end
|
74
80
|
|
75
81
|
|
76
|
-
#inverso de una fraccion
|
82
|
+
#Calcula el inverso de una fraccion
|
77
83
|
def reciprocal
|
78
84
|
Fraccion.new(@d, @n)
|
79
85
|
end
|
80
86
|
|
81
87
|
|
82
|
-
#
|
88
|
+
#Calcula el opuesto de una fraccion
|
83
89
|
def -@
|
84
90
|
Fraccion.new(@n*-1, @d)
|
85
91
|
end
|
data/lib/Matriz.rb
CHANGED
@@ -3,84 +3,50 @@ class Matriz
|
|
3
3
|
|
4
4
|
attr_accessor :filas, :cols, :matriz
|
5
5
|
|
6
|
+
#Constructor de la matriz
|
6
7
|
def initialize(m)
|
7
8
|
@filas = m.size
|
8
9
|
@cols = m[1].size
|
9
10
|
@matriz = m
|
10
11
|
end
|
11
12
|
|
13
|
+
#Función que imprime la matriz
|
12
14
|
def to_s ()
|
13
15
|
@matriz.each do |fila|
|
14
16
|
puts fila.join(" ")
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
20
|
+
#Definición de la sobrecarga del operador +
|
18
21
|
def + (other)
|
19
|
-
aux_m = Array.new
|
20
|
-
for i in 0...@filas do
|
21
|
-
aux_m[i] = Array.new
|
22
|
-
for j in 0...@cols do
|
23
|
-
aux_m[i][j] = 0;
|
24
|
-
end
|
25
|
-
end
|
26
|
-
for i in 0...@filas do
|
27
|
-
for j in 0...@cols do
|
28
|
-
aux_m[i][j] = @matriz[i][j] + other.matriz[i][j]
|
29
|
-
end
|
30
|
-
end
|
31
|
-
Matriz.new(aux_m).matriz
|
32
22
|
end
|
33
23
|
|
24
|
+
#Definición de la sobrecarga del operador -
|
34
25
|
def - (other)
|
35
|
-
aux_m = Array.new
|
36
|
-
for i in 0...@filas do
|
37
|
-
aux_m[i] = Array.new
|
38
|
-
for j in 0...@cols do
|
39
|
-
aux_m[i][j] = 0;
|
40
|
-
end
|
41
|
-
end
|
42
|
-
for i in 0...@filas do
|
43
|
-
for j in 0...@cols do
|
44
|
-
aux_m[i][j] = @matriz[i][j] - other.matriz[i][j]
|
45
|
-
end
|
46
|
-
end
|
47
|
-
Matriz.new(aux_m).matriz
|
48
26
|
end
|
49
27
|
|
28
|
+
#Definición de la sobrecarga del operador *
|
50
29
|
def * (other)
|
51
|
-
aux_m = Array.new
|
52
|
-
for i in 0...@filas do
|
53
|
-
aux_m[i] = Array.new
|
54
|
-
for j in 0...@cols do
|
55
|
-
aux_m[i][j] = 0;
|
56
|
-
end
|
57
|
-
end
|
58
|
-
for i in 0...@filas do
|
59
|
-
for j in 0...other.cols do
|
60
|
-
for k in 0...other.filas do
|
61
|
-
aux_m[i][j] += @matriz[i][k] * other.matriz[k][j]
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
Matriz.new(aux_m).matriz
|
66
30
|
end
|
67
31
|
|
32
|
+
#Calcula la traspuesta de una matriz y la devuelve según el tipo que sea
|
68
33
|
def traspuesta ()
|
69
34
|
aux_m = Array.new
|
70
|
-
|
35
|
+
@filas.times do |i|
|
71
36
|
aux_m[i] = Array.new
|
72
|
-
|
37
|
+
@cols.times do |j|
|
73
38
|
aux_m[i][j] = @matriz[(@filas-1)-i][(@cols-1)-j]
|
74
39
|
end
|
75
40
|
end
|
76
41
|
Matriz.new(aux_m).comprobar
|
77
42
|
end
|
78
43
|
|
44
|
+
#Comprueba la matriz y la devuelve según su tipo
|
79
45
|
def comprobar()
|
80
46
|
cont_total = 0
|
81
47
|
cont_ceros = 0
|
82
|
-
|
83
|
-
|
48
|
+
@filas.times do |i|
|
49
|
+
@cols.times do |j|
|
84
50
|
if @matriz[i][j] == 0
|
85
51
|
cont_ceros = cont_ceros + 1
|
86
52
|
end
|
@@ -94,9 +60,11 @@ def comprobar()
|
|
94
60
|
end
|
95
61
|
end
|
96
62
|
|
63
|
+
#Definición de el cálculo del máximo de una matriz
|
97
64
|
def max()
|
98
65
|
end
|
99
66
|
|
67
|
+
#Definición de el cálculo del mínimo de una matriz
|
100
68
|
def min()
|
101
69
|
end
|
102
70
|
|
data/lib/Matriz_densa.rb
CHANGED
@@ -2,17 +2,18 @@ require "Fraccion.rb"
|
|
2
2
|
require "Matriz.rb"
|
3
3
|
class Matriz_densa < Matriz
|
4
4
|
|
5
|
+
#Sobrecarga del operador + para operar con matrices densas y dispersas
|
5
6
|
def + (other)
|
6
7
|
aux_m = Array.new
|
7
|
-
|
8
|
+
@filas.times do |i|
|
8
9
|
aux_m[i] = Array.new
|
9
|
-
|
10
|
+
@cols.times do |j|
|
10
11
|
aux_m[i][j] = 0;
|
11
12
|
end
|
12
13
|
end
|
13
14
|
if other.is_a?(Matriz_dispersa)
|
14
|
-
|
15
|
-
|
15
|
+
@filas.times do |i|
|
16
|
+
@cols.times do |j|
|
16
17
|
if other.matriz[i.to_s+"_"+j.to_s] != nil
|
17
18
|
aux_m[i][j] = @matriz[i][j] + other.matriz[i.to_s+"_"+j.to_s]
|
18
19
|
else
|
@@ -21,8 +22,8 @@ def + (other)
|
|
21
22
|
end
|
22
23
|
end
|
23
24
|
elsif other.is_a?(Matriz_densa)
|
24
|
-
|
25
|
-
|
25
|
+
@filas.times do |i|
|
26
|
+
@cols.times do |j|
|
26
27
|
aux_m[i][j] = @matriz[i][j] + other.matriz[i][j]
|
27
28
|
end
|
28
29
|
end
|
@@ -30,17 +31,18 @@ def + (other)
|
|
30
31
|
Matriz.new(aux_m).comprobar()
|
31
32
|
end
|
32
33
|
|
34
|
+
#Sobrecarga del operador - para operar con matrices densas y dispersas
|
33
35
|
def - (other)
|
34
36
|
aux_m = Array.new
|
35
|
-
|
37
|
+
@filas.times do |i|
|
36
38
|
aux_m[i] = Array.new
|
37
|
-
|
39
|
+
@cols.times do |j|
|
38
40
|
aux_m[i][j] = 0;
|
39
41
|
end
|
40
|
-
end
|
42
|
+
end
|
41
43
|
if other.is_a?(Matriz_dispersa)
|
42
|
-
|
43
|
-
|
44
|
+
@filas.times do |i|
|
45
|
+
@cols.times do |j|
|
44
46
|
if other.matriz[i.to_s+"_"+j.to_s] != nil
|
45
47
|
aux_m[i][j] = @matriz[i][j] - other.matriz[i.to_s+"_"+j.to_s]
|
46
48
|
else
|
@@ -49,8 +51,8 @@ def - (other)
|
|
49
51
|
end
|
50
52
|
end
|
51
53
|
elsif other.is_a?(Matriz_densa)
|
52
|
-
|
53
|
-
|
54
|
+
@filas.times do |i|
|
55
|
+
@cols.times do |j|
|
54
56
|
aux_m[i][j] = @matriz[i][j] - other.matriz[i][j]
|
55
57
|
end
|
56
58
|
end
|
@@ -58,18 +60,19 @@ def - (other)
|
|
58
60
|
Matriz.new(aux_m).comprobar()
|
59
61
|
end
|
60
62
|
|
63
|
+
#Sobrecarga del operador * para operar con matrices densas y dispersas
|
61
64
|
def * (other)
|
62
65
|
aux_m = Array.new
|
63
|
-
|
66
|
+
@filas.times do |i|
|
64
67
|
aux_m[i] = Array.new
|
65
|
-
|
68
|
+
@cols.times do |j|
|
66
69
|
aux_m[i][j] = 0;
|
67
70
|
end
|
68
71
|
end
|
69
72
|
if other.is_a?(Matriz_dispersa)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
+
@filas.times do |i|
|
74
|
+
other.cols.times do |j|
|
75
|
+
other.filas.times do |k|
|
73
76
|
if other.matriz[k.to_s+"_"+j.to_s] != nil
|
74
77
|
aux_m[i][j] += @matriz[i][j] * other.matriz[k.to_s+"_"+j.to_s]
|
75
78
|
end
|
@@ -77,9 +80,9 @@ def * (other)
|
|
77
80
|
end
|
78
81
|
end
|
79
82
|
elsif other.is_a?(Matriz_densa)
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
+
@filas.times do |i|
|
84
|
+
other.cols.times do |j|
|
85
|
+
other.filas.times do |k|
|
83
86
|
aux_m[i][j] += @matriz[i][k] * other.matriz[k][j]
|
84
87
|
end
|
85
88
|
end
|
@@ -88,12 +91,13 @@ def * (other)
|
|
88
91
|
Matriz.new(aux_m).comprobar()
|
89
92
|
end
|
90
93
|
|
94
|
+
#Calcula el máximo de una matriz densa
|
91
95
|
def max()
|
92
96
|
|
93
97
|
aux_max = @matriz[0][0]
|
94
98
|
|
95
|
-
|
96
|
-
|
99
|
+
@filas.times do |i|
|
100
|
+
@cols.times do |j|
|
97
101
|
if aux_max < @matriz[i][j]
|
98
102
|
aux_max = @matriz[i][j]
|
99
103
|
end
|
@@ -103,12 +107,13 @@ def max()
|
|
103
107
|
aux_max
|
104
108
|
end
|
105
109
|
|
110
|
+
#Calcula el mínimo de una matriz densa
|
106
111
|
def min()
|
107
112
|
|
108
113
|
aux_min = @matriz[0][0]
|
109
114
|
|
110
|
-
|
111
|
-
|
115
|
+
@filas.times do |i|
|
116
|
+
@cols.times do |j|
|
112
117
|
if aux_min > @matriz[i][j]
|
113
118
|
aux_min = @matriz[i][j]
|
114
119
|
end
|