Module: Num4InteLib

Extended by:
FFI::Library
Defined in:
lib/num4inte.rb

Overview

数値計算による数値積分の解法するライブラリ

Instance Method Summary collapse

Instance Method Details

#f(xi) {|x| ... } ⇒ double

dy = f(xi)

Yields:

  • (x)

    dy = f(x)

Yield Parameters:

  • xi (double)

    xiの値

Returns:

  • (double)

    xiに対するyの値



16
# File 'lib/num4inte.rb', line 16

callback   :f, [:double], :double

#gaussLegendreRule(n, a, b, h, func) ⇒ double

ガウス求積法

Examples:

h = 0.001
func = Proc.new{|x|
    next 4 / (1 + x * x)
}
y = Num4InteLib.gaussLegendreRule(3, 0, 1, h, func)

y = gaussLegendreRule(n, a, b, h, func)

Parameters:

  • n (int)

    分割数

  • a (double)

    aの値

  • b (double)

    bの値

  • h (double)

    刻み幅

  • func (callback)

    xiに対する傾きを計算する関数

Returns:

  • (double)

    [a,b]の間の積分値



107
108
# File 'lib/num4inte.rb', line 107

attach_function :gaussLegendreRule,
:CNum4Inte_gauss_gaussLegendreRule, [:int, :double, :double, :double, :f], :double

#leftReimannSumMethod(a, b, h, func) ⇒ double

左リーマン和法

Examples:

h = 0.001
func = Proc.new{|x|
    next 4 / (1 + x * x)
}
y = Num4InteLib.leftReimannSumMethod(0, 1, h, func)

y = leftReimannSumMethod(a, b, h, func)

Parameters:

  • a (double)

    aの値

  • b (double)

    bの値

  • h (double)

    刻み幅

  • func (callback)

    xiに対する傾きを計算する関数

Returns:

  • (double)

    [a,b]の間の積分値



34
35
# File 'lib/num4inte.rb', line 34

attach_function :leftReimannSumMethod,
:CNum4Inte_reimann_leftReimannSumMethod, [:double, :double, :double, :f], :double

#rigtReimannSumMethod(a, b, h, func) ⇒ double

右リーマン和法

Examples:

h = 0.001
func = Proc.new{|x|
    next 4 / (1 + x * x)
}
y = Num4InteLib.rigtReimannSumMethod(0, 1, h, func)

y = rigtReimannSumMethod(a, b, h, func)

Parameters:

  • a (double)

    aの値

  • b (double)

    bの値

  • h (double)

    刻み幅

  • func (callback)

    xiに対する傾きを計算する関数

Returns:

  • (double)

    [a,b]の間の積分値



52
53
# File 'lib/num4inte.rb', line 52

attach_function :rigtReimannSumMethod,
:CNum4Inte_reimann_rigtReimannSumMethod, [:double, :double, :double, :f], :double

#simpsonRule(a, b, h, func) ⇒ double

ニュートン・コーツ法(2次:シンプソンの公式)

Examples:

h = 0.001
func = Proc.new{|x|
    next 4 / (1 + x * x)
}
y = Num4InteLib.simpsonRule(0, 1, h, func)

y = simpsonRule(a, b, h, func)

Parameters:

  • a (double)

    aの値

  • b (double)

    bの値

  • h (double)

    刻み幅

  • func (callback)

    xiに対する傾きを計算する関数

Returns:

  • (double)

    [a,b]の間の積分値



88
89
# File 'lib/num4inte.rb', line 88

attach_function :simpsonRule,
:CNum4Inte_rewton_simpsonRule, [:double, :double, :double, :f], :double

#trapezioidalRule(a, b, h, func) ⇒ double

ニュートン・コーツ法(1次:台形公式)

Examples:

h = 0.001
func = Proc.new{|x|
    next 4 / (1 + x * x)
}
y = Num4InteLib.trapezioidalRule(0, 1, h, func)

y = trapezioidalRule(a, b, h, func)

Parameters:

  • a (double)

    aの値

  • b (double)

    bの値

  • h (double)

    刻み幅

  • func (callback)

    xiに対する傾きを計算する関数

Returns:

  • (double)

    [a,b]の間の積分値



70
71
# File 'lib/num4inte.rb', line 70

attach_function :trapezioidalRule,
:CNum4Inte_rewton_trapezioidalRule, [:double, :double, :double, :f], :double