I have the following equation :

$$\frac{dx}{dt} = -5(x-2)$$

$$\frac{dy}{dt} = 0$$

How do I change this differential equation to a difference equation ? Do I use Euler forward method ? I remember taking this before but I have totally forgotten about it. I tried reading online to refresh my memory but I did not really grasp the idea. I would really appreciate if someone can solve this particular equation step by step so that I can fully understand the solution, along with supporting key concept points to grasp the idea. Thanks.

  • $\begingroup$ Why do you want to change this differential equation into a difference equation? There are difference equations "approximating" the given differential equation, but there is no (finite) difference equation equivalent to it. $\endgroup$ – Christian Blatter Feb 6 '13 at 19:27
  • $\begingroup$ @ChristianBlatter Yes, I want to approximate it because I want to later on discretize the model and simulate it in Python. So I want a difference equation. $\endgroup$ – NLed Feb 6 '13 at 19:41

You seem to be interested in the general techniques for solving differential equations numerically.

Given $x'(t), y'(t)$ there are many ways you can come up with a differencing equation to approximate the solution on a discretized domain. Most of these are derived from Taylor series expansions.

$$x(t+\Delta t) = x(t) + x'(t) \Delta t + \ldots$$

Truncating the expansion here gives you forward differencing. As this is a problem rooted in time integration, this is most likely the kind of thing you would want to do.

However, as often as not one prefers more sophisticated approaches. Euler's method is simple but also not very good. 4th order Runge-Kutta is often used, as it strikes a balance between simplicity and accuracy that is usually pretty good. This too can, in principle, be derived from Taylor series expansions, but that's a bit more involved.


$\frac{dx}{dt}=-5(x-2)$ then $\frac{dx}{(x-2)}=-5dt$ :integrate both side$$ln(x-2)=-5t+c $$$$x=e^{-5t+c}+2$$ and $y(t)=2t+c$

  • $\begingroup$ The OP wants to change the differential equation to a difference equation. He/she is asking about it not about solving the OE. ;-) $\endgroup$ – mrs Feb 6 '13 at 18:59
  • $\begingroup$ @Babak sorouh:hi thanks i dont understand question perfectly $\endgroup$ – M.H Feb 6 '13 at 19:02
  • $\begingroup$ Thanks for the info though $\endgroup$ – NLed Feb 6 '13 at 20:54

You can put $y$ in terms of $x$ by noting $dy/dx = (dy/dt) / (dx / dt)$.

For your first question, $dy/dx = (0) / (-5(x-2)) = 0$, so integrating, $y = C$ for some constant $C$.

Your second question is more complicated as it has both $x$ and $y$ in it, so I'm not sure this method will apply for that equation.

  • $\begingroup$ Can you please elaborate and structure your answer better ? So that I can actually mark this as correct... $\endgroup$ – NLed Feb 6 '13 at 19:13

I will consider the first equation:

$$\frac{dx}{dt} = -5 (x-2)$$

There are many schemes for discretization. In my experience, centered difference works because the error is second order and the computation relatively light. In this, we assume that we have a vector of sample points $x_k$, $k \in \{1,2,3,\ldots,n\}$, each $x_k$ corresponding to a value of $t_k = (k-1) \Delta t$. The discrete equation then reads

$$\frac{x_{k+1/2} - x_{k-1/2}}{\Delta t} = - 5 (x_k - 2)$$

Why the half-steps? Again, it is a centered difference whose symmetry cancels out 1st-order error. We may compute the values of $x$ on the half steps by, e.g., averaging (so that $x_{k+1/2} = (1/2) (x_k + x_{k+1})$.

Now, in order to use this equation, you need an initial value, i.e., $x(0) = x_0$. Assume $x_{-1/2}=0$. You now have enough to propagate a solution through all of the $x_k$.

  • $\begingroup$ Thanks for the response, can you also explain how the Forward Difference method can be used instead of the centered difference method ? $\endgroup$ – NLed Feb 6 '13 at 20:13
  • $\begingroup$ It would be used exactly the same way, but the left side replaced by $x_{k+1}-x_k$, which is fine, but you have a larger error. $\endgroup$ – Ron Gordon Feb 6 '13 at 20:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.