# Ways to solve numerically differential equations in C [closed]

I have to solve numerically a differential equation in C. The equation is:

How can I write some code to solve it? Are there some numerical methods (Runge-Kutta maybe?) to solve it?

A colleague proposed to me to use the exact discretization method, but I don't think it's the smartest way to do, especially in programming.

Any suggestions?

• This question is too broad to answer in a generally useful way and doesn't really show any effort to answer it on your own. Assuming that h and u are constants in your equation then it easily can easily be solved analytically. – Doug Lipinski Jun 15 '15 at 11:33
• To answer your questions: "How can I write some code to solve it?" Find the method you want to use and start coding. "Are there some numerical methods (Runge-Kutta maybe?) to solve it?" Yes, there are many, RK is one. "Any suggestions?" Read up on numerical solutions to first order ODEs. – Doug Lipinski Jun 15 '15 at 11:35
• One thing you can try is reading the wikipedia page on Runge-Kutta and try implementing yourself based on the explanation on wikipedia. I did this on the past and was very intructive. – Hydro Guy Jun 22 '15 at 13:27

## 2 Answers

I think that the easiest way is to use the Forward Euler method. You should take a look at this page in which the code is explained.

If you are willing to use C++, I suggest taking a look at the odeint package that is part of the Boost library:

http://www.boost.org/doc/libs/1_58_0/libs/numeric/odeint/doc/html/index.html

In general, writing a production quality ODE solver is not a simple task. odeint has been available in Boost for several years and is relatively mature and robust. Pre-built Boost libraries are available for many platforms which significantly simplifies installation.

• unfortunately I need to use C – Betelgeuse Jun 15 '15 at 12:49