using Plots, DifferentialEquations
function projectile_motion(v₀, θ)
g = 9.8067 # acceleration due to gravity (m/s^2)
t_final = 2 * v₀ * sind(θ) / g # total flight time
# Define the system of second-order ODEs
function projectile!(du, u, p, t)
x, y = u
ddu = [0 -g]
end
# Initial conditions
(u₀, du₀) = [[0.0 0.0], [v₀ * cosd(θ) v₀ * sind(θ)]]
# Time span
t_span = [0.0, 20]
# Solve the ODE
prob = SecondOrderODEProblem(projectile!, du₀, u₀, t_span)
sol = solve(prob, Tsit5(), dt=0.001)
return sol # return the value of du u
end
# Initial velocity and launch angle
v₀ = 100.0 # initial velocity in m/s
θ = 45.0 # launch angle in degrees
# Simulate projectile motion
sol = projectile_motion(v₀, θ)
the type of sol.u is a Vector
Plot the results gives:
plot(sol, title = "Projectile Motion", xaxis = "Time in Seconds",
yaxis = "Velocity (m/s) | Position(m)",labels = ["x Velocity" "y Velocity" "x Position" "y Position"], widen = true, xlims = (0.0, 20.0), ylims = (-500.0, 1500.0))
using twinx()
how to display velocity and position separately? what syntax can change the structure or type of sol.u?
by the way, I want labels box off,what syntax should be used?