1

This is equations of motion in $3D:$ How can we numerically solve this system of the equations? (preferably Euler). can you give a sample of $2$ step sizes how is it possible?

$\frac{d^2x}{dt^2} = -vk_d\frac{dx}{dt} + vk_l\frac{dy}{dt}$
$\frac{d^2y}{dt^2} = -vk_d\frac{dy}{dt} - vk_l\frac{dx}{dt}$
$\frac{d^2z}{dt^2} = -vk_d\frac{dz}{dt} - g$

$v = \sqrt{(\frac{dx}{dt})^2 + (\frac{dy}{dt})^2 +(\frac{dz}{dt})^2}$

$g, k_d, k_l$ are constants.
step size = $0.01$ sec = $t$

Intial Conditions:
x,y,z = 0
$\frac{dx}{dt}=10.45$
$\frac{dy}{dt}=5.45$
$\frac{dz}{dt}=33.45$
$v_0=25$

Lutz Lehmann
  • 126,666
Nish
  • 133
  • Giving constants is useless if you do not give all constants, $g,k_d,k_l$ are missing. It should also be $v=\sqrt{v_x^2+v_y^2+v_z^2}$. What is the second force, some kind of Coriolis force? But then it is proportional to the square of the speed over ground,... – Lutz Lehmann Dec 13 '20 at 12:30
  • Yeah you are right , my bad, it should velocities – Nish Dec 13 '20 at 19:17

1 Answers1

1

In python (and similar in other languages) you would encode the ODE function of the right side, for the first order system with $v_x=\dot x$ etc., as

def motioneqns(t,u):
    x,y,z,vx,vy,vz = u
    v = (vx**2+vy**2+vz**2)**0.5
    ax = -kd*v*vx + kl*v*vy
    ay = -kd*v*vy - kl*v*vx
    az = -kd*v*vz - g
    return vx,vy,vz,ax,ay,az

and pass it along to any general-purpose solver, which might be one implementing the Euler method, or RK4, or some higher order method with adaptive step size.

If you use implementations similar to those in Does fourth-order Runge-Kutta have an higher accuracy than the second-order one? you need to wrap the result list in a vector type, for instance numpy.array, either in the return line or in the function call. For further inspiration on getting the trajectories as list see https://stackoverflow.com/questions/61333687/how-do-i-solve-a-2nd-order-differential-equation-for-projectile-motion, https://stackoverflow.com/questions/53645649/cannot-get-rk4-to-solve-for-position-of-orbiting-body.

Lutz Lehmann
  • 126,666
  • Thank you so much for your help, it was helpful. But I wanted to write theoretically / Mathematically. – Nish Dec 13 '20 at 17:00
  • You mean like writing $u_{n+1,k}=u_{n,k}+hf_k(t_n,u_n)$, where $u_n=(u_{n,1},...,u_{n,d})$ is the state vector at time $t_n$? – Lutz Lehmann Dec 13 '20 at 17:13
  • yes, I want the working for 2 steps (step-size=0.01 so for 0.01 and 0.02) using Euler. i cant seem to wrap my head around the mathematics – Nish Dec 13 '20 at 18:28