Class: Matriz
- Inherits:
-
Object
show all
- Defined in:
- lib/Matriz.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(m) ⇒ Matriz
Returns a new instance of Matriz.
6
7
8
9
10
|
# File 'lib/Matriz.rb', line 6
def initialize(m)
@filas = m.size
@cols = m[1].size
@matriz = m
end
|
Instance Attribute Details
#cols ⇒ Object
Returns the value of attribute cols.
4
5
6
|
# File 'lib/Matriz.rb', line 4
def cols
@cols
end
|
#filas ⇒ Object
Returns the value of attribute filas.
4
5
6
|
# File 'lib/Matriz.rb', line 4
def filas
@filas
end
|
#matriz ⇒ Object
Returns the value of attribute matriz.
4
5
6
|
# File 'lib/Matriz.rb', line 4
def matriz
@matriz
end
|
Instance Method Details
#*(other) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/Matriz.rb', line 50
def * (other)
aux_m = Array.new
for i in 0...@filas do
aux_m[i] = Array.new
for j in 0...@cols do
aux_m[i][j] = 0;
end
end
for i in 0...@filas do
for j in 0...other.cols do
for k in 0...other.filas do
aux_m[i][j] += @matriz[i][k] * other.matriz[k][j]
end
end
end
Matriz.new(aux_m).matriz
end
|
#+(other) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/Matriz.rb', line 18
def + (other)
aux_m = Array.new
for i in 0...@filas do
aux_m[i] = Array.new
for j in 0...@cols do
aux_m[i][j] = 0;
end
end
for i in 0...@filas do
for j in 0...@cols do
aux_m[i][j] = @matriz[i][j] + other.matriz[i][j]
end
end
Matriz.new(aux_m).matriz
end
|
#-(other) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/Matriz.rb', line 34
def - (other)
aux_m = Array.new
for i in 0...@filas do
aux_m[i] = Array.new
for j in 0...@cols do
aux_m[i][j] = 0;
end
end
for i in 0...@filas do
for j in 0...@cols do
aux_m[i][j] = @matriz[i][j] - other.matriz[i][j]
end
end
Matriz.new(aux_m).matriz
end
|
#comprobar ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/Matriz.rb', line 79
def comprobar()
cont_total = 0
cont_ceros = 0
for i in 0...@filas do
for j in 0...@cols do
if @matriz[i][j] == 0
cont_ceros = cont_ceros + 1
end
cont_total = cont_total + 1
end
end
if cont_ceros >= (cont_total * 0.6)
Matriz_dispersa.new(@matriz)
else
Matriz_densa.new(@matriz)
end
end
|
#max ⇒ Object
97
98
|
# File 'lib/Matriz.rb', line 97
def max()
end
|
#min ⇒ Object
100
101
|
# File 'lib/Matriz.rb', line 100
def min()
end
|
#to_s ⇒ Object
12
13
14
15
16
|
# File 'lib/Matriz.rb', line 12
def to_s ()
@matriz.each do |fila|
puts fila.join(" ")
end
end
|
#traspuesta ⇒ Object
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/Matriz.rb', line 68
def traspuesta ()
aux_m = Array.new
for i in 0...@filas do
aux_m[i] = Array.new
for j in 0...@cols do
aux_m[i][j] = @matriz[(@filas-1)-i][(@cols-1)-j]
end
end
Matriz.new(aux_m).comprobar
end
|