I have calculated formulas with 1 dimensional trajectory motion (free-fall) including quadratic drag, and have created the following equations.
These equations of motion are not of much use on its own, therefore I would like either a analytical method/numerical method in order to plot 2-dimensional projectile motion on a graph, y against x. However, I am aware that the equations of motion for two-dimensional projectiles are the following: m∗ax=−k∗√v2x+v2y∗vx
Hence, this is where I do not know the approach to the problem, I am not very familiar with numerical methods of solving equations. Is there any way to do this in a spreadsheet or in MATLAB, maintaining a great level of accuracy (If possible, using RK4).
Note: x-velocity is oriented on the right hand side, and the y-velocity directly upwards.
Please correct me if I have made any mistakes.
Answer
You basically have two ODEs to solve: dvμdt=1mF(xμ,vμ)dxμdt=vμ
One of the more stable routines is not actually RK4, but a variation of the leapfrog integration called velocity verlet. This turns (1) & (2) into a multi-step process: aμ1=F(xμi)/mxμi+1=xμi+(vi+12⋅aμ1⋅Δt)⋅Δtaμ2=F(xμi+1)/mvμi+1=vμi+12(aμ1+aμ2)⋅Δtx,y,vx,vy
).
Where your problem differs is that aμ=aμ(xμ,vμ), which makes computing the second acceleration a bit tricky since a2 depends on vμi+1 and vice versa. This answer at GameDev (definitely worth the read for some numerics aspect to the problem) suggests that you can use the following algorithm
aμ1=F(xμi,vμi)/mxμi+1=xμi+(vi+12⋅aμ1⋅Δt)⋅Δtvμi+1=vμi+12⋅aμ1⋅Δtaμ2=F(xμi+1,vμi+1)/mvμi+1=vμi+12⋅(aμ2−aμ1)⋅Δt
It's not quite as accurate as fourth-order Runge-Kutta (as one would expect from a second-order method), but it's much better than Euler or naïve velocity Verlet without the intermediate velocity estimate, and it still retains the symplectic property of normal velocity Verlet for conservative, non-velocity-dependent forces.
Since this is projectile motion, x=y=0 is probably a natural choice for initial conditions, with vy=v0sin(θ) and vx=v0cos(θ) as is normal.
No comments:
Post a Comment