diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/FallingBall3.jl | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/examples/FallingBall3.jl b/examples/FallingBall3.jl index 123a19a..823adfb 100644 --- a/examples/FallingBall3.jl +++ b/examples/FallingBall3.jl @@ -8,13 +8,15 @@ g = 9.8 # acceleration of gravity in m/s^2 t_final = 1.0 # final time of trajectory p = 0.0 # parameters (not used here) -function tendency!(dyv::Vector{Float64}, yv::Vector{Float64}, p, t::Float64) # ! notation tells us that arguments will be modified - y = yv[1] # 2D phase space; use vcat(x, v) to combine 2 vectors - v = yv[2] # dy/dt = v - a = -g # dv/dt = -g +function tendency!(dyv::Vector{Float64}, yv::Vector{Float64}, p, t) # ! notation tells us that arguments will be modified + y = yv[1] # 2D phase space; use vcat(x, v) to combine 2 vectors + v = yv[2] # dy/dt = v + a = -g # dv/dt = -g - dyv[1] = v - dyv[2] = a + dyv[1] = v + dyv[2] = a + + println("t = ", t, " y = ", y, " v = ", v) end y0 = 10.0 # initial position in meters @@ -23,7 +25,7 @@ yv0 = [y0, v0] # initial condition in phase space tspan = (0.0, t_final) # span of time to simulate prob = ODEProblem(tendency!, yv0, tspan, p) # specify ODE -sol = solve(prob, Tsit5(), reltol=1e-8, abstol=1e-8) # solve using Tsit5 algorithm to specified accuracy +sol = solve(prob, Tsit5(), reltol = 1e-8, abstol = 1e-8) # solve using Tsit5 algorithm to specified accuracy println("\n\t Results") println("final time = ", sol.t[end]) |