Programming advice for a physics major?

In summary: But, if you're mainly interested in programming for physics, then learning Python is the best way to go.
  • #1
GoldenBear
12
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
  • #2
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
  • #3
I don't think it would hurt to learn some C++.
 
  • Like
Likes GuthrJo
  • #4
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!
 
  • #5
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
  • #6
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
  • #7
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
  • #8
@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
  • #9
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

1. What programming languages should I learn as a physics major?

As a physics major, it is important to have a strong foundation in at least one high-level programming language, such as Python or MATLAB. These languages are commonly used in physics research and have a variety of mathematical and scientific libraries that can assist in data analysis and modeling. It is also beneficial to have some familiarity with lower-level languages, such as C++, as they are often used in computational physics and numerical simulations.

2. How can programming skills benefit me as a physics major?

Programming skills are becoming increasingly important in the field of physics. They can help you analyze and visualize complex data, perform simulations and calculations, and automate repetitive tasks. In addition, having programming skills can make you more competitive in the job market and open up opportunities in fields such as data science and software development.

3. Do I need to be a computer expert to learn programming as a physics major?

No, you do not need to be a computer expert to learn programming as a physics major. While some background in computer science may be helpful, most physics programs offer introductory courses in programming that assume no prior knowledge. With dedication and practice, anyone can learn to code and apply it to their physics studies.

4. Are there any resources or tools specifically for physics majors learning programming?

Yes, there are resources specifically designed for physics majors learning programming. Some websites, such as Codeacademy and Coursera, offer free online courses in programming for beginners. Additionally, there are textbooks and tutorials that focus on using programming languages for physics applications, such as "Computational Physics" by Mark Newman and "Python for Data Science and Computational Science" by Hans Fangohr.

5. How much time should I dedicate to learning programming as a physics major?

The amount of time you should dedicate to learning programming as a physics major depends on your goals and the level of proficiency you want to achieve. It is recommended to start with a few hours per week and gradually increase as you become more comfortable with the language. It is also important to practice regularly and apply programming to your physics studies to reinforce your skills.

Similar threads

  • Programming and Computer Science
Replies
8
Views
878
  • Programming and Computer Science
Replies
16
Views
1K
  • Programming and Computer Science
Replies
11
Views
1K
  • Programming and Computer Science
4
Replies
107
Views
5K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
9
Views
1K
  • Programming and Computer Science
Replies
7
Views
478
  • Programming and Computer Science
12
Replies
397
Views
13K
  • Programming and Computer Science
Replies
15
Views
1K
  • Programming and Computer Science
Replies
3
Views
1K
Back
Top