-2
$\begingroup$

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

enter image description here

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?

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Doug Lipinski Jun 15 '15 at 11:33
  • 1
    $\begingroup$ 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. $\endgroup$ – Doug Lipinski Jun 15 '15 at 11:35
  • $\begingroup$ 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. $\endgroup$ – Hydro Guy Jun 22 '15 at 13:27
1
$\begingroup$

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.

| cite | improve this answer | |
$\endgroup$
1
$\begingroup$

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.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ unfortunately I need to use C $\endgroup$ – Betelgeuse Jun 15 '15 at 12:49

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