Programming advice for a physics major?

Click For Summary
To prepare for programming in a physics major, focus on improving your Python skills, particularly with libraries like NumPy, SciPy, and SymPy, as they are highly relevant for computational physics. MATLAB is also recommended due to its popularity in engineering and physics, with a free alternative called Freemat available for practice. While learning C++ can be beneficial for specific fields, it's generally advised to concentrate on the language most used in your courses or research group. Familiarity with multiple languages can be useful, but mastering one relevant language is often sufficient for physicists. Engaging with resources like Open Source Physics can further enhance your programming skills and understanding of simulations.
GoldenBear
Messages
12
Reaction score
0
I will be starting my undergraduate career this coming fall and was wondering how I should prepare for the programming that I will need for my studies. My first computational physics course will be in my second year, therefor I have quite a bit of time to practice my coding.

I have taken two computer science classes in high school, and have done some learning on my free time as well. I know some JavaScript, HTML, and CSS, but I spend most of my practice time writing code in Python (as I've assumed it is the most relevant language to programming for physics among the languages that I know).

I'm just wondering if it would be best to continue working on and improving my coding through the languages I already know, such as Python, or if I should spend my time learning a new language, such as C++. Any suggestions, practice tips, and/or advice is greatly appreciated!
 
Technology news on Phys.org
Well one thing you could do is get more familiar with Python using numpy, sympy and scipy.

And you could take some time to play with MATLAB. Its big in the engineering community. Many physicists here at work are masters of it.

There's a free clone called Freemat (look for v4.2) that is a pretty good with the core MATLAB functionality enough to get you started without dropping any money on MATLAB. The MATLAB student version though is $100 (its how they get you addicted to MATLAB) and is worth it if you're serious about computational aspects of physics. It can draw some nice charts with minimal effort.

Anyway, here's the freemat primer to get you started:

http://stuffle.website/references/FreematPrimerV4e1-1.pdf

There's also the Open Source Physics website www.compadre.org where you can find resources and code to build real physical simulations. They also have a book Intro to Computer Simulation by Gould, Tobochnick and Christian that has many great examples of using the software they provide.
 
  • Like
Likes GuthrJo and stoomart
I don't think it would hurt to learn some C++.
 
  • Like
Likes GuthrJo
jedishrfu said:
Well one thing you could do is get more familiar with Python using numpy, sympy and scipy.

And you could take some time to play with MATLAB. Its big in the engineering community. Many physicists here at work are masters of it.

There's a free clone called Freemat (look for v4.2) that is a pretty good with the core MATLAB functionality enough to get you started without dropping any money on MATLAB. The MATLAB student version though is $100 (its how they get you addicted to MATLAB) and is worth it if you're serious about computational aspects of physics. It can draw some nice charts with minimal effort.

Anyway, here's the freemat primer to get you started:

http://stuffle.website/references/FreematPrimerV4e1-1.pdf

There's also the Open Source Physics website www.compadre.org where you can find resources and code to build real physical simulations. They also have a book Intro to Computer Simulation by Gould, Tobochnick and Christian that has many great examples of using the software they provide.

I'll definitely look into MATLAB and www.compadre.org, thanks!
 
It would help you to be at aware of important languages like C++ and MATLAB and their general characteristics. They are very different from Python. But you should find out what language your school uses in their courses and concentrate on that language.
 
  • Like
Likes GuthrJo
Josh_Guthrie said:
I will be starting my undergraduate career this coming fall and was wondering how I should prepare for the programming that I will need for my studies. My first computational physics course will be in my second year, therefor I have quite a bit of time to practice my coding.
Good luck with your studies. As for computational physics I believe either knowing python or Matlab will be good enough for you... In fact, as a physicist, it doesn't matter which language you're using as long as it allows you to do the job.

Josh_Guthrie said:
I have taken two computer science classes in high school, and have done some learning on my free time as well. I know some JavaScript, HTML, and CSS, but I spend most of my practice time writing code in Python (as I've assumed it is the most relevant language to programming for physics among the languages that I know).
HTML and CSS are not that useful in this aspect (except for if you will need to create your homepage + modify it as you like ).
Python is amazing, since it's easy to read and write, and if you come across speed issues you can always use cython or something like this.

Josh_Guthrie said:
I'm just wondering if it would be best to continue working on and improving my coding through the languages I already know, such as Python, or if I should spend my time learning a new language, such as C++. Any suggestions, practice tips, and/or advice is greatly appreciated!
I wouldn't suggest C++ except for if you want to work with a very specific field in physics (such as particle physics) or if you want to understand a little better (or get a handle of) how memory is treated by your programs.

In fact, as a physicist knowing 1 language is good enough to allow you migrate to others, because the logic that you will need (how to turn your problems into program algorithms) is always the same, what changes is the syntax (eg the beautiful Python code, which is read like a book, vs the terrible C++ syntax) and the features of each language (eg Java works only with classes). The important for you is to learn the language that your group (or collaboration) is widely using.
 
Last edited:
  • Like
Likes GuthrJo
Many traditional modeling programs were written in fortran and are still in use today.

Some of the more popular ones have transitioned to C++ for increased flexibility and extending and improving the programs architecture.

In our lab, a mix of matlab, fortran, c++, python and java are used along with several scripting languages for glueing things together.
 
  • Like
Likes FactChecker and GuthrJo
@Josh_Guthrie: you're already doing one thing right, which is to practice solving programming problems and writing code.

You can learn things that are used by physicists (Matlab, C++, Numpy/Scipy for Python, etc.). I'm not sure how useful this is though in the long term, since they're not really going to teach you anything fundamentally new about programming and they're the sort of thing that you can just look up when you know you need them. So passing familiarity and awareness that they exist is probably enough.

If you want to broaden your perspectives on programming and you're in it for the long haul then I'd recommend learning C and Lisp. They're both historically important programming languages that have had a huge influence on other languages, and are both still in use today. They're also very different languages from each other (i.e., not just the same thing with different syntax) that you can learn different useful things from (broadly, low-level issues from C and high-level abstractions and metaprogramming from Lisp).
 
  • Like
Likes GuthrJo
jedishrfu said:
In our lab, [...] c++ and java are used [...]
I don't know why would someone "waste" work time (their time and also time for the new-comers who will handle the code later- who will have to learn how both languages work) for writing code in Java when they are already using C++ (or the other way around)... Several times I have turned against Fortran use from (new) physicists.
From a physicist perspective, the only difference I see in C++ and Java is that the last has the garbage collectors (and so you don't have to free memory with "delete"), and what I mentioned above (Java works with classes even for the simplest tasks).

Of course I am not going to say what is better or worse, a programmer must know several languages and be able to jump from the one to the other (because that's his job) and also learn new languages easily (because several appear in market each year)... My comments aim specifically for a physicist. Lisp is both bad and unnecessary in that case. C can be useful.
 
Last edited:
  • Like
Likes GuthrJo
  • #10
ChrisVer said:
My comments aim specifically for a physicist. Lisp is both bad and unnecessary in that case.

If this is directed at me then, as a physics postdoc who has found some excuses to use Lisp, I disagree. (I could make the case that the physics community as a whole has also disagreed insofar as it is adopting more Lisp-like languages like Python and Julia.)

I think you're also assuming (in this case possibly correctly and possibly not) that a physics student won't be interested in learning anything more than the bare minimum that they can immediately put to use about programming.
 
  • #11
wle said:
Lisp-like languages like Python
I wouldn't put a terrible language as lisp next to python.

wle said:
I think you're also assuming (in this case possibly correctly and possibly not) that a physics student won't be interested in learning anything more than the bare minimum that they can immediately put to use about programming.
Hmmm, no I don't believe that. I am interested in several languages myself... But it's up to an individual to decide how far they want to go in language learning and CS (another science).
A physicist though, doesn't have to know a lot of details to make their program work (or develop their code). When you aim for a specific goal though, I recommend to learn the language your group is using (in my case I had to learn python and c++, someone else might have to learn MatLab,Mathematica or Java).
 
  • #12
ChrisVer said:
I wouldn't put a terrible language as lisp next to python.

What makes you think Lisp is a terrible language?
 
  • #13
wle said:
Lisp-like languages like Python and Julia.
That is a startling statement. I have never seen a similarity between Lisp and those languages. What similarities are you referring to?
 
Last edited:
  • #14
wle said:
What makes you think Lisp is a terrible language?
parentheses... even a bash script is easier to read or write.
 
  • #15
I think that the varieties of recommendations hare has made the point that there are a lot of languages that physicists might use. That is why I would recommend asking some physics professors in your school what language they recommend. Any work you do with them will almost certainly be in their preferred, established language.
 
  • Like
Likes GuthrJo and jedishrfu
  • #16
Since this thread discussion has run its course and the OPs question has been answered, its a good time to close this thread and thank everyone for their contribution.

Take care and thank you
Jedi
 
Last edited:
  • Like
Likes jim mcnamara and GuthrJo

Similar threads

  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
Replies
16
Views
3K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 133 ·
5
Replies
133
Views
11K
  • · Replies 397 ·
14
Replies
397
Views
20K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K