1
- proc verlet (pos_in, acc, dt: float ): float =
1
+ func verlet (pos_in, acc, dt: float ): float =
2
2
var
3
3
pos: float = pos_in
4
4
prevPos: float = pos
@@ -11,9 +11,9 @@ proc verlet(pos_in, acc, dt: float): float =
11
11
pos = pos * 2 - prevPos + acc * dt * dt
12
12
prevPos = tempPos
13
13
14
- return time
14
+ time
15
15
16
- proc stormerVerlet (pos_in, acc, dt: float ): (float , float ) =
16
+ func stormerVerlet (pos_in, acc, dt: float ): (float , float ) =
17
17
var
18
18
pos: float = pos_in
19
19
prevPos: float = pos
@@ -29,9 +29,9 @@ proc stormerVerlet(pos_in, acc, dt: float): (float, float) =
29
29
30
30
vel += acc * dt
31
31
32
- return (time, vel)
32
+ (time, vel)
33
33
34
- proc velocityVerlet (pos_in, acc, dt: float ): (float , float ) =
34
+ func velocityVerlet (pos_in, acc, dt: float ): (float , float ) =
35
35
var
36
36
pos: float = pos_in
37
37
time: float = 0.0
@@ -42,15 +42,16 @@ proc velocityVerlet(pos_in, acc, dt: float): (float, float) =
42
42
pos += vel * dt + 0.5 * acc * dt * dt
43
43
vel += acc * dt
44
44
45
- return (time, vel)
45
+ (time, vel)
46
46
47
- let timeV = verlet (5.0 , - 10.0 , 0.01 )
48
- echo " Time for Verlet integration is: " , timeV
47
+ when isMainModule :
48
+ let timeV = verlet (5.0 , - 10.0 , 0.01 )
49
+ echo " Time for Verlet integration is: " , timeV
49
50
50
- let (timeSV, velSV) = stormerVerlet (5.0 , - 10.0 , 0.01 )
51
- echo " Time for Stormer Verlet integration is: " , timeSV
52
- echo " Velocity for Stormer Verlet integration is: " , velSV
51
+ let (timeSV, velSV) = stormerVerlet (5.0 , - 10.0 , 0.01 )
52
+ echo " Time for Stormer Verlet integration is: " , timeSV
53
+ echo " Velocity for Stormer Verlet integration is: " , velSV
53
54
54
- let (timeVV, velVV) = velocityVerlet (5.0 , - 10.0 , 0.01 )
55
- echo " Time for velocity Verlet integration is: " , timeVV
56
- echo " Velocity for velocity Verlet integration is: " , velVV
55
+ let (timeVV, velVV) = velocityVerlet (5.0 , - 10.0 , 0.01 )
56
+ echo " Time for velocity Verlet integration is: " , timeVV
57
+ echo " Velocity for velocity Verlet integration is: " , velVV
0 commit comments