Module: Rical
- Extended by:
- Rical
- Included in:
- Rical
- Defined in:
- lib/rical.rb,
lib/rical/errors.rb,
lib/rical/version.rb
Defined Under Namespace
Classes: NoConvergenceError
Constant Summary collapse
- VERSION =
'1.2.1'
Instance Method Summary collapse
- #inverse_for(f:, fargs: nil, y: 0.0, **args) ⇒ Object (also: #inv_for)
- #root_for(f:, fargs: nil, df: nil, dfargs: nil, x0: 0.0, x1: 1.0, method:, num: 100, err: 1e-6) ⇒ Object
Instance Method Details
#inverse_for(f:, fargs: nil, y: 0.0, **args) ⇒ Object Also known as: inv_for
24 25 26 27 |
# File 'lib/rical.rb', line 24 def inverse_for f:, fargs: nil, y: 0.0, **args f_1 = compute_f_1 f, fargs, y root_for f: f_1, fargs: fargs, **args end |
#root_for(f:, fargs: nil, df: nil, dfargs: nil, x0: 0.0, x1: 1.0, method:, num: 100, err: 1e-6) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rical.rb', line 7 def root_for f:, fargs: nil, df: nil, dfargs: nil, x0: 0.0, x1: 1.0, method:, num: 100, err: 1e-6 raise ArgumentError, 'f must respond_to call' unless f.respond_to? :call case method when :n, :newton, :newton_raphson raise ArgumentError, 'df is required' unless df raise ArgumentError, 'df must respond_to call' unless df.respond_to? :call newton_raphson_root_for f, fargs, df, dfargs, Float(x0), num, err when :s, :sec, :secant secant_root_for f, fargs, Float(x0), Float(x1), num, err else raise ArgumentError, 'unexpected method (allowed :newton, :secant)' end end |