Module: Num4MechaEquLib

Defined in:
lib/num4mechaequ.rb

Overview

数値計算による力学方程式の解法するライブラリ

Class Method Summary collapse

Class Method Details

.freeFallMotion(m, c, t, h0, v0) ⇒ hash[]

自由落下による運動方程式(空気抵抗有り)

Returns 0秒からt秒までの位置(h)と速度(v)の値.

Parameters:

  • m (double)

    重りの重さ

  • c (double)

    空気抵抗

  • t (double)

    時間

  • h0 (double)

    初期位置値

  • v0 (double)

    初期速度

Returns:

  • (hash[])

    0秒からt秒までの位置(h)と速度(v)の値



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/num4mechaequ.rb', line 72

def freeFallMotion(m, c, t, h0, v0)
    @w = c / m
    hvt = []
    yi_1 = []
    yi = [h0, v0]
    0.step(t, @dt) { |x|
      yi_1 = Num4SimDiffLib.rungeKuttaMethod(yi, @dt, @motionFunc)
      hvt.push({"t" => x, 
                "h" => yi_1[0], "v" => m * yi_1[1]})
      yi = yi_1
    }
    return hvt

end

.projectileMotion(m, theta, t, h0, v0) ⇒ hash[]

放物運動

Returns 0秒からt秒までの位置(h)と速度(v)の値.

Parameters:

  • m (double)

    重りの重さ

  • theta (double)

    角度(ラジアン指定)

  • t (double)

    時間

  • h0 (double)

    初期位置値

  • v0 (double)

    初期速度

Returns:

  • (hash[])

    0秒からt秒までの位置(h)と速度(v)の値



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/num4mechaequ.rb', line 96

def projectileMotion(m, theta, t, h0, v0)
    hvt = []
    yxi_1 = []
    yyi_1 = []
    yxi = [h0, v0 * Math.cos(theta)]
    yyi = [h0, v0 * Math.sin(theta)]
    0.step(t, @dt) { |x|
      yxi_1 = Num4SimDiffLib.rungeKuttaMethod(yxi, @dt, @projectileXFunc)
      yyi_1 = Num4SimDiffLib.rungeKuttaMethod(yyi, @dt, @projectileYFunc)
      hvt.push({"t" => x, 
                "x" => {"h" => yxi_1[0], "v" => m * yxi_1[1]},
                "y" => {"h" => yyi_1[0], "v" => m * yyi_1[1]},
               }
              )
      yxi = yxi_1
      yyi = yyi_1
    }
    return hvt
end

.SHM(k, m, t, h0, v0) ⇒ hash[]

単振動(simple harmonic motion)

Returns 0秒からt秒までの位置(h)と速度(v)の値.

Parameters:

  • k (double)

    バネ定数

  • m (double)

    重りの重さ

  • t (double)

    時間

  • h0 (double)

    初期位置値

  • v0 (double)

    初期速度

Returns:

  • (hash[])

    0秒からt秒までの位置(h)と速度(v)の値



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/num4mechaequ.rb', line 49

def SHM(k, m, t, h0, v0)
    @w = Math.sqrt((k / m))
    hvt = []
    yi_1 = []
    yi = [h0, v0]
    0.step(t, @dt) { |x|
      yi_1 = Num4SimDiffLib.rungeKuttaMethod(yi, @dt, @springFunc)
      hvt.push({"t" => x, 
                "h" => yi_1[0], "v" => m * yi_1[1]})
      yi = yi_1
    }
    return hvt
end