Class: Matriz
- Inherits:
-
Object
- Object
- Matriz
- Defined in:
- lib/matriz.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#c ⇒ Object
readonly
Returns the value of attribute c.
-
#f ⇒ Object
readonly
Returns the value of attribute f.
-
#m ⇒ Object
readonly
Returns the value of attribute m.
Instance Method Summary collapse
- #*(other) ⇒ Object
- #+(other) ⇒ Object
- #-(other) ⇒ Object
-
#initialize(f, c, m) ⇒ Matriz
constructor
A new instance of Matriz.
Constructor Details
#initialize(f, c, m) ⇒ Matriz
Returns a new instance of Matriz.
9 10 11 12 13 |
# File 'lib/matriz.rb', line 9 def initialize(m) @m=m @f=m.size @c=m[1].size end |
Instance Attribute Details
#c ⇒ Object (readonly)
Returns the value of attribute c.
7 8 9 |
# File 'lib/matriz.rb', line 7 def c @c end |
#f ⇒ Object (readonly)
Returns the value of attribute f.
7 8 9 |
# File 'lib/matriz.rb', line 7 def f @f end |
#m ⇒ Object (readonly)
Returns the value of attribute m.
7 8 9 |
# File 'lib/matriz.rb', line 7 def m @m end |
Instance Method Details
#*(other) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/matriz.rb', line 34 def *(other) z = Array.new for i in 0...@f do z[i] = Array.new for j in 0...@c do z[i][j] = 0 end end for i in 0...@f do for j in 0...@c do for k in 0...@f do z[i][j] += @m[i][k] * other.m[k][j] end end end return z end |
#+(other) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/matriz.rb', line 24 def +(other) suma = @m for i in 0...@f do for j in 0...@c do suma[i][j]=@m[i][j]+other.m[i][j] end end return suma end |
#-(other) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/matriz.rb', line 56 def -(other) resta = @m for i in 0...@f do for j in 0...@c do resta[i][j] = @m[i][j] - other.m[i][j] end end return resta end |