Helplife2.net: Help me be a real physicist!

KiplingsCat

Space Core
Joined
Jul 15, 2009
Messages
446
Reaction score
25
So when I started my Physics course, nobody had ever told me how important it would be for me to have computer skills. Not as in being able to type and make spreadsheets; real computer skills like being able to write code. I was literally clueless as to the amount of reliance physicists had on computers. None of the computer courses offered in 1st year were compulsory, and I chose a Chemistry elective instead, which, due to my college's credit system, meant that I couldn't choose any other optional module (Most modules are worth 5 credits; 1st year Chemistry was worth 15, and my remaining 45 credits were taken up with compulsory subjects).

Any computer module I could have chosen in the following years then had these first year modules as prerequisites, essentially excluding me from taking them, as I wouldn't have had the necessary skills and would have failed. So now I'm in something of a pickle: all my lecturers expect me to have competent coding skills, but due to a combination of misinformation and academic loopholes, I have virtually none.

So my question is this: Where do I start? What languages should I learn? And does anybody know of some good online tutorials that will give me what I need? Can anybody recommend a textbook or instruction manual to me? I'm probably going to go on to do a PhD and I don't want to be the laughing stock of science.
 
Many engineering departments now use Matlab. I don't know if this is the case for physics also? Anyways, that might be a good place to start. You might have access to download it if your school has a subscription -- check their computing website; otherwise it is probably installed in the university computer labs. It is pretty easy to code in, make plots, etc. I took a class on that (and Excel, lol). This was our textbook. I never opened it. So you can probably find an equally good online tutorial, or maybe if some course out there has open resources with handouts, that could work.

Another popular one is R (which is perhaps more for statistics?). If you know Matlab, you can pick up R, or vice versa. The nice thing about R is that it's completely free, and it comes with a nice manual. Also, when assigning variables, you can write stupid crap like "i <- 2" instead of "i = 2" (yes I just drew an arrow), so you can make your code look pretty retarded if you want to.

And lastly, C and Fortran still get used in science and engineering. C is pretty easy to figure out if you know Matlab, but you need a compiler or a linux/mac. I haven't tried Fortran.

Maybe the best thing would be to ask your professor or some other students what they usually program in.

[edit] Actually I have not written C code, only modified it. On further thought, I would suggest not starting with C unless that is the standard for physics. Matlab and R are easier to use as you don't have to worry about including libraries and such.
 
Man, I've been out of college for apparently a long time - the closest thing we had to computers in that class were early varieties of programmable calculators (the TI-81 specifically). Calculus was required knowledge, but no coding. Is the coding a module of the class or used to work with data from your experiments (or something else)? It really seems like they would specify the language in the requirements unless it's just checking to see if you know your way around 'complicated' software that they'll provide for you.
 
Many engineering departments now use Matlab. I don't know if this is the case for physics also? Anyways, that might be a good place to start. You might have access to download it if your school has a subscription -- check their computing website; otherwise it is probably installed in the university computer labs. It is pretty easy to code in, make plots, etc. I took a class on that (and Excel, lol). This was our textbook. I never opened it. So you can probably find an equally good online tutorial, or maybe if some course out there has open resources with handouts, that could work.

Another popular one is R (which is perhaps more for statistics?). If you know Matlab, you can pick up R, or vice versa. The nice thing about R is that it's completely free, and it comes with a nice manual. Also, when assigning variables, you can write stupid crap like "i <- 2" instead of "i = 2" (yes I just drew an arrow), so you can make your code look pretty retarded if you want to.

And lastly, C and Fortran still get used in science and engineering. C is pretty easy to figure out if you know Matlab, but you need a compiler or a linux/mac. I haven't tried Fortran.

Maybe the best thing would be to ask your professor or some other students what they usually program in.

[edit] Actually I have not written C code, only modified it. On further thought, I would suggest not starting with C unless that is the standard for physics. Matlab and R are easier to use as you don't have to worry about including libraries and such.

Ah, Matlab I do slightly know! Now that I think of it, I took a rather haphazard course in it in my second year. It was taught by this very dense academic type who couldn't understand the merits of learning the basics before you dive into the heavy stuff...he set me a coding project on a really difficult condensed matter problem...a subject which we don't learn anything about til third year, so understandably I was confused and terrified, and didn't really learn any actual code. Plus it was assumed that we were all competent in C++ already. I don't know why that was assumed. But maybe if I go back to it myself I can get what I need from it. It's very widely used in college.

I've only ever heard horror stories about Fortran. In my lab, I work with an imaging program that was written in the 70s with Fortran, and never updated since. It's completely unreliable and unhinged, and is all I feel I need to know about Fortran; I'm an observationalist as opposed to a theorist, so I'll never have to actually fiddle with the mechanics of it, I just have to use it.

I suppose C and C++ are what I'd ultimately like to learn. I have a mac already so that won't be a problem. But maybe if I try to go back to Matlab stuff will come back to me and I'll get a bit more comfortable. I've never heard of R! I'll check it out for sure though, sounds interesting.

Thanks!

Is the coding a module of the class or used to work with data from your experiments (or something else)? It really seems like they would specify the language in the requirements unless it's just checking to see if you know your way around 'complicated' software that they'll provide for you.

We do a lot of independent research in our final year. Though not specifically required for some projects, programming skills are usually helpful no matter what you're doing...it just gives you an extra degree of freedom, if you'll forgive the unintentional pun. For some homework problems we need to use Mathematica or something similar, which I have never learned...they just kind of assume that we'd have picked it up by now somehow, or else don't know that not all of us have taken a course in it. (I usually fall back on cumbersome excel spreadsheets for these problems...it's ugly and inconvenient but it works).

So really, there are no specific "requirements"...just problems that we need to solve, or data that we need to collect, and it's left up to us to decide how we do these things. Up until now, I've avoided using programming to do this stuff for me, or had people help me, but I'm beginning to feel rather behind my classmates and my possible future colleagues.
 
I didn't have the same physics track as my (non-conputer) engineering roomates, but the one constant was Matlab, I remember. C is always good to know for learning rock-hard fundamentals. One of my engy buddies who works in aerospace now writes Java, which takes the manual memory mangement out of the equation and was my primary learning language in college. You could go either way, but coming out with the basic tools to create structures for your data and the procedures for processing them would be a very good and achievable goal.
 
Basically what Mutoid said. C, C++, Java. Most application-specific scripts and purpose-built languages I've encountered employ syntax that's derivative of those (yes I know they're derivative of each other, code history purists, but she wanted basic info). If you can get through those you can adapt to most other languages pretty quickly.
 
I recommend C++ and Python. At higher levels, you will find most physicists writing their simulations in C++ for its efficiencies, and using python as a handle for these simulations. Python is also great for plotting through matplotlib. You will probably also want to learn LaTeX if you are wanting to write up your results in a half-presentable way, not so much a programming language but equally invaluable, every single published paper is written with it.

In saying that, Matlab is straightforward, quick and dirty if you just need something to plot and handle arrays. Since you want to do a PhD though I would recommend going for the big guns above.

The way I learned python was through "Google Code University" which has both written instructions and videos that should lead you straight in if you know the basics like what "=" does and what a for loop is.

You'll also want Linux on your system, not sure if that's obvious or not. Which means you'll want to learn the very basics of bash.
 
You're an astrophysicist too, right? Familiar with AIPS by any chance?
 
The book my school uses for MatLab is pretty good, and it is very accessible if you read everything he writes. Joseph Musto (main co-author and professor at my school) is kind of an asshole, but Engineering Computations: an Introduction Using MatLab and Excel is a good one for learning MatLab. For more complex stuff in C or C++, you have got me; I'm a mechanical engineering major.
 
I know the physics majors at my school use primarily MATLAB and C/C++.

They require all engineers to take a programming class that covers basic C and MATLAB, plus a bit of c++.

Don't know when I'll use C for chemical engineering, but hey, gotta do what you gotta do I guess.
 
They require all engineers to take a programming class that covers basic C and MATLAB, plus a bit of c++

See this is what I needed; someone to just make me do it. Because then at least I wouldn't find it so intimidating. But I'd forgotten Matlab, which I did once slightly know...in fact I seem to remember being fairly handy at it as long as I understood the physics that was going on behind it. So I'll probably start with that and then migrate to C or C++.
 
Matlab is frickin' expensive, so that means if you want a personal copy, you pretty much have to pirate it. Python is free, and more powerful, and faster at most things than Matlab. It feels more like a programming language though which can be good or bad. Running Python with Numpy (mathematics package) in the DrPython editor is basically the same as Matlab. Almost all grad students in know in physics use Python. I hear Octave is good too, but I don't know anybody who uses it. If you are really absolutely new to programming. "Learn Python the Hard Way" is a long but easy to follow set of step by step tutorials that really walks you through everything.

Also learn to use LaTeX right away. Don't write anything technical in Word, it will seem harder at first, but is magnitudes easier in the long run. (Just don't expect it to put your figures exactly where you want them. Accept that you are wrong and LaTex is right)

Get a good handle on a robust plotting package. I recommend Gnuplot because it's free and it's what I use and it gives you complete control over everything (that makes it powerful and frustrating at the same time). If you can spin off a set of professional looking plots quickly, you can analyse data faster and get ideas across in meetings, not too mention, when you plot from a script rather than a visual interface, you can quickly make changes across a set of plots.

Lastly, because I don't remember much of first year calculus, I do most of my math that you're supposed to do by hand in Maxima, the free equivalent to Mathematica.
 
I wasn't aware there was a free equivalent to Mathematica, thanks for that! I've had Octave recommended to me by some postgrads in my lab so I'll probably give that a try...but I've heard good things about Python too and know a few people who use it.

Yeah I've downloaded LaTex but it's WEIRD....probably going to have to put together my final year project report with it though, so I'm going to have to get used to it soon.
 
There are a lot of guides to LaTeX out there. Report writing is pretty much a cinch though. You just write the text of what you want to write and pepper in a few bits of code to handle the sections or figures or equations. If you are juggling a lot of references for your bibliography, I highly recommend pairing it up with BibTeX for handling your bibliography and JabRef to handle your BibTeX file.
 
^^Is BibTeX better than EndNote, and can it sync up to Word? Everyone I know here writes and submits their articles in Word (and I have never seen a formatted article sent out for peer review). So for the sake of being argumentative, I don't consider LaTex to be a necessity. However, EndNote sucks. They don't even provide properly formatted reference lists for the journals we submit to.

Anyways, I still stand by using whatever your prof will use in the class. If you're provided example code in say Matlab, for starters you'll want to be able to actually run it, and it just makes it a little more difficult to do your homework if you're using a different language.
 
^^Is BibTeX better than EndNote, and can it sync up to Word? Everyone I know here writes and submits their articles in Word (and I have never seen a formatted article sent out for peer review). So for the sake of being argumentative, I don't consider LaTex to be a necessity. However, EndNote sucks. They don't even provide properly formatted reference lists for the journals we submit to.

BibTeX as the name implies is a package for LaTeX. It's database file is probably compatible with EndNote I would imagine. So if you have a database of EndNote references, I bet there is some option to export them to a .bib file. I have never used EndNote, so I can't say how well it works, but to get an idea of the ubiquity of LaTeX and BibTeX in academia, Google Scholar has an option to produce BibTeX entries for all of its search results. Most journal databases also have this option. Just copy and paste the BibTeX formated entry into your BibTeX .bib file or into your frontend database manager (that's what JabRef is for) and you have that reference saved. You can cite it in your work, and then simply apply whatever bibliography and citation style you want at the end. Someone has made a BibTeX style for pretty much every journal and style there is.

So for example, every time I come across a paper that I think is relevant to my work, I paste the BibTeX reference into JabRef which is just a program to manage the .bib files. You can also edit with notepad. Eventually this file has hundreds of entries, but when I write a paper, I just cite the papers I want to cite in the body, and then write one line to point BibTeX to the relevant .bib database that has all those references, and another line to tell it what style file to use and it formats all of the citations and bibliography using only the references I have cited.

If you look up LaTeX vs Word you will find hundreds of articles championing LaTeX for publishing professional looking documents and almost none in favour of Word. It's a tiny bit harder to start using, but everyone who uses it is happier in the long run.
 
How can I learn code from NOTHING? I took a coding class in high school and even there they expected that I'd already done a lot of coding my entire childhood in the basement or something.

Serious replies for a serious question.
 
Depending on the language you choose, there are a huge number of absolute beginners guides. Most of them teach by having you write example codes to understand how everything works.
 
How can I learn code from NOTHING? I took a coding class in high school and even there they expected that I'd already done a lot of coding my entire childhood in the basement or something.

I know, right? It's crazy! They just presume we know all this stuff already. Even in the Matlab class I took in 2nd year, they assumed we knew it already. HOW WOULD I KNOW A THING LIKE THAT ALREADY?
 
I'm not sure why Physics majors would need to code. Wouldn't programs be made for their needs by say, ex-computer science majors? Why you would need to make programs yourself for whatever calculations you need is beyond me. Surely everyone's needs are around the same?
 
It's because grad students are cheaper than ex-computer science majors.

just kidding............. or am I


BibTeX as the name implies is a package for LaTeX. It's database file is probably compatible with EndNote I would imagine. So if you have a database of EndNote references, I bet there is some option to export them to a .bib file. I have never used EndNote, so I can't say how well it works, but to get an idea of the ubiquity of LaTeX and BibTeX in academia, Google Scholar has an option to produce BibTeX entries for all of its search results. Most journal databases also have this option. Just copy and paste the BibTeX formated entry into your BibTeX .bib file or into your frontend database manager (that's what JabRef is for) and you have that reference saved. You can cite it in your work, and then simply apply whatever bibliography and citation style you want at the end. Someone has made a BibTeX style for pretty much every journal and style there is.

Thanks, that is really good to know. I vaguely remember noticing the BibTeX export option, but never bothered to try cross-syncing. I should do that next time. As for the LaTeX vs. Word formatting, I know Word looks like crap in comparison -- I just meant that in most scenarios, crap formatting is acceptable :p. But I concede that I'm definitely interested in trying LaTeX now, just based on the whole referencing business.
 
I'm not sure why Physics majors would need to code. Wouldn't programs be made for their needs by say, ex-computer science majors? Why you would need to make programs yourself for whatever calculations you need is beyond me. Surely everyone's needs are around the same?

I would guess that most physics coding projects have something to do with numerical simulation or optimization or data processing. Even if you can formulate some useful theory just using a chalkboard, figuring out the repercussions of that theory probably involves some kind of simulation. Suppose you want to create a simulation of how galaxies collide, or how they form, or figure out how confident that your particle detector hits are actually particle detector hits. Nobody has software packages built for new research, because it's new research. And coding it yourself gives you a better understanding and more control over what's happening. And it's cheaper.
 
I'm not sure why Physics majors would need to code. Wouldn't programs be made for their needs by say, ex-computer science majors? Why you would need to make programs yourself for whatever calculations you need is beyond me. Surely everyone's needs are around the same?

Everybody's needs tend to be quite different actually. It's also just a really handy skill to have. For example, I use an astronomical imaging program that was made by computer-scientists/astrophysicists that should in theory take care of my needs, as you suggest. But it's glitchy and old and doesn't always do what you want it to do. So even just some knowledge of how it works would be useful. And then there's the whole issue of whether or not you can believe the output of a code that was written 30 years ago and has never really been put to the test (2 of the Phds in my lab are investigating this; most of their work involves writing code).

What I do involves manipulating hundreds and hundreds of data files in a very repetitive way, so obviously the ability to properly write script for the program I use would be handy...what I'm doing is so specific that nobody else would have written a program that could deal with it exactly; at the moment, I'm using somebody else's script that we tweaked slightly to suit my needs better. A non astrophysicist-computer-scientist definitely couldn't have done it for us, for one thing, they wouldn't have sufficient knowledge of astrophysics, and for another, they wouldn't know enough about the program itself.

Of course, my research would be considered to be relatively free of coding since it's mainly observational. My boyfriend, for example, favours theoretical quantum physics, which is all coding, since he has to run simulations of many different situations. The code he writes would have to be written by a physicist; a computer scientist alone probably wouldn't have sufficient knowledge of quantum physics to do it, unless they were into that sort of thing.
 
I guess that makes sense. A lot of it tbh.

But I am glad that I am not a physics major, because that seems like a lot of work to do. You have to do experiments, listen to lectures, read your textbooks, and than code programs to fit your research? Economics only requires a pen, paper, and a TI-89. :p
 
It gets better, but in the meantime you are using AIPS, which runs on magic. Good luck!

Actually it is a well established program that I found not to be glitchy so much as plain old fashioned. I can assure you though that your outputs are certainly accurate so long as you are giving it the right inputs. If you don't know what the right inputs are, read more textbooks. Don't bother fiddling around with the code until you really understand what you are doing. I made that mistake and it just leads to wasted hours and less certainty that you got a true result. I know it can be tempting to dive in so that you have something to show, but try to resist the temptation. You can show that you have been working by writing down what you are learning as you go, and that also comes in handy when you write a thesis at the end.

Since you are using AIPS, programs like C++ and Python start to become a little bit less relevant, but still worth learning if you have the time.
 
It gets better, but in the meantime you are using AIPS, which runs on magic. Good luck!

You know things are bad when, if something doesn't work, your strategy is to go home for the weekend and try again on Monday. As for the data being believable; that's not really something I concern myself with (I mainly just want my TVServer not to disappear) but some people in my lab are interested in finding out. Not that they think AIPS is making mistakes or anything, they just want to know if that's the best way of doing it. It's interesting, but I prefer observational stuff.
 
Back
Top