Class: Kamelopard::Functions::Quadratic

Inherits:
Cubic show all
Defined in:
lib/kamelopard/function.rb

Overview

Describes a quadratic equation

Instance Attribute Summary

Attributes inherited from Cubic

#c0, #c1, #c2, #c3

Attributes inherited from Function

#append, #compose, #end, #max, #min, #start, #verbose

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Cubic

#run_function

Methods inherited from Function1D

#compose=

Methods inherited from Function

#get_value, #run_function

Constructor Details

#initialize(c2 = 1.0, c1 = 0.0, c0 = 0.0, min = -1.0,, max = 1.0) ⇒ Quadratic

Returns a new instance of Quadratic.



133
134
135
# File 'lib/kamelopard/function.rb', line 133

def initialize(c2 = 1.0, c1 = 0.0, c0 = 0.0, min = -1.0, max = 1.0)
    super(0.0, c2, c1, c0, min, max)
end

Class Method Details

.interpolate(ymin, ymax, x1, y1, min = -1.0,, max = 1.0) ⇒ Object



137
138
139
140
141
142
143
144
145
146
147
# File 'lib/kamelopard/function.rb', line 137

def self.interpolate(ymin, ymax, x1, y1, min = -1.0, max = 1.0)
    x1 = (max.to_f + min) / 2.0 if x1.nil?
    y1 = (ymax.to_f + ymin) / 2.0 if y1.nil?
    xm = Matrix[[min ** 2, x1 ** 2, max ** 2], [min, x1, max], [1, 1, 1]]
    ym = Matrix[[ymin, y1, ymax]]
    m = ym * xm.inverse
    c2 = m[0,0]
    c1 = m[0,1]
    c0 = m[0,2]
    return Quadratic.new(c2, c1, c0, min, max)
end