I am wondering if this is the right place to ask this question. I found a related question on stack overflow https://stackoverflow.com/questions/814312/physics-in-computer-science but it was closed. So I am asking my question on SE Physics.

I am planning to study graduate level computational physics study. For example, it involves programming to solve problems in linear algebra, PDEs, ODEs (more specific examples are finite volume, finite element, iterative methods to solve nonlinear equations). I am mechanical engineering major student with basic programming knowledge. During my ME coursework, I didn't program heavily. I just took a look at the undergraduate CS degree curriculum, and found that I do not know most of the CS stuff - algorithms, theory of computer science, parallel computing, etc. This knowledge may be vital in programming efficiently - in terms of human time spent on programming. I am feeling that a CS major student can far easily program and debug; something that can take hours for a beginner physics student without CS or computer engineering knowledge.

I am confused how a ME major student can undertake computational physics study without CS or computer engineering background. Is knowledge of a programming language enough? Can anyone comment here? Thanks in advance.

  • 2
    $\begingroup$ Yes, you need to know how to program. That's more than just having theoretical knowledge about programming language -- being able to program requires practice. $\endgroup$ Commented Dec 21, 2016 at 12:02
  • $\begingroup$ During my graduate school (finishing in a year or so) in computational sciences I've witnessed a few dropouts. The most common reason is that the student could not perform the required programming tasks. On the other hand, most of the people that finish have had programming as a hobby from high school or even before that. If you are up for the task of learning to write code while learning computational sciences, please go for it, but it will be tough. I'd advise you to immediately enroll some online programming course and really take your time to look into the details. $\endgroup$
    – knl
    Commented Dec 23, 2016 at 9:55

3 Answers 3


I had basically no programming experience (except for a one semester class I took in first year - Octave) when I started solving problems in computational physics (it was basic quantum mechanics), as part of my Honours year coursework. In the first week of learning how to code in FORTRAN, we did trivial things, like formatting text for printing, and compiling source code contained in one file. In the second week, we solved the 1D Schrodinger equation using a shooting method. By the fourth week, we were coding the Numerov-Cooley method, and it was a few weeks later (this was a half-semester course), after a few more assignments, that we were propagating a Gaussian wave packet. The math involved was a little tricky at first, but it was the programming which made life very difficult for the uninitiated.

It was about the fifth week when I learnt about options to see helpful error messages when compiling my programs! You mean you know which array reference is out of bounds, and you haven't been telling me? I was livid that this had not been considered important enough for the lecture slides.

Anyhow, enough about me, and my hopelessly inefficient 80 hour coding weeks which were required to ace that course... the point is that you don't want to go through what I went through, and you don't have to. Here are the lessons, in order of importance:

1) Don't bother with FORTRAN or C as your first language, if you're trying to solve mathematical problems. These languages (especially C) will only slow you down in reaching your short term goal of completing a scientific computing course. Instead, learn a language which is designed to help you write useful code faster (Python is ideal, but Octave and Matlab have their advantages too). With Python and the appropriate modules installed (mainly just numpy), you'll have no problems performing "simple" tasks like reading data files into arrays, sorting the data, and subjecting it to standard linear algebra operations. In FORTRAN, on the contrary, you're likely to give up trying to write your own parser for input files, or smash the keyboard after getting every one of the ten thousand arguments to a LAPACK routine incorrect. C is better to learn than FORTRAN, but in your case, it will only make writing numerical routines more frustrating, as well as looking much uglier in your text editor (C is a horrendously ugly language - at least FORTRAN code looks a bit like math on the page).

2) Ask for help early, regularly, and online. Don't allow simple, idiosyncratic tricks of the trade to waste all your free time. It's OK that you don't know that stuff; it's unintuitive.

3) If you can't debug the code in time, don't destroy it with hacks and arbitrary "bug fixes". Submit your concise pseudo code, along with the source code, and provide a clear writeup of the problems. Sometimes, only time and a clear head will help, while at other times (equally often when you're first learning) you just need the help of someone more experienced.

4) Get your math right before you start planning your code. Algorithms are understood on paper by humans, and then taught to computers via programming languages. If you get the algorithm wrong, you'll never be able to find the bug, because it doesn't actually exist (you just coded the wrong algorithm, correctly).

5) Forget about parallel computing, until you've "mastered" writing programs for one processor. Most computational scientists just lean on the expertise of colleagues here.

In summary: learn Python as quickly as possible, and try using numpy to solve linear algebra problems. Use of a language like Python will make your life a million times easier.


You are correct that with respect to the software side of things, it's possible a typical CS student who has programmed a lot in their undergrad could perform much quicker than someone with basic programming experience. They may not have the solid physics background you could, though, so obviously both sides have their weaknesses with respect to computational physics.

The thing about getting involved in computational science is not only do you need to have a strong footing in the actual science, but you ideally would have sufficiently strong software and algorithmic abilities. As Wolfgang mentions in the comments, a big part of this is just practice. Things like data structures is a useful topic to study as well provided you have the time, but you could get away with a basic understanding of what each data structure is best used for and just use the data structure implementations that come along with language libraries.

At the end of the day, the most beneficial thing you could probably start doing is trying to get a lot of practice programming with whatever language(s) you expect you might use. I would probably recommend looking into Fortran or C, maybe C++ after you understand the basics of C.

I would also recommend getting a book or two to not just help with learning the languages, but learning to build good software. Some books that come to mind are API Design in C++ and Clean Code. Note that API Design in C++ actually teaches a lot of language independent keys to building good software, so this is useful whether you use C++ or not. I stress developing this background because without it, you may end up building codes that are hard to maintain, that are buggy, and in turn result in lots of lost time in the long run. Taking the effort to build something clean and modular can really save time in the long run even if you put up a little more effort up front.

After you have these fundamentals down, then you should investigate more advanced topics like parallel computing.


A typical computational physics class will have a modest expectation on the students' abilities to program. The physics curriculum often covers only basic programming. From the "coding" point of view, you should not worry that much.

If you are worried anyway, consider following a tutorial online where the language is the one used in your planned class.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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