num4mechaequ 0.0.3 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -0
  3. data/lib/num4mechaequ.rb +102 -16
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa1f15732e36a08d7b119cc9d638d27ea13182fd1f4a36bac3b4e823996fcffd
4
- data.tar.gz: 486c9ee96ffdf6db1a83e23f68bc146b7ea7af7b7298ec13215b71f06078cb91
3
+ metadata.gz: ece1c1f8ac4951ed3e9225bc0139f6a332f4ecc22d271cdcb149cd191e28840f
4
+ data.tar.gz: e9579a5fe2e05b269f0e0aac9c232588bcbe2660268098087311337b694ecd08
5
5
  SHA512:
6
- metadata.gz: 4e6936f8107a121a98a2d3f010a99219b8a09bb1f1d769b748300953a42a9d4a6f9780f68a33a838122a88e94a0e962c25d96b87675b15abcf025f3385e09af1
7
- data.tar.gz: d1886b86214b6670ce2c5698b1ca4f639a59f5d7cc884be83385b302425d40da6640e57637a47dbe35edaa1a126cdc23da6cb59bcb697ee2499d705d4bd9c88b
6
+ metadata.gz: 6c943c0d56cdb23ba471236f6e772c70f20f0bc96303d9a3138ce7247e27c4ad48a52e63047ad055a2fb03522bdf99eeed6bc4b09b3d104ce19a5276046a8656
7
+ data.tar.gz: 2428c482848f27714fe833dd741347aa30e29f37191faecf35984a28bdab2c38a4c96787a4d1e7469afb94d927792322570769775bb20c44de330800c250cd7a
data/CHANGELOG.md CHANGED
@@ -2,6 +2,30 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## [0.1.2] - 2022-07-13
6
+
7
+ ### Added
8
+ - add function of UCM
9
+ - add function of pendulumMotion
10
+
11
+ ### Fixed
12
+ - change order of parameter of SHM
13
+
14
+ SHM(k, m, t, h0, v0) -> SHM(m, k, t, h0, v0)
15
+
16
+ ## [0.1.1] - 2022-07-10
17
+
18
+ ### Changed
19
+ - change of function name
20
+ * motiEqu4freeFallEqu -> freeFallMotion
21
+ * springFreqEqu -> SHM
22
+
23
+ ### Fixed
24
+ - fix appointed time. (from 0 to n)
25
+
26
+ ### Added
27
+ - add function of projectileMotion
28
+
5
29
  ## [0.0.3] - 2022-07-03
6
30
 
7
31
  ### Changed
data/lib/num4mechaequ.rb CHANGED
@@ -4,39 +4,55 @@ require 'num4simdiff'
4
4
  # 数値計算による力学方程式の解法するライブラリ
5
5
  #
6
6
  module Num4MechaEquLib
7
- @g = 9.80665 # 重力加速度
8
- @t = 0.001 # 時間刻み
7
+ @g = 9.80665 # 重力加速度(m/s2)
8
+ @dt = 0.001 # 時間刻み
9
9
  @w = 0.0
10
+ # 単振動
10
11
  @springFunc = Proc.new do | n, yi |
11
12
  f = []
12
13
  f[0] = yi[1] # hの傾き値
13
- f[1] = @w * yi[0] - @g# vの傾き値
14
+ f[1] = - @w * @w * yi[0] # vの傾き値
14
15
  next f
15
16
  end
17
+ # 自由落下運動
16
18
  @motionFunc = Proc.new do | n, yi |
17
19
  f = []
18
20
  f[0] = yi[1] # hの傾き値
19
- f[1] = - @g # vの傾き値
21
+ f[1] = - @g + @w * yi[1] # vの傾き値
22
+ next f
23
+ end
24
+ # 放物運動
25
+ @projectileXFunc = Proc.new do | n, yi |
26
+ f = []
27
+ f[0] = yi[1] # hの傾き値
28
+ f[1] = 0 # vの傾き値
29
+ next f
30
+ end
31
+ @projectileYFunc = Proc.new do | n, yi |
32
+ f = []
33
+ f[0] = yi[1] # hの傾き値
34
+ f[1] = - @g # vの傾き値
20
35
  next f
21
36
  end
22
37
  class << self
23
38
 
24
39
  #
25
- # バネの固有振動
26
- # @overload springFreqEqu(k, m, h0, v0)
27
- # @param [double] k バネ定数
40
+ # 単振動(simple harmonic motion)
41
+ # @overload SHM(m, k, t, h0, v0)
28
42
  # @param [double] m 重りの重さ
43
+ # @param [double] k バネ定数
44
+ # @param [double] t 時間
29
45
  # @param [double] h0 初期位置値
30
46
  # @param [double] v0 初期速度
31
- # @return [hash[]] 0秒から1秒までの位置(h)と速度(v)の値
47
+ # @return [hash[]] 0秒からt秒までの位置(h)と速度(v)の値
32
48
  #
33
- def springFreqEqu(k, m, h0, v0)
49
+ def SHM(m, k, t, h0, v0)
34
50
  @w = Math.sqrt((k / m))
35
51
  hvt = []
36
52
  yi_1 = []
37
53
  yi = [h0, v0]
38
- 0.step(1, @t) { |x|
39
- yi_1 = Num4SimDiffLib.rungeKuttaMethod(yi, @t, @springFunc)
54
+ 0.step(t, @dt) { |x|
55
+ yi_1 = Num4SimDiffLib.rungeKuttaMethod(yi, @dt, @springFunc)
40
56
  hvt.push({"t" => x,
41
57
  "h" => yi_1[0], "v" => m * yi_1[1]})
42
58
  yi = yi_1
@@ -45,18 +61,21 @@ module Num4MechaEquLib
45
61
  end
46
62
  #
47
63
  # 自由落下による運動方程式(空気抵抗有り)
48
- # @overload motiEqu4freeFallEqu(m, h0, v0)
64
+ # @overload freeFallMotion(m, c, t, h0, v0)
49
65
  # @param [double] m 重りの重さ
66
+ # @param [double] c 空気抵抗
67
+ # @param [double] t 時間
50
68
  # @param [double] h0 初期位置値
51
69
  # @param [double] v0 初期速度
52
- # @return [hash[]] 0秒から1秒までの位置(h)と速度(v)の値
70
+ # @return [hash[]] 0秒からt秒までの位置(h)と速度(v)の値
53
71
  #
54
- def motiEqu4freeFallEqu(m, h0, v0)
72
+ def freeFallMotion(m, c, t, h0, v0)
73
+ @w = c / m
55
74
  hvt = []
56
75
  yi_1 = []
57
76
  yi = [h0, v0]
58
- 0.step(1, @t) { |x|
59
- yi_1 = Num4SimDiffLib.rungeKuttaMethod(yi, @t, @motionFunc)
77
+ 0.step(t, @dt) { |x|
78
+ yi_1 = Num4SimDiffLib.rungeKuttaMethod(yi, @dt, @motionFunc)
60
79
  hvt.push({"t" => x,
61
80
  "h" => yi_1[0], "v" => m * yi_1[1]})
62
81
  yi = yi_1
@@ -64,6 +83,73 @@ module Num4MechaEquLib
64
83
  return hvt
65
84
 
66
85
  end
86
+ #
87
+ # 放物運動
88
+ # @overload projectileMotion(m, theta, t, h0, v0)
89
+ # @param [double] m 重りの重さ
90
+ # @param [double] theta 角度(ラジアン指定)
91
+ # @param [double] t 時間
92
+ # @param [double] h0 初期位置値
93
+ # @param [double] v0 初期速度
94
+ # @return [hash[]] 0秒からt秒までの位置(h)と速度(v)の値
95
+ #
96
+ def projectileMotion(m, theta, t, h0, v0)
97
+ hvt = []
98
+ yxi_1 = []
99
+ yyi_1 = []
100
+ yxi = [h0, v0 * Math.cos(theta)]
101
+ yyi = [h0, v0 * Math.sin(theta)]
102
+ 0.step(t, @dt) { |x|
103
+ yxi_1 = Num4SimDiffLib.rungeKuttaMethod(yxi, @dt, @projectileXFunc)
104
+ yyi_1 = Num4SimDiffLib.rungeKuttaMethod(yyi, @dt, @projectileYFunc)
105
+ hvt.push({"t" => x,
106
+ "x" => {"h" => yxi_1[0], "v" => m * yxi_1[1]},
107
+ "y" => {"h" => yyi_1[0], "v" => m * yyi_1[1]},
108
+ }
109
+ )
110
+ yxi = yxi_1
111
+ yyi = yyi_1
112
+ }
113
+ return hvt
114
+ end
115
+ #
116
+ # 等速円運動(Uniform Circular motion)
117
+ # @overload UCM(m, r, w, t)
118
+ # @param [double] m 重りの重さ
119
+ # @param [double] r 半径
120
+ # @param [double] w 角速度
121
+ # @param [double] t 時間
122
+ # @return [hash[]] 0秒からt秒までの位置(h)と速度(v)の値
123
+ def UCM(m, r, w, t)
124
+ hvt = []
125
+ h = []
126
+ v = []
127
+ 0.step(t, @dt) { |x|
128
+ sinwt = Math.sin(w * x)
129
+ coswt = Math.cos(w * x)
130
+ h = [r * coswt, r * sinwt]
131
+ v = [r * w * -sinwt, r * w * coswt]
132
+ a = [-r * w * w * coswt, -r * w * w * sinwt]
133
+ hvt.push({"t" => x,
134
+ "x" => {"h" => h[0], "v" => m * v[0]},
135
+ "y" => {"h" => h[1], "v" => m * v[1]},
136
+ }
137
+ )
138
+ }
139
+ return hvt
140
+ end
141
+ #
142
+ # 振り子運動
143
+ # @overload pendulumMotion(m, l, t, h0, v0)
144
+ # @param [double] m 重りの重さ
145
+ # @param [double] l 糸の長さ
146
+ # @param [double] t 時間
147
+ # @param [double] h0 初期位置値
148
+ # @param [double] v0 初期速度
149
+ # @return [hash[]] 0秒からt秒までの位置(h)と速度(v)の値
150
+ def pendulumMotion(m, l, t, h0, v0)
151
+ return SHM(m, l, t, h0, v0)
152
+ end
67
153
  end
68
154
  end
69
155
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: num4mechaequ
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - siranovel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-03 00:00:00.000000000 Z
11
+ date: 2023-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: num4simdiff
@@ -45,7 +45,7 @@ licenses:
45
45
  - MIT
46
46
  metadata:
47
47
  changelog_uri: http://github.com/siranovel/num4mechaequation/blob/main/CHANGELOG.md
48
- documentation_uri: https://rubydoc.info/gems/num4mechaequ/0.0.3
48
+ documentation_uri: https://rubydoc.info/gems/num4mechaequ/0.1.2
49
49
  homepage_uri: http://github.com/siranovel/num4mechaequation
50
50
  wiki_uri: https://github.com/siranovel/mydocs/tree/main/num4phyequation/num4mechaequation
51
51
  post_install_message: