Class: Linear1::System

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/linear1/system.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(equation1, equation2) ⇒ System

Returns a new instance of System



8
9
10
# File 'lib/linear1/system.rb', line 8

def initialize equation1, equation2
  @e1, @e2 = equation1, equation2
end

Instance Attribute Details

#e1Object (readonly)

Returns the value of attribute e1



4
5
6
# File 'lib/linear1/system.rb', line 4

def e1
  @e1
end

#e2Object (readonly)

Returns the value of attribute e2



4
5
6
# File 'lib/linear1/system.rb', line 4

def e2
  @e2
end

Instance Method Details

#eachObject



5
6
7
# File 'lib/linear1/system.rb', line 5

def each
  return yield(@e1), yield(@e2)
end

#execute(x) ⇒ Object



11
12
13
14
15
# File 'lib/linear1/system.rb', line 11

def execute x
  final = Array.new
  @equations.each {|equation| final << equation.execute(x)}
  final
end

#intersectionObject Also known as: solution



16
17
18
19
20
# File 'lib/linear1/system.rb', line 16

def intersection
  e = [@e1.to_standard, @e2.to_standard]
  y, x = e[0].b * (e[1].c - e[1].a), e[1].a * (e[0].c - e[0].b)
  [x, y]
end