Implement Runge-Kutta 4 method to calculate the trajectory of a particle in a vector field

calculusnumerical methodsordinary differential equationsrunge-kutta-methodsVector Fields

I'm currently trying to approximate the trajectory of a particle inside a 2D vector field.

The particle has an initial position $P = (a,b)$, an initial velocity vector $\vec{V} = (p,q)$, and a given vector field $\vec{F}(x,y)=u(x,y)\mathbf{\hat{\imath}} + v(x,y)\mathbf{\hat{\jmath}}$

I was trying to implement RK4 to solve this problem. The issue is, I don't know how to do it.

I do not know how to implement the initial differential equations required for RK4 nor what the final iterative equation would look like.

Also, how do the final trajectory would be? Its going to be a set of points?

I would appreciate the help if someone could help me to better understand how to carry out this problem.

Thanks so much, I'll be keeping track to any recommendations, comments and answers on this topic. For everything else, have a nice day!

EDIT:

If the problem involving the initial velocity vector becomes too complicated, It can be omitted. Just with the initial position and the vector field should be enough to understand this numerical method. Thanks so much!

Best Answer

If the trajectory is $S(t) = (x(t), y(t))$ the velocity and acceleration are given by $$ V(t)= (x'(t), y'(t)), \quad A(t)=(x''(t),y''(t)) $$

So, using Newton's second law (I'm assuming $m=1$) $$ \begin{cases} x''(t) = u(x(t), y(t))\\ y''(t) = v(x(t), y(t)) \end{cases} $$

Considering that RK4 requires 1st order equations, you must rewrite the system as

$$ \begin{cases} x'(t) = v_x(t)\\ y'(t) = v_y(t)\\ v_x'(t) = u(x(t), y(t))\\ v_y'(t) = v(x(t), y(t)) \end{cases} $$

This system (together with the initial conditions for position and velocity) will give you the trajectory and velocity.

Related Question