Class: Ode::Solver

Inherits:
Object
  • Object
show all
Defined in:
lib/ode/solver.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(f, jac = nil) ⇒ Solver

Returns a new instance of Solver.



3
4
5
6
7
8
9
10
11
# File 'lib/ode/solver.rb', line 3

def initialize(f, jac=nil)
  @f = f
  @t = 0
  @y = 0
  @jac = jac
  @fargs = nil
  @opts = nil
  @method = :lsoda
end

Instance Attribute Details

#tObject (readonly)

Returns the value of attribute t.



40
41
42
# File 'lib/ode/solver.rb', line 40

def t
  @t
end

#yObject (readonly)

Returns the value of attribute y.



40
41
42
# File 'lib/ode/solver.rb', line 40

def y
  @y
end

Instance Method Details

#f_args(args) ⇒ Object



28
29
30
31
# File 'lib/ode/solver.rb', line 28

def f_args(args)
  @fargs=args
  self
end

#init(t0, y0) ⇒ Object



13
14
15
16
17
# File 'lib/ode/solver.rb', line 13

def init(t0, y0)
  @t = t0
  @y = y0
  self
end

#integrate(t_out) ⇒ Object



33
34
35
36
37
38
# File 'lib/ode/solver.rb', line 33

def integrate(t_out)
  @opts ||= Ode::Methods.default_opts(@method)
  @y = Ode::Methods.send(@method, t_out, @f, @jac, @t, @y, @fargs, @opts)
  @t = t_out
  self
end

#method(name) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/ode/solver.rb', line 19

def method(name)
    if Ode::Methods.respond_to?(name)
      @method = name
    else
      raise NameError, "Ode do not have an implementation of the method named" + name.to_s + "."
    end
  self
end