matrix_disp 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/Rakefile +5 -0
- data/lib/matrix_disp/version.rb +1 -1
- data/lib/matrix_disp.rb +474 -527
- data/matrix_disp.gemspec +2 -2
- data/spec/matrix_disp_spec.rb +4 -4
- metadata +5 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 90f3a171022a59a76588af5a17118568b36c015b
|
|
4
|
+
data.tar.gz: 9cb596c942318ba7d8575a6cd84b0d061df4f13b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ca4c07378b2dad9f7ed7b0da6cdbc7a6c9131341421c4bad23fb271ce5ef02a1869d2a5c8fa0b573c8652f11f794d51d5c1bcae691b71eca2e43c69fc7b9b46a
|
|
7
|
+
data.tar.gz: e7956434933c72595d68fd98579506e8cebd5b4bacaa11fffae2b9ed9dc5e189355a4eac2aa7bb4208fd1dc9cc2d0e962e1c8fe6f93fe73d0781280b3dbaad0c
|
data/Rakefile
CHANGED
data/lib/matrix_disp/version.rb
CHANGED
data/lib/matrix_disp.rb
CHANGED
|
@@ -1,567 +1,514 @@
|
|
|
1
1
|
#require "matrix_disp/version"
|
|
2
2
|
|
|
3
3
|
module Math
|
|
4
|
-
|
|
5
|
-
class Matriz
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
4
|
+
#Clase encargada de definir una matriz según el número de ceros.
|
|
5
|
+
class Matriz
|
|
6
|
+
#recoge el número de filas, número de columnas y un vector con los valores de la matriz.
|
|
7
|
+
def initialize (f,c,v)
|
|
8
|
+
@f, @c = f, c
|
|
9
|
+
@v = v
|
|
10
|
+
end
|
|
11
|
+
#define el tipo de matriz y crea un objeto de matriz dispersa o de matriz densa según el número de ceros.
|
|
12
|
+
def def_tipo
|
|
13
|
+
if (((@v.count{|e| e == 0}*100)/(@f*@c)) >= 60)
|
|
14
|
+
resultado = SparseMatrix.new
|
|
15
|
+
for i in (0...@f*@c)
|
|
16
|
+
tmp = SparseVector.new
|
|
17
|
+
if @v[i] != 0
|
|
18
|
+
if resultado.matrix[i%@c].is_a? SparseVector
|
|
19
|
+
resultado.matrix[i%@c][i/@f] = @v[i]
|
|
20
|
+
else
|
|
21
|
+
tmp[i/@f] = @v[i]
|
|
22
|
+
resultado.matrix[i%@c] = tmp
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
return resultado
|
|
27
|
+
else
|
|
28
|
+
return DenseMatrix.new(@f,@c,@v)
|
|
24
29
|
end
|
|
25
|
-
return resultado
|
|
26
|
-
else
|
|
27
|
-
return DenseMatrix.new(@f,@c,@v)
|
|
28
30
|
end
|
|
29
31
|
end
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
gcd #reduce la fracción
|
|
46
|
-
end
|
|
47
|
-
#método que reduce la fracción calculando el mcd y dividiendolo entre el numerador y el denominador
|
|
48
|
-
def gcd
|
|
49
|
-
mcd, v = @num.abs, @denom.abs
|
|
50
|
-
while v > 0
|
|
51
|
-
mcd, v = v, mcd % v
|
|
52
|
-
end
|
|
53
|
-
@num = @num/mcd
|
|
54
|
-
@denom = @denom/mcd
|
|
55
|
-
end
|
|
56
|
-
#método que muestra la fracción en la forma a/b
|
|
57
|
-
def to_s
|
|
58
|
-
"#{@num}/#{@denom}"
|
|
59
|
-
#puts "#{@num}/#{@denom}"
|
|
60
|
-
#cadena = "#{@num}/#{@denom}" #se usa para que la función to_s devuelva lo que acaba de imprimir por pantalla
|
|
61
|
-
end
|
|
62
|
-
def to_f
|
|
63
|
-
@num.to_f/@denom.to_f
|
|
64
|
-
end
|
|
65
|
-
#método que muestra la fracción en la forma a/b en flotante
|
|
66
|
-
def to_sf
|
|
67
|
-
"#{@num.to_f}/#{@denom.to_f}"
|
|
68
|
-
#puts "#{@num.to_f}/#{@denom.to_f}"
|
|
69
|
-
#cadena = "#{@num.to_f}/#{@denom.to_f}" #se usa para que la función to_s devuelva lo que acaba de imprimir por pantalla
|
|
70
|
-
end
|
|
71
|
-
#método que devuelve true si la fracción con la que se compara es igual a la actual
|
|
72
|
-
def ==(o)
|
|
73
|
-
return @num == o.num && @denom == o.denom if o.instance_of? Fraccion
|
|
74
|
-
false
|
|
75
|
-
end
|
|
76
|
-
#método que calcula el valor absoluto de la fracción
|
|
77
|
-
def abs
|
|
78
|
-
@denom = @denom.abs
|
|
79
|
-
@num = @num.abs
|
|
80
|
-
end
|
|
81
|
-
#método que calcula el recíproco de la fracción.
|
|
82
|
-
def reciprocal
|
|
83
|
-
tmpNumerador = @num
|
|
84
|
-
@num = @denom
|
|
85
|
-
@denom = tmpNumerador
|
|
86
|
-
end
|
|
87
|
-
#método que calcula el inverso de la fracción
|
|
88
|
-
def -@
|
|
89
|
-
@num = -@num
|
|
90
|
-
end
|
|
91
|
-
#método que devuelve la suma de la fracción actual con la que se pasa como parámetro
|
|
92
|
-
def +(other)
|
|
93
|
-
Fraccion.new((@num*other.denom)+(@denom*other.num), @denom*other.denom)
|
|
94
|
-
end
|
|
95
|
-
#método que devuelve la resta de la fracción actual con la que se pasa como parámetro
|
|
96
|
-
def -(other)
|
|
97
|
-
Fraccion.new((@num*other.denom)-(@denom*other.num), @denom*other.denom)
|
|
98
|
-
end
|
|
99
|
-
#método que devuelve la multiplicación de la fracción actual con la que se pasa como parámetro
|
|
100
|
-
def *(other)
|
|
101
|
-
Fraccion.new(@num*other.num, @denom*other.denom)
|
|
102
|
-
end
|
|
103
|
-
#método que devuelve la división de la fracción actual con la que se pasa como parámetro
|
|
104
|
-
def /(other)
|
|
105
|
-
other.reciprocal
|
|
106
|
-
Fraccion.new(@num*other.num, @denom*other.denom)
|
|
107
|
-
end
|
|
108
|
-
#método que devuelve el módulo de la fracción actual con la que se pasa como parámetro
|
|
109
|
-
def %(other)
|
|
110
|
-
other.reciprocal
|
|
111
|
-
a = Fraccion.new(@num*other.num, @denom*other.denom)
|
|
112
|
-
a.num % a.denom
|
|
113
|
-
end
|
|
114
|
-
def divReciprocal(other)
|
|
115
|
-
other.reciprocal
|
|
116
|
-
a = Fraccion.new(@num*other.num, @denom*other.denom)
|
|
117
|
-
a.reciprocal
|
|
118
|
-
a
|
|
119
|
-
end
|
|
120
|
-
def <=>(other)
|
|
121
|
-
(@num.to_f/@denom.to_f) <=> (other.num.to_f/other.denom.to_f)
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
class SparseVector
|
|
126
|
-
attr_reader :vector
|
|
127
|
-
|
|
128
|
-
def initialize(h = {})
|
|
129
|
-
@vector = Hash.new(0)
|
|
130
|
-
@vector = @vector.merge!(h)
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
def [](i)
|
|
134
|
-
@vector[i]
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
def []=(i,v)
|
|
138
|
-
@vector[i] = v
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
def to_s
|
|
142
|
-
@vector.to_s
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
def keys
|
|
146
|
-
@vector.keys
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
def +(other)
|
|
150
|
-
resultado = SparseVector.new
|
|
151
|
-
for i in other.vector.keys do
|
|
152
|
-
resultado[i] = other[i]
|
|
32
|
+
#Clase que permite representar un número fraccionario y hacer las operaciones básicas.
|
|
33
|
+
class Fraccion
|
|
34
|
+
include Comparable
|
|
35
|
+
|
|
36
|
+
attr_accessor :num
|
|
37
|
+
attr_accessor :denom
|
|
38
|
+
#método para permitir las operaciones desde otros tipos de datos con Fraccion
|
|
39
|
+
def coerce(other)
|
|
40
|
+
[self, other]
|
|
41
|
+
end
|
|
42
|
+
#método que llama al constructor del objeto de la clase
|
|
43
|
+
def initialize(n, d)
|
|
44
|
+
@num = n
|
|
45
|
+
@denom = d
|
|
46
|
+
gcd
|
|
153
47
|
end
|
|
154
|
-
|
|
155
|
-
|
|
48
|
+
#método que reduce la fracción calculando el mcd y dividiendolo entre el numerador y el denominador
|
|
49
|
+
def gcd
|
|
50
|
+
mcd, v = @num.abs, @denom.abs
|
|
51
|
+
while v > 0
|
|
52
|
+
mcd, v = v, mcd % v
|
|
53
|
+
end
|
|
54
|
+
@num = @num/mcd
|
|
55
|
+
@denom = @denom/mcd
|
|
156
56
|
end
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
def -(other)
|
|
161
|
-
resultado = SparseVector.new
|
|
162
|
-
for i in other.vector.keys do
|
|
163
|
-
resultado[i] = other[i]
|
|
57
|
+
#método que muestra la fracción en la forma a/b
|
|
58
|
+
def to_s
|
|
59
|
+
"#{@num}/#{@denom}"
|
|
164
60
|
end
|
|
165
|
-
|
|
166
|
-
|
|
61
|
+
def to_f
|
|
62
|
+
@num.to_f/@denom.to_f
|
|
167
63
|
end
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
def initialize(h = {})
|
|
177
|
-
@matrix = Hash.new({})
|
|
178
|
-
for k in h.keys do
|
|
179
|
-
@matrix[k] = if h[k].is_a? SparseVector
|
|
180
|
-
h[k]
|
|
181
|
-
else
|
|
182
|
-
@matrix[k] = SparseVector.new(h[k])
|
|
183
|
-
end
|
|
64
|
+
#método que muestra la fracción en la forma a/b en flotante
|
|
65
|
+
def to_sf
|
|
66
|
+
"#{@num.to_f}/#{@denom.to_f}"
|
|
67
|
+
end
|
|
68
|
+
#método que devuelve true si la fracción con la que se compara es igual a la actual
|
|
69
|
+
def ==(o)
|
|
70
|
+
return @num == o.num && @denom == o.denom if o.instance_of? Fraccion
|
|
71
|
+
false
|
|
184
72
|
end
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
@
|
|
195
|
-
|
|
73
|
+
#método que calcula el valor absoluto de la fracción
|
|
74
|
+
def abs
|
|
75
|
+
@denom = @denom.abs
|
|
76
|
+
@num = @num.abs
|
|
77
|
+
end
|
|
78
|
+
#método que calcula el recíproco de la fracción.
|
|
79
|
+
def reciprocal
|
|
80
|
+
tmpNumerador = @num
|
|
81
|
+
@num = @denom
|
|
82
|
+
@denom = tmpNumerador
|
|
83
|
+
end
|
|
84
|
+
#método que calcula el inverso de la fracción
|
|
85
|
+
def -@
|
|
86
|
+
@num = -@num
|
|
87
|
+
end
|
|
88
|
+
#método que devuelve la suma de la fracción actual con la que se pasa como parámetro
|
|
89
|
+
def +(other)
|
|
90
|
+
Fraccion.new((@num*other.denom)+(@denom*other.num), @denom*other.denom)
|
|
91
|
+
end
|
|
92
|
+
#método que devuelve la resta de la fracción actual con la que se pasa como parámetro
|
|
93
|
+
def -(other)
|
|
94
|
+
Fraccion.new((@num*other.denom)-(@denom*other.num), @denom*other.denom)
|
|
95
|
+
end
|
|
96
|
+
#método que devuelve la multiplicación de la fracción actual con la que se pasa como parámetro
|
|
97
|
+
def *(other)
|
|
98
|
+
Fraccion.new(@num*other.num, @denom*other.denom)
|
|
99
|
+
end
|
|
100
|
+
#método que devuelve la división de la fracción actual con la que se pasa como parámetro
|
|
101
|
+
def /(other)
|
|
102
|
+
other.reciprocal
|
|
103
|
+
Fraccion.new(@num*other.num, @denom*other.denom)
|
|
104
|
+
end
|
|
105
|
+
#método que devuelve el módulo de la fracción actual con la que se pasa como parámetro
|
|
106
|
+
def %(other)
|
|
107
|
+
other.reciprocal
|
|
108
|
+
a = Fraccion.new(@num*other.num, @denom*other.denom)
|
|
109
|
+
a.num % a.denom
|
|
110
|
+
end
|
|
111
|
+
#método que calcula el recíproco de una fracción
|
|
112
|
+
def divReciprocal(other)
|
|
113
|
+
other.reciprocal
|
|
114
|
+
a = Fraccion.new(@num*other.num, @denom*other.denom)
|
|
115
|
+
a.reciprocal
|
|
116
|
+
a
|
|
117
|
+
end
|
|
118
|
+
#método de la guerra de las galaxias que permite los tipos de comparación ==, <, >, <=, >=
|
|
119
|
+
def <=>(other)
|
|
120
|
+
(@num.to_f/@denom.to_f) <=> (other.num.to_f/other.denom.to_f)
|
|
196
121
|
end
|
|
197
122
|
end
|
|
123
|
+
#Clase que permite representar un vector disperso
|
|
124
|
+
class SparseVector
|
|
125
|
+
attr_reader :vector
|
|
198
126
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
127
|
+
def initialize(h = {})
|
|
128
|
+
@vector = Hash.new(0)
|
|
129
|
+
@vector = @vector.merge!(h)
|
|
202
130
|
end
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
c = {}
|
|
207
|
-
for r in @matrix.keys do
|
|
208
|
-
c[r] = @matrix[r].vector[j] if @matrix[r].vector.keys.include? j
|
|
131
|
+
#método que permite la indexación de elementos del vector disperso
|
|
132
|
+
def [](i)
|
|
133
|
+
@vector[i]
|
|
209
134
|
end
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
end
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
135
|
+
#método que permite la asignación de elementos del vector disperso
|
|
136
|
+
def []=(i,v)
|
|
137
|
+
@vector[i] = v
|
|
138
|
+
end
|
|
139
|
+
#método que permite pasar el vector a string
|
|
140
|
+
def to_s
|
|
141
|
+
@vector.to_s
|
|
142
|
+
end
|
|
143
|
+
#devuelve las claves del Hash @vector
|
|
144
|
+
def keys
|
|
145
|
+
@vector.keys
|
|
146
|
+
end
|
|
147
|
+
#método que implementa la suma de vectores dispersos
|
|
148
|
+
def +(other)
|
|
149
|
+
resultado = SparseVector.new
|
|
150
|
+
for i in other.vector.keys do
|
|
151
|
+
resultado[i] = other[i]
|
|
152
|
+
end
|
|
153
|
+
for i in @vector.keys do
|
|
154
|
+
resultado[i] = @vector[i] + other[i]
|
|
225
155
|
end
|
|
156
|
+
resultado
|
|
226
157
|
end
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
for i in other.matrix.keys do
|
|
233
|
-
resultado.matrix[i] = other[i]
|
|
234
|
-
end
|
|
235
|
-
for i in @matrix.keys do
|
|
236
|
-
for j in @matrix[i].keys do
|
|
237
|
-
if other.matrix[i][j] == nil
|
|
238
|
-
resultado.matrix[i] = @matrix[i]
|
|
239
|
-
else
|
|
240
|
-
resultado.matrix[i][j] = @matrix[i][j]-other.matrix[i][j]
|
|
241
|
-
end
|
|
158
|
+
#método que implementa la resta de vectores dispersos
|
|
159
|
+
def -(other)
|
|
160
|
+
resultado = SparseVector.new
|
|
161
|
+
for i in other.vector.keys do
|
|
162
|
+
resultado[i] = other[i]
|
|
242
163
|
end
|
|
164
|
+
for i in @vector.keys do
|
|
165
|
+
resultado[i] = @vector[i] - other[i]
|
|
166
|
+
end
|
|
167
|
+
resultado
|
|
243
168
|
end
|
|
244
|
-
resultado
|
|
245
169
|
end
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
if j == y
|
|
258
|
-
#puts "#{j} == #{y}, por tanto tmp[#{i}] = #{@matrix[x][y]}"
|
|
259
|
-
tmp[i] = @matrix[x][y]
|
|
260
|
-
#puts "TMP[#{i}] = #{tmp[i]}"
|
|
261
|
-
end
|
|
262
|
-
end
|
|
263
|
-
end
|
|
264
|
-
resultado.matrix[j] = tmp
|
|
265
|
-
#puts "resultado.matrix[#{j}] = #{tmp}, Y QUEDA: #{resultado.matrix[j]}"
|
|
170
|
+
#Clase que permite representar un vector de vectores dispersos, es decir, una matriz dispersa
|
|
171
|
+
class SparseMatrix < Matriz
|
|
172
|
+
attr_reader :matrix
|
|
173
|
+
def initialize(h = {})
|
|
174
|
+
@matrix = Hash.new({})
|
|
175
|
+
for k in h.keys do
|
|
176
|
+
@matrix[k] = if h[k].is_a? SparseVector
|
|
177
|
+
h[k]
|
|
178
|
+
else
|
|
179
|
+
@matrix[k] = SparseVector.new(h[k])
|
|
180
|
+
end
|
|
266
181
|
end
|
|
267
182
|
end
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
end
|
|
183
|
+
#método que permite la indexación de elementos de la matriz por columnas
|
|
184
|
+
def [](i)
|
|
185
|
+
@matrix[i]
|
|
186
|
+
end
|
|
187
|
+
#método que permite la asignación de elementos de la matriz por columnas
|
|
188
|
+
def []=(i,other)
|
|
189
|
+
for y in other.keys do
|
|
190
|
+
puts "---- other[#{y}] #{other[y]}"
|
|
191
|
+
@matrix[i][y] = other[y]
|
|
192
|
+
puts "---- matrix[#{i}][#{y}] #{@matrix[i][y]}"
|
|
279
193
|
end
|
|
280
194
|
end
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
for i in @matrix.keys do
|
|
286
|
-
for j in @matrix[i].keys do
|
|
287
|
-
if @matrix[i][j].is_a? Fraccion
|
|
288
|
-
tmp = Fraccion.new(max,1)
|
|
289
|
-
if @matrix[i][j] > tmp
|
|
290
|
-
max = @matrix[i][j].to_f
|
|
291
|
-
end
|
|
292
|
-
else
|
|
293
|
-
if @matrix[i][j] > max
|
|
294
|
-
max = @matrix[i][j]
|
|
295
|
-
end
|
|
195
|
+
#método que muestra por pantalla la matriz dispersa
|
|
196
|
+
def imp
|
|
197
|
+
for i in @matrix.keys do
|
|
198
|
+
puts "#{i} ---- #{@matrix[i].to_s}"
|
|
296
199
|
end
|
|
297
200
|
end
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
min = 999999999
|
|
304
|
-
for i in @matrix.keys do
|
|
305
|
-
for j in @matrix[i].keys do
|
|
306
|
-
if @matrix[i][j].is_a? Fraccion
|
|
307
|
-
tmp = Fraccion.new(min,1)
|
|
308
|
-
if @matrix[i][j] < tmp
|
|
309
|
-
min = @matrix[i][j].to_f
|
|
310
|
-
end
|
|
311
|
-
else
|
|
312
|
-
if @matrix[i][j] < min
|
|
313
|
-
min = @matrix[i][j]
|
|
314
|
-
end
|
|
201
|
+
#método que muestra por pantalla una columna de la matriz
|
|
202
|
+
def col(j)
|
|
203
|
+
c = {}
|
|
204
|
+
for r in @matrix.keys do
|
|
205
|
+
c[r] = @matrix[r].vector[j] if @matrix[r].vector.keys.include? j
|
|
315
206
|
end
|
|
207
|
+
SparseVector.new c
|
|
316
208
|
end
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
209
|
+
#método que permite la suma de matrices dispersas
|
|
210
|
+
def +(other)
|
|
211
|
+
resultado = SparseMatrix.new
|
|
212
|
+
for i in other.matrix.keys do
|
|
213
|
+
resultado.matrix[i] = other[i]
|
|
214
|
+
end
|
|
215
|
+
for i in @matrix.keys do
|
|
216
|
+
for j in @matrix[i].keys do
|
|
217
|
+
if other.matrix[i][j] == nil
|
|
218
|
+
resultado.matrix[i] = @matrix[i]
|
|
219
|
+
else
|
|
220
|
+
resultado.matrix[i][j] = @matrix[i][j]+other.matrix[i][j]
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
resultado
|
|
225
|
+
end
|
|
226
|
+
#método que permite la resta de matrices dispersas
|
|
227
|
+
def -(other)
|
|
228
|
+
resultado = SparseMatrix.new
|
|
229
|
+
for i in other.matrix.keys do
|
|
230
|
+
resultado.matrix[i] = other[i]
|
|
231
|
+
end
|
|
232
|
+
for i in @matrix.keys do
|
|
233
|
+
for j in @matrix[i].keys do
|
|
234
|
+
if other.matrix[i][j] == nil
|
|
235
|
+
resultado.matrix[i] = @matrix[i]
|
|
236
|
+
else
|
|
237
|
+
resultado.matrix[i][j] = @matrix[i][j]-other.matrix[i][j]
|
|
238
|
+
end
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
resultado
|
|
242
|
+
end
|
|
243
|
+
#método que permite calcular la traspuesta de una matriz dispersa
|
|
244
|
+
def traspuesta
|
|
245
|
+
resultado = SparseMatrix.new
|
|
246
|
+
for i in @matrix.keys do
|
|
247
|
+
for j in @matrix[i].keys do
|
|
248
|
+
tmp = SparseVector.new
|
|
249
|
+
for x in @matrix.keys do
|
|
250
|
+
for y in @matrix[x].keys do
|
|
251
|
+
if j == y
|
|
252
|
+
tmp[i] = @matrix[x][y]
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
end
|
|
256
|
+
resultado.matrix[j] = tmp
|
|
257
|
+
end
|
|
258
|
+
end
|
|
259
|
+
resultado
|
|
260
|
+
end
|
|
261
|
+
#método que permite calcular el elemento máximo de una matriz dispersa
|
|
262
|
+
def max
|
|
263
|
+
max = 0
|
|
264
|
+
for i in @matrix.keys do
|
|
265
|
+
for j in @matrix[i].keys do
|
|
266
|
+
if @matrix[i][j].is_a? Fraccion
|
|
267
|
+
tmp = Fraccion.new(max,1)
|
|
268
|
+
if @matrix[i][j] > tmp
|
|
269
|
+
max = @matrix[i][j].to_f
|
|
270
|
+
end
|
|
271
|
+
else
|
|
272
|
+
if @matrix[i][j] > max
|
|
273
|
+
max = @matrix[i][j]
|
|
274
|
+
end
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
end
|
|
278
|
+
max
|
|
279
|
+
end
|
|
280
|
+
#método que permite calcular el elemento mínimo de una matriz dispersa
|
|
281
|
+
def min
|
|
282
|
+
min = 9999999999999999999
|
|
283
|
+
for i in @matrix.keys do
|
|
284
|
+
for j in @matrix[i].keys do
|
|
285
|
+
if @matrix[i][j].is_a? Fraccion
|
|
286
|
+
tmp = Fraccion.new(min,1)
|
|
287
|
+
if @matrix[i][j] < tmp
|
|
288
|
+
min = @matrix[i][j].to_f
|
|
289
|
+
end
|
|
290
|
+
else
|
|
291
|
+
if @matrix[i][j] < min
|
|
292
|
+
min = @matrix[i][j]
|
|
293
|
+
end
|
|
294
|
+
end
|
|
295
|
+
end
|
|
296
|
+
end
|
|
297
|
+
min
|
|
336
298
|
end
|
|
337
299
|
end
|
|
300
|
+
#Clase que permite representar matrices densas
|
|
301
|
+
class DenseMatrix < Matriz
|
|
302
|
+
attr_accessor :m
|
|
303
|
+
attr_accessor :f
|
|
304
|
+
attr_accessor :c
|
|
338
305
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
306
|
+
def initialize(filas, columnas, v)
|
|
307
|
+
@f = filas
|
|
308
|
+
@c = columnas
|
|
309
|
+
@m = []
|
|
310
|
+
i = 0
|
|
311
|
+
while i < @f*@c
|
|
312
|
+
@m[i] = v[i]
|
|
313
|
+
i=i+1
|
|
314
|
+
end
|
|
315
|
+
end
|
|
316
|
+
#Método que permite la indexación de elementos de la matriz
|
|
317
|
+
def [](a,b)
|
|
318
|
+
@m[a+(b*@c)]
|
|
319
|
+
end
|
|
320
|
+
#Método que permite la asignación de elementos de la matriz
|
|
321
|
+
def []=(a,b,r)
|
|
322
|
+
@m[a+(b*@c)] = r
|
|
323
|
+
end
|
|
324
|
+
#método que transforma la matriz en un vector de vectores. Devuelve un vector.
|
|
325
|
+
def to_v
|
|
326
|
+
v = []
|
|
351
327
|
for i in (0...@c) do
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
resultado[i,j] = s
|
|
358
|
-
end
|
|
328
|
+
tmp = []
|
|
329
|
+
for j in (0...@f) do
|
|
330
|
+
tmp[j] = @m[i+(j*@c)]
|
|
331
|
+
end
|
|
332
|
+
v[i] = tmp
|
|
359
333
|
end
|
|
360
|
-
|
|
361
|
-
puts "Las matriz A debe tener el mismo numero de filas que las columnas de B"
|
|
334
|
+
v
|
|
362
335
|
end
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
end
|
|
425
|
-
if ((i+1)+(j+1))%2 == 0
|
|
426
|
-
tmp = other[0]
|
|
427
|
-
resultado = resultado + tmp[i+(j*Math.sqrt(other[0].size).to_i)]*det(adj)
|
|
428
|
-
else
|
|
429
|
-
tmp = other[0]
|
|
430
|
-
resultado = resultado - tmp[i+(j*Math.sqrt(other[0].size).to_i)]*det(adj)
|
|
431
|
-
end
|
|
432
|
-
end
|
|
433
|
-
end
|
|
434
|
-
end
|
|
435
|
-
end
|
|
436
|
-
return resultado
|
|
437
|
-
end
|
|
438
|
-
|
|
439
|
-
def adj()
|
|
440
|
-
a = Array.new(@f*@c, 0)
|
|
441
|
-
resultado = DenseMatrix.new(@f, @c, a)
|
|
442
|
-
for i in (0...@c) do
|
|
443
|
-
for j in (0...@f) do
|
|
444
|
-
adj = []
|
|
445
|
-
z = 0
|
|
446
|
-
for x in (0...@c) do
|
|
447
|
-
for y in (0...@f) do
|
|
448
|
-
if (x != i) && (y != j)
|
|
449
|
-
adj[z] = @m[x+(y*@c)]
|
|
450
|
-
z=z+1
|
|
451
|
-
end
|
|
452
|
-
end
|
|
453
|
-
end
|
|
454
|
-
if ((i+1)+(j+1))%2 == 0
|
|
455
|
-
resultado[i,j] = det(adj)
|
|
456
|
-
else
|
|
457
|
-
resultado[i,j] = -det(adj)
|
|
458
|
-
end
|
|
459
|
-
end
|
|
460
|
-
end
|
|
461
|
-
return resultado
|
|
462
|
-
end
|
|
463
|
-
|
|
464
|
-
def tras()
|
|
465
|
-
a = Array.new(@f*@c, 0)
|
|
466
|
-
resultado = DenseMatrix.new(@f, @c, a)
|
|
467
|
-
for i in (0...@c) do
|
|
468
|
-
for j in (0...@f) do
|
|
469
|
-
resultado[i,j] = @m[j+(i*@c)]
|
|
470
|
-
end
|
|
471
|
-
end
|
|
472
|
-
return resultado
|
|
473
|
-
end
|
|
474
|
-
|
|
475
|
-
def inv
|
|
476
|
-
determinante = self.det
|
|
477
|
-
if determinante != 0
|
|
478
|
-
a = Array.new(@f*@c, 0)
|
|
479
|
-
resultado = DenseMatrix.new(@f, @c, a)
|
|
480
|
-
resultado = self.adj
|
|
481
|
-
resultado = resultado.tras
|
|
482
|
-
for i in (0...resultado.c) do
|
|
483
|
-
for j in (0...resultado.f) do
|
|
484
|
-
resultado[i,j] = (1/determinante.to_f)*resultado[i,j]
|
|
485
|
-
end
|
|
486
|
-
end
|
|
487
|
-
return resultado
|
|
488
|
-
end
|
|
489
|
-
end
|
|
490
|
-
|
|
491
|
-
def imprimir
|
|
492
|
-
for i in (0...@c*@f) do
|
|
493
|
-
print "#{@m[i].round(2)}\t"
|
|
494
|
-
if i % @c == 2
|
|
495
|
-
print "\n"
|
|
496
|
-
end
|
|
497
|
-
end
|
|
498
|
-
end
|
|
499
|
-
|
|
500
|
-
def /(other1)
|
|
501
|
-
a = Array.new(@f*@c, 0)
|
|
502
|
-
resultado = DenseMatrix.new(@f, @c, a)
|
|
503
|
-
other = other1.inv
|
|
504
|
-
if @f*@c == other.c*other.f
|
|
505
|
-
for i in (0...@c) do
|
|
506
|
-
for j in (0...@f) do
|
|
507
|
-
s = 0
|
|
508
|
-
for k in (0...@c) do
|
|
509
|
-
s = s + (@m[i+(k*@c)] / other.m[k+(j*other.c)])
|
|
510
|
-
end
|
|
511
|
-
resultado[i,j] = s
|
|
512
|
-
end
|
|
513
|
-
end
|
|
514
|
-
else
|
|
515
|
-
puts "Las matriz A debe tener el mismo numero de filas que las columnas de B"
|
|
516
|
-
end
|
|
517
|
-
resultado
|
|
336
|
+
#Método que permite la multiplicación de matrices densas mediante programación funcional
|
|
337
|
+
def *(other)
|
|
338
|
+
tmp = self.tras; a = tmp.to_v; d = other.to_v;
|
|
339
|
+
i = -1; j = -1; k= -1; l= -1;
|
|
340
|
+
ex = Array.new()
|
|
341
|
+
a.map { |b| i+=1; k=-1; d.map { |e| k+=1; l=-1; e.map { |f| l+=1; a[i][l]*d[k][l] }.inject (0) { |s,p| s+p } } }.map{ |r| r.each { |t| ex.push(t) } }
|
|
342
|
+
return DenseMatrix.new(@c,@f, ex)
|
|
343
|
+
end
|
|
344
|
+
#Método que permite la suma de matrices densas
|
|
345
|
+
def +(other)
|
|
346
|
+
i=-1
|
|
347
|
+
return DenseMatrix.new(@c,@f,other.m.map { |e| i+=1; e+@m[i]})
|
|
348
|
+
end
|
|
349
|
+
#Método que permite la resta de matrices densas
|
|
350
|
+
def -(other)
|
|
351
|
+
i = 0
|
|
352
|
+
tmp = []
|
|
353
|
+
while i < @f*@c
|
|
354
|
+
tmp[i] = @m[i]-other.m[i]
|
|
355
|
+
i=i+1
|
|
356
|
+
end
|
|
357
|
+
tmp
|
|
358
|
+
end
|
|
359
|
+
#Método que permite calcular el determinante de una matriz densa. (Recursivo)
|
|
360
|
+
def det(*other)
|
|
361
|
+
resultado = 0
|
|
362
|
+
if other.size == 0
|
|
363
|
+
for i in (0...@c) do
|
|
364
|
+
j = 0;
|
|
365
|
+
adj = []
|
|
366
|
+
z = 0
|
|
367
|
+
for x in (0...@c) do
|
|
368
|
+
for y in (0...@f) do
|
|
369
|
+
if (x != i) && (y != j)
|
|
370
|
+
adj[z] = @m[x+(y*@c)]
|
|
371
|
+
z=z+1
|
|
372
|
+
end
|
|
373
|
+
end
|
|
374
|
+
end
|
|
375
|
+
if ((i+1)+(j+1))%2 == 0
|
|
376
|
+
resultado = resultado + @m[i+(j*@c)]*det(adj)
|
|
377
|
+
else
|
|
378
|
+
resultado = resultado - @m[i+(j*@c)]*det(adj)
|
|
379
|
+
end
|
|
380
|
+
end
|
|
381
|
+
else
|
|
382
|
+
if other[0].size == 1
|
|
383
|
+
tmp = other[0]
|
|
384
|
+
return tmp[0]
|
|
385
|
+
else
|
|
386
|
+
if other[0].size >= 4
|
|
387
|
+
for i in (0...Math.sqrt(other[0].size).to_i) do
|
|
388
|
+
j=0
|
|
389
|
+
adj = []
|
|
390
|
+
z = 0
|
|
391
|
+
for x in (0...Math.sqrt(other[0].size).to_i) do
|
|
392
|
+
for y in (0...Math.sqrt(other[0].size).to_i) do
|
|
393
|
+
if (x != i) && (y != j)
|
|
394
|
+
adj[z] = other[0][x+(y*Math.sqrt(other[0].size).to_i)]
|
|
395
|
+
z=z+1
|
|
396
|
+
end
|
|
518
397
|
end
|
|
519
|
-
end
|
|
398
|
+
end
|
|
399
|
+
if ((i+1)+(j+1))%2 == 0
|
|
400
|
+
tmp = other[0]
|
|
401
|
+
resultado = resultado + tmp[i+(j*Math.sqrt(other[0].size).to_i)]*det(adj)
|
|
402
|
+
else
|
|
403
|
+
tmp = other[0]
|
|
404
|
+
resultado = resultado - tmp[i+(j*Math.sqrt(other[0].size).to_i)]*det(adj)
|
|
405
|
+
end
|
|
406
|
+
end
|
|
407
|
+
end
|
|
408
|
+
end
|
|
409
|
+
end
|
|
410
|
+
return resultado
|
|
411
|
+
end
|
|
412
|
+
#Método que permite calcular la matriz adjunta de una matriz densa
|
|
413
|
+
def adj()
|
|
414
|
+
a = Array.new(@f*@c, 0)
|
|
415
|
+
resultado = DenseMatrix.new(@f, @c, a)
|
|
416
|
+
for i in (0...@c) do
|
|
417
|
+
for j in (0...@f) do
|
|
418
|
+
adj = []
|
|
419
|
+
z = 0
|
|
420
|
+
for x in (0...@c) do
|
|
421
|
+
for y in (0...@f) do
|
|
422
|
+
if (x != i) && (y != j)
|
|
423
|
+
adj[z] = @m[x+(y*@c)]
|
|
424
|
+
z=z+1
|
|
425
|
+
end
|
|
426
|
+
end
|
|
427
|
+
end
|
|
428
|
+
if ((i+1)+(j+1))%2 == 0
|
|
429
|
+
resultado[i,j] = det(adj)
|
|
430
|
+
else
|
|
431
|
+
resultado[i,j] = -det(adj)
|
|
432
|
+
end
|
|
433
|
+
end
|
|
434
|
+
end
|
|
435
|
+
return resultado
|
|
436
|
+
end
|
|
437
|
+
#Método que permite calcular la traspuesta de una matriz densa
|
|
438
|
+
def tras()
|
|
439
|
+
a = Array.new(@f*@c, 0)
|
|
440
|
+
resultado = DenseMatrix.new(@f, @c, a)
|
|
441
|
+
for i in (0...@c) do
|
|
442
|
+
for j in (0...@f) do
|
|
443
|
+
resultado[i,j] = @m[j+(i*@c)]
|
|
444
|
+
end
|
|
445
|
+
end
|
|
446
|
+
return resultado
|
|
447
|
+
end
|
|
448
|
+
#Método que permite calcular la inversa de una matriz densa
|
|
449
|
+
def inv
|
|
450
|
+
determinante = self.det
|
|
451
|
+
if determinante != 0
|
|
452
|
+
a = Array.new(@f*@c, 0)
|
|
453
|
+
resultado = DenseMatrix.new(@f, @c, a)
|
|
454
|
+
resultado = self.adj
|
|
455
|
+
resultado = resultado.tras
|
|
456
|
+
for i in (0...resultado.c) do
|
|
457
|
+
for j in (0...resultado.f) do
|
|
458
|
+
resultado[i,j] = (1/determinante.to_f)*resultado[i,j]
|
|
459
|
+
end
|
|
460
|
+
end
|
|
461
|
+
return resultado
|
|
462
|
+
end
|
|
463
|
+
end
|
|
464
|
+
#método que permite mostrar por pantalla una matriz densa
|
|
465
|
+
def imprimir
|
|
466
|
+
for i in (0...@c*@f) do
|
|
467
|
+
print "#{@m[i].round(2)}\t"
|
|
468
|
+
if i % @c == 2
|
|
469
|
+
print "\n"
|
|
470
|
+
end
|
|
471
|
+
end
|
|
472
|
+
end
|
|
473
|
+
#Método que permite hacer la división de matrices densas
|
|
474
|
+
def /(other1)
|
|
475
|
+
a = Array.new(@f*@c, 0)
|
|
476
|
+
resultado = DenseMatrix.new(@f, @c, a)
|
|
477
|
+
other = other1.inv
|
|
478
|
+
if @f*@c == other.c*other.f
|
|
479
|
+
for i in (0...@c) do
|
|
480
|
+
for j in (0...@f) do
|
|
481
|
+
s = 0
|
|
482
|
+
for k in (0...@c) do
|
|
483
|
+
s = s + (@m[i+(k*@c)] / other.m[k+(j*other.c)])
|
|
484
|
+
end
|
|
485
|
+
resultado[i,j] = s
|
|
486
|
+
end
|
|
487
|
+
end
|
|
488
|
+
else
|
|
489
|
+
puts "Las matriz A debe tener el mismo numero de filas que las columnas de B"
|
|
490
|
+
end
|
|
491
|
+
resultado
|
|
492
|
+
end
|
|
493
|
+
end
|
|
520
494
|
|
|
521
|
-
if __FILE__ == $0
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
#
|
|
531
|
-
#
|
|
532
|
-
#
|
|
533
|
-
#
|
|
534
|
-
#
|
|
535
|
-
#
|
|
536
|
-
#
|
|
537
|
-
|
|
538
|
-
# r = z - y
|
|
539
|
-
# puts "-------------------------"
|
|
540
|
-
# r.imp
|
|
541
|
-
# puts "-------------------------"
|
|
542
|
-
# b = SparseVector.new ({ 1 => 10, 2 => 22, 3 => 33 })
|
|
543
|
-
# c = SparseVector.new ({ 1 => 10, 2 => 20, 3 => 30 })
|
|
544
|
-
# x = b + c
|
|
545
|
-
#
|
|
546
|
-
# puts x
|
|
547
|
-
#
|
|
548
|
-
# mi = z.min
|
|
549
|
-
# puts mi
|
|
550
|
-
|
|
551
|
-
a = Matriz.new(3,3,[1,2,3,4,5,6,7,8,9])
|
|
552
|
-
b = a.def_tipo
|
|
553
|
-
puts b.class
|
|
554
|
-
puts "-------------------"
|
|
555
|
-
b.imprimir
|
|
556
|
-
|
|
557
|
-
c = Matriz.new(3,3,[1,0,0,0,0,6,0,0,9])
|
|
558
|
-
d = c.def_tipo
|
|
559
|
-
puts d.class
|
|
560
|
-
puts "-------------------"
|
|
561
|
-
d.imp
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
end
|
|
495
|
+
if __FILE__ == $0
|
|
496
|
+
a = DenseMatrix.new(3,3,[1,2,3,4,5,6,7,8,9])
|
|
497
|
+
b = DenseMatrix.new(3,3,[2,4,6,8,10,12,14,16,18])
|
|
498
|
+
a.imprimir
|
|
499
|
+
b.imprimir
|
|
500
|
+
puts "-----------------------"
|
|
501
|
+
c = a * b
|
|
502
|
+
puts c.inspect
|
|
503
|
+
c.imprimir
|
|
504
|
+
# x = a.to_v
|
|
505
|
+
# y = b.to_v
|
|
506
|
+
# for i in (0...x.size) do
|
|
507
|
+
# for j in (0...x[i].size) do
|
|
508
|
+
# puts x[i][j]
|
|
509
|
+
# end
|
|
510
|
+
# end
|
|
511
|
+
end
|
|
565
512
|
|
|
566
513
|
end
|
|
567
514
|
|
data/matrix_disp.gemspec
CHANGED
|
@@ -6,8 +6,8 @@ require 'matrix_disp/version'
|
|
|
6
6
|
Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = "matrix_disp"
|
|
8
8
|
spec.version = MatrixDisp::VERSION
|
|
9
|
-
spec.authors = ["Jonás", "Sergio"]
|
|
10
|
-
spec.email = ["alu0100608359@ull.edu.es"]
|
|
9
|
+
spec.authors = ["Jonás López Mesa", "Sergio"]
|
|
10
|
+
spec.email = ["alu0100608359@ull.edu.es", "alu0100706468@ull.edu.es"]
|
|
11
11
|
spec.description = %q{Gema para realizar operaciones básicas con matrices (Tanto densas como dispersas)}
|
|
12
12
|
spec.summary = %q{Gema para realizar operaciones básicas con matrices (Tanto densas como dispersas)}
|
|
13
13
|
spec.homepage = ""
|
data/spec/matrix_disp_spec.rb
CHANGED
|
@@ -272,25 +272,25 @@ end
|
|
|
272
272
|
a = DenseMatrix.new(3, 3,[1,2,3,4,5,6,7,8,9])
|
|
273
273
|
b = a * @p
|
|
274
274
|
expect(b[1,1]).to be_a_kind_of(Fixnum)
|
|
275
|
-
|
|
275
|
+
expect(b[1,1]).to eq(81)
|
|
276
276
|
end
|
|
277
277
|
it "2.2 Division" do
|
|
278
278
|
a = DenseMatrix.new(3, 3,[1,2,3,4,5,6,7,8,9])
|
|
279
279
|
a[1,2] = 15
|
|
280
280
|
b = @p/a
|
|
281
|
-
|
|
281
|
+
expect(b[1,1]).to eq(52.5)
|
|
282
282
|
end
|
|
283
283
|
it "2.3 Suma" do
|
|
284
284
|
a = DenseMatrix.new(3, 3,[1,2,3,4,5,6,7,8,9])
|
|
285
285
|
b = []
|
|
286
286
|
b = a + @p
|
|
287
|
-
|
|
287
|
+
expect(b[1,1]).to eq(10)
|
|
288
288
|
end
|
|
289
289
|
it "2.4 Resta" do
|
|
290
290
|
a = DenseMatrix.new(3, 3,[1,2,3,4,5,6,7,8,9])
|
|
291
291
|
b = []
|
|
292
292
|
b = a - @p
|
|
293
|
-
|
|
293
|
+
expect(b[4]).to eq(0)
|
|
294
294
|
end
|
|
295
295
|
end
|
|
296
296
|
end
|
metadata
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: matrix_disp
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
-
- Jonás
|
|
7
|
+
- Jonás López Mesa
|
|
8
8
|
- Sergio
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2013-11-
|
|
12
|
+
date: 2013-11-26 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: bundler
|
|
@@ -43,6 +43,7 @@ description: Gema para realizar operaciones básicas con matrices (Tanto densas
|
|
|
43
43
|
dispersas)
|
|
44
44
|
email:
|
|
45
45
|
- alu0100608359@ull.edu.es
|
|
46
|
+
- alu0100706468@ull.edu.es
|
|
46
47
|
executables:
|
|
47
48
|
- Practica9
|
|
48
49
|
extensions: []
|
|
@@ -85,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
85
86
|
version: '0'
|
|
86
87
|
requirements: []
|
|
87
88
|
rubyforge_project:
|
|
88
|
-
rubygems_version: 2.
|
|
89
|
+
rubygems_version: 2.1.11
|
|
89
90
|
signing_key:
|
|
90
91
|
specification_version: 4
|
|
91
92
|
summary: Gema para realizar operaciones básicas con matrices (Tanto densas como dispersas)
|
|
@@ -93,4 +94,3 @@ test_files:
|
|
|
93
94
|
- spec/matrix_disp_spec.rb
|
|
94
95
|
- spec/matrix_disp_spec.rb~
|
|
95
96
|
- spec/spec_helper.rb
|
|
96
|
-
has_rdoc:
|