# Setting up and solving differential equation with The Euler Method

I recently started this question and it gave me some insight into the world of differential equations.

However the solution was not fit for my goals as I wanted a general method for calculating the position of a particle travelling through a vector field where the vectors in the field represents a force pushing on the particle.

So this is kind of a follow-up from the information I got from my other question.

So what do I have?

A vector field that is defined by a function:

$\vec{F}(x,y)$

I have left out the definition of the function since I wish to find a solution that works regardless off the function definition. But one example could be: $\vec{F}(x,y) = (\sin(x),\cos(y))$

A particle, which have some initial values for position and velocity

$\vec{p}(0)=P$

$\dot{\vec{p}}(0)=Q$

I know wish to find the position of the particle after a specified time $\vec{P}(t)$ and velocity $\dot{\vec{P}}(t)$.

From what I learned from the other question it's not possible to find a closed form solution to this, but you have to use some approximation with for example Euler's Method. However I don't know how to model this scenario as a differential equation and how to apply Euler's Method (or any other approximation technique) to my scenario. If someone could, step by step explain this process it would be much appreciated!

I should also add, the goal is to implement this in a program, so keep that in mind!

Thanks!

P.S.

I'm sure I missed stuff and you have questions about my logic here so I'd be happy to edit and answer any questions.

-
If you require good accuracy for your differential-equation solving needs, you don't need to write your own code, and you certainly shouldn't be using Euler naked (at least, not without additional machinery subscribed). Have a look at these for instance. – J. M. May 16 '11 at 1:02

If the vector field represents the force acting on the particle, then by Newton's law you have $F(p(t)) = m \ddot p(t)$, where $m$ is the mass. Since you don't say anything about mass, let's take $m=1$. You can write Newton's equation as a first-order differential equation by setting $u(t)=(p(t),\dot p(t))$ and getting $\dot u = (\dot p, \ddot p) = (\dot p, F(p))$. In this form, Euler's method is simply $u^{k+1} = u^k + h (\dot p^k, F(p^k))$, which gives you two equations: $p^{k+1} = p^k + h \dot p^{k}$, $\dot p^{k+1} = \dot p^{k} + h F(p^k)$, with $p^0 = P$, $\dot p^0 = Q$.