Skip to content

Commit 1fb836c

Browse files
leiosButt4cak3
authored andcommitted
Julia verlet update (#266)
1 parent 43cc48f commit 1fb836c

File tree

1 file changed

+13
-6
lines changed
  • chapters/algorithms/verlet_integration/code/julia

1 file changed

+13
-6
lines changed

chapters/algorithms/verlet_integration/code/julia/verlet.jl

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function verlet(pos::Float64, acc::Float64, dt::Float64)
99
prev_pos = temp_pos
1010
end
1111

12-
println(time)
12+
return time
1313
end
1414

1515
function stormer_verlet(pos::Float64, acc::Float64, dt::Float64)
@@ -27,7 +27,7 @@ function stormer_verlet(pos::Float64, acc::Float64, dt::Float64)
2727
vel += acc*dt
2828
end
2929

30-
println(time)
30+
return time, vel
3131
end
3232

3333
function velocity_verlet(pos::Float64, acc::Float64, dt::Float64)
@@ -41,13 +41,20 @@ function velocity_verlet(pos::Float64, acc::Float64, dt::Float64)
4141
vel += acc * dt;
4242
end
4343

44-
println(time)
44+
return time, vel
4545
end
4646

4747
function main()
48-
verlet(5.0, -10.0, 0.01);
49-
stormer_verlet(5.0, -10.0, 0.01);
50-
velocity_verlet(5.0, -10.0, 0.01);
48+
time = verlet(5.0, -10.0, 0.01);
49+
println("Time for Verlet integration is: $(time)\n")
50+
51+
time, vel = stormer_verlet(5.0, -10.0, 0.01);
52+
println("Time for Stormer Verlet integration is: $(time)")
53+
println("Velocity for Stormer Verlet integration is: $(vel)\n")
54+
55+
time, vel = velocity_verlet(5.0, -10.0, 0.01);
56+
println("Time for velocity Verlet integration is: $(time)")
57+
println("Velocity for velocity Verlet integration is: $(vel)\n")
5158
end
5259

5360
main()

0 commit comments

Comments
 (0)