11

I'm currently using C and some FORTRAN to solve numerically systems of differential equations.

I'm a bit fed up with both of these languages but I need to have some (rather) efficient code... I'm thinking of switching to OCaml.

Is it worth it?

2
  • 4
    I highly recommend SciPy - it is free, looks like Matlab (but is Python), and takes only a few lines to get it done! scipy.org/Cookbook/…
    – Job
    Feb 20, 2011 at 1:51
  • 1
    MATLAB. Numerical solution of systems of differential equations is a solved problem, and has been for quite some time. If your objective is to crunch your numbers, use the tools that have been developed over the last several decades to do just that. Don't reinvent the wheel, no matter how much fun it might be. You will save yourself a lot of time and aggravation. Jan 9, 2014 at 14:59

4 Answers 4

11

The people at Jane Street Capital sure think so. They gave a talk at CMU in 2009 about using OCaml.

The only drawback I can think of is that matrices aren't first class citizens.

8

First of all, I want to make the unusual statement that for numerical computations, high-level languages are much more useful in the long run than low-level languages. Let me loosely quote a researcher from Fraunhofer Institut working in numerical simulations used in weather forecasts.

In the last decade, CPUs became 1000 times faster while algorithms became 1000*1000 faster. This means, that today's algorithms running on yesterday's CPUs will beat yesterday's algorithms running on today's CPUs by a factor of 1000.

Obviously, there is much more parameters to take into account as CPU speed and algorithms, like disks or RAM, but that statement helps us to undestand that, if you choose a low-level language, you focus on the wrong factor (1000 instead of 1000*1000).

Of course, given any specific numerical algorithm one can expect C or Fortran to beat OCaml or Common Lisp by a (actually not that) large factor. But if you are actually interested in numerical problems and are willing to improve algorithms, you should then pick a high-level language that will allow you to express your ideas at a high level and to easily improve algorithms.

As a side note, if you consider writing numerical code in OCaml, you should definitely know about how OCaml pass parameters to functions, inline functions and unbox floats. All of this is detailed in Xavier Leroy's notes.

1
  • Thanks for the answer. I've since resorted to J and loving it. OCaml is a close second for me.
    – Eelvex
    Jan 9, 2014 at 19:44
5

To to solve numerically systems of differential equations you'll need first of all proper libraries. So a mandatory check is: does a programming language x support them.

Personally I like to write code higher level than C or Fortran, thus I have used Matlab, Octave, numpy\scipy.

2

I liked OCaml, at least until I looked at multi-threaded programming.

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