diff options
Diffstat (limited to 'examples/FallingBall.jl')
-rw-r--r-- | examples/FallingBall.jl | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/examples/FallingBall.jl b/examples/FallingBall.jl new file mode 100644 index 0000000..35d4b31 --- /dev/null +++ b/examples/FallingBall.jl @@ -0,0 +1,25 @@ +#!/Applications/Julia-1.8.app/Contents/Resources/julia/bin/julia + +dt = 0.01 # time step in seconds +g = 9.8 # acceleration of gravity in m/s^2 + +function dynamics(y::Float64, v::Float64, t::Float64) + for i in 1:100 + y = y + v * dt + v = v - g * dt + t = t + dt + end + + return y, v, t +end + +y0 = 10.0 # initial position in meters +v0 = 0.0 # initial velocity in m/s + +y, v, t = dynamics(y0, v0, 0.0) # evolave for 100 time steps + +println("\n\t Results") +println("final time = ", t) +println("y = ", y, " and v = ", v) +println("exact v = ", v0 - g * t) +println("exact y = ", y0 + v0 * t - 0.5 * g * t^2.0)
\ No newline at end of file |