class CAS::AutoDiff::DualNumber

Attributes

x[R]
y[R]

Public Class Methods

new(x, y) click to toggle source
# File lib/Mr.CAS/auto-diff.rb, line 9
def initialize(x, y)
  @x, @y = x, y
end

Public Instance Methods

*(v) click to toggle source
# File lib/Mr.CAS/auto-diff.rb, line 21
def *(v)
  DualNumber.new @x * v.x, @y * v.x + @x * v.y
end
**(v) click to toggle source
# File lib/Mr.CAS/auto-diff.rb, line 33
def **(v)
  t = (v.y == 0 ? 0 : @x * log(@x) * v.y)
  DualNumber.new @x ** v.x, (@x ** (v.x - 1)) * (v.x * @y + t)
end
+(v) click to toggle source
# File lib/Mr.CAS/auto-diff.rb, line 13
def +(v)
  DualNumber.new @x + v.x, @y + v.y
end
-(v) click to toggle source
# File lib/Mr.CAS/auto-diff.rb, line 17
def -(v)
  DualNumber.new @x - v.x, @y - v.y
end
-@() click to toggle source
# File lib/Mr.CAS/auto-diff.rb, line 29
def -@
  DualNumber.new -@x, -@y
end
/(v) click to toggle source
# File lib/Mr.CAS/auto-diff.rb, line 25
def /(v)
  DualNumber.new @x / v.x, (@y * v.x - @x * v.y) / (v.x ** 2)
end
abs() click to toggle source
# File lib/Mr.CAS/auto-diff.rb, line 38
def abs
  return DualNumber.new(0, 0) if @x == 0
  DualNumber.new @x.abs, @y * (@x <=> 0)
end
diff() click to toggle source
# File lib/Mr.CAS/auto-diff.rb, line 46
def diff; @y; end
inspect() click to toggle source
# File lib/Mr.CAS/auto-diff.rb, line 44
def inspect; "<#{@x},#{@y}>"; end
real() click to toggle source
# File lib/Mr.CAS/auto-diff.rb, line 45
def real; @x; end
to_s() click to toggle source
# File lib/Mr.CAS/auto-diff.rb, line 43
def to_s;    self.inspect;  end