Module: Mathpack::Equation
- Defined in:
- lib/mathpack/equation.rb
Class Method Summary collapse
Class Method Details
.derivative(xk, &function) ⇒ Object
13 14 15 16 |
# File 'lib/mathpack/equation.rb', line 13 def self.derivative(xk, &function) eps = 1e-5 (function.call(xk + eps) - function.call(xk - eps)) / (2 * eps) end |
.solve(params = {}, &function) ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/mathpack/equation.rb', line 3 def self.solve(params = {}, &function) xk1 = params[:start] loop do xk = xk1 xk1 = xk - function.call(xk) / derivative(xk, &function) break if (xk1 - xk).abs < params[:eps] end xk1 end |