Skip to content

Julia verlet update #266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions chapters/algorithms/verlet_integration/code/julia/verlet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function verlet(pos::Float64, acc::Float64, dt::Float64)
prev_pos = temp_pos
end

println(time)
return time
end

function stormer_verlet(pos::Float64, acc::Float64, dt::Float64)
Expand All @@ -27,7 +27,7 @@ function stormer_verlet(pos::Float64, acc::Float64, dt::Float64)
vel += acc*dt
end

println(time)
return time, vel
end

function velocity_verlet(pos::Float64, acc::Float64, dt::Float64)
Expand All @@ -41,13 +41,20 @@ function velocity_verlet(pos::Float64, acc::Float64, dt::Float64)
vel += acc * dt;
end

println(time)
return time, vel
end

function main()
verlet(5.0, -10.0, 0.01);
stormer_verlet(5.0, -10.0, 0.01);
velocity_verlet(5.0, -10.0, 0.01);
time = verlet(5.0, -10.0, 0.01);
println("Time for Verlet integration is: $(time)\n")

time, vel = stormer_verlet(5.0, -10.0, 0.01);
println("Time for Stormer Verlet integration is: $(time)")
println("Velocity for Stormer Verlet integration is: $(vel)\n")

time, vel = velocity_verlet(5.0, -10.0, 0.01);
println("Time for velocity Verlet integration is: $(time)")
println("Velocity for velocity Verlet integration is: $(vel)\n")
end

main()