Module: Num4MechaEquLib

Defined in:
lib/num4mechaequ.rb

Overview

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

Class Method Summary collapse

Class Method Details

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

減衰振動(damped harmonic motion)

Examples:

m = 1.0
k = 1.0
h0 = 1.0
v0 = 0.0
yi_1 = Num4MechaEquLib.DHM(m, k, 0.6, 2, h0, v0)

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

Parameters:

  • m (double)

    重りの重さ

  • k (double)

    比例定数

  • b (double)

    抵抗力の比例定数

  • t (double)

    時間

  • h0 (double)

    初期位置値

  • v0 (double)

    初期速度

Returns:

  • (hash[])

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



215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/num4mechaequ.rb', line 215

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

.forcedOscillation(m, k, w0, w, t, h0, v0) ⇒ hash[]

強制振動

Examples:

m = 1.0
k = 1.0
f0 = 2.5
h0 = 1.0
v0 = 0.0
yi_1 = Num4MechaEquLib.forcedOscillation(m, k, 0.6, f0, 2, h0, v0)

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

Parameters:

  • m (double)

    重りの重さ

  • k (double)

    比例定数

  • w0 (double)

    振動系の固有角振動

  • w (double)

    外力の角振動数

  • t (double)

    時間

  • h0 (double)

    初期位置値

  • v0 (double)

    初期速度

Returns:

  • (hash[])

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



248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/num4mechaequ.rb', line 248

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

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

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

Examples:

m = 1.0
c = 0.0
h0 = 1.0
v0 = 0.0
yi_1 = Num4MechaEquLib.freeFallMotion(m, c, 2, h0, v0)

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

Parameters:

  • m (double)

    重りの重さ

  • c (double)

    空気抵抗

  • t (double)

    時間

  • h0 (double)

    初期位置値

  • v0 (double)

    初期速度

Returns:

  • (hash[])

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



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

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

.pendulumMotion(m, l, t, h0, v0) ⇒ hash[]

振り子運動

Examples:

m = 1.0
l  = 10
h0 = 1.0
v0 = 0.0
yi_1 = Num4MechaEquLib.pendulumMotion(m, l, 2, h0, v0)

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

Parameters:

  • m (double)

    重りの重さ

  • l (double)

    糸の長さ

  • t (double)

    時間

  • h0 (double)

    初期位置値

  • v0 (double)

    初期速度

Returns:

  • (hash[])

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



195
196
197
# File 'lib/num4mechaequ.rb', line 195

def pendulumMotion(m, l, t, h0, v0)
    return SHM(m, l, t, h0, v0)
end

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

放物運動

Examples:

m = 1.0
theta = 5 * Math::PI / 180.0
yi_1 = Num4MechaEquLib.projectileMotion(m, theta, 2, 0.0, 3.0)

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

Parameters:

  • m (double)

    重りの重さ

  • theta (double)

    角度(ラジアン指定)

  • t (double)

    時間

  • h0 (double)

    初期位置値

  • v0 (double)

    初期速度

Returns:

  • (hash[])

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



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/num4mechaequ.rb', line 128

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(m, k, t, h0, v0) ⇒ hash[]

単振動(simple harmonic motion)

Examples:

m = 1.0
k = 1.0
h0 = 1.0
v0 = 0.0
yi_1 = Num4MechaEquLib.SHM(m, k, 2, h0, v0)

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

Parameters:

  • m (double)

    重りの重さ

  • k (double)

    バネ定数

  • t (double)

    時間

  • h0 (double)

    初期位置値

  • v0 (double)

    初期速度

Returns:

  • (hash[])

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



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

def SHM(m, k, 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, @SHMFunc)
      hvt.push({"t" => x, 
                "h" => yi_1[0], "v" => m * yi_1[1]})
      yi = yi_1
    }
    return hvt
end

.UCM(m, r, w, t) ⇒ hash[]

等速円運動(Uniform Circular motion)

Examples:

m = 1.0
r  = 3
w  = 2
yi_1 = Num4MechaEquLib.UCM(m, r, w, 2)

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

Parameters:

  • m (double)

    重りの重さ

  • r (double)

    半径

  • w (double)

    角速度

  • t (double)

    時間

Returns:

  • (hash[])

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



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/num4mechaequ.rb', line 161

def UCM(m, r, w, t)
    hvt = []
    h = []
    v = []
    0.step(t, @dt) { |x|
      sinwt = Math.sin(w * x)
      coswt = Math.cos(w * x)
      h = [r * coswt, r * sinwt]
      v = [r * w * -sinwt, r * w * coswt]
      a = [-r * w * w * coswt, -r * w * w * sinwt]
      hvt.push({"t" => x, 
                "x" => {"h" => h[0], "v" => m * v[0]},
                "y" => {"h" => h[1], "v" => m * v[1]},
               }
              )
    }
    return hvt
end