Programming Struggles for Physics Majors: Ideas to Cope

In summary, programming can be challenging for those who are not used to thinking in terms of state and flow control. It is a skill that is necessary for any physics major, whether you end up as a theorist or experimentalist. The best way to improve is to practice and ask for help from your TA or professor if needed. It may also be helpful to learn a simpler language like Python before tackling MATLAB assignments. Don't be discouraged by mistakes, as they are a natural part of the learning process. Remember that many people struggle with programming at first, and with practice and determination, you can improve.
  • #1
Mulz
124
5
I'm not sure what to do, I keep on struggling with the MATLAB assigments and I'm a physics major. Any ideas on how to cope with this? Didn't really expect to be doing this much programming, and I do not like it.
 
  • Like
Likes Delong
Physics news on Phys.org
  • #2
You don't need to cope with it, you need to get better at it. Whether you end up as a theorist or experimentalist, programming is a skill that is necessary. Unfortunately, you get better at programming by doing, so maybe try some practice exercises beyond what you do for class. If you don't understand the logic, maybe ask the TA or professor in your class to walk you through a program.
 
  • Like
Likes Dr. Courtney and symbolipoint
  • #3
Mulz said:
I'm not sure what to do, I keep on struggling with the MATLAB assigments and I'm a physics major. Any ideas on how to cope with this? Didn't really expect to be doing this much programming, and I do not like it.
Is this the first time you've done any programming? Or have you done some programming in C or Perl or some other language before? Have you had any introductory programming classes yet, going over things like data structures, I/O, pointers, etc.?
 
  • #4
Have you taken (or: are you taking) a course on linear algebra or another course featuring matrices? The primary data type in MATLAB is the matrix, so it helps when you are familiar with the very basics such as indexing, matrix and vector addition and multiplication, transposition, the dot product etc.

Compared to e.g. C or Fortran, MATLAB is very forgiving and not difficult to learn if you are comfortable with the matrix structure. It may even become fun :smile:.
 
  • Like
Likes Student100 and berkeman
  • #5
Don't let 2 things come crashing on you. When I do octave/matlab I suffer from 2 things bellow.
1-Programming syntax and stuff (loops and stuff)
2-Extensive functions and data structure.

How you can deal with it, forget about your academic requirement, learn a sweet and nice language, like python.
everyday python at courasra dot org. Play with it .. enjoy it.

Then go back to matlab. so you only have to deal with 2.
 
  • #6
Hey Mulz.

You should probably tell us what the problem is so we can discuss it in more detail.

There could be any number of reasons why you are finding something difficult and could range from a slight "misunderstanding" to a big conceptual difficulty.

Let us know what it is so the forum can discuss it further.
 
  • Like
Likes S.G. Janssens
  • #7
chiro said:
Hey Mulz.

You should probably tell us what the problem is so we can discuss it in more detail.

There could be any number of reasons why you are finding something difficult and could range from a slight "misunderstanding" to a big conceptual difficulty.

Let us know what it is so the forum can discuss it further.

It's usually problem solving questions that tend to bother me. It is difficult to explain it but simply put I have a difficult time solving questions such as:

1) Write a function min2(x,y) that takes two numbers x and y as in parameter and returns the lowest of them. If the numbers are equal the function will return any of them. Use the function definition to start with:

function out = min2(x,y)
%MIN2 Returns the smallest of two numbers
__________________________
Now this was only one example of a question I simply have trouble understanding. I did solve it with the help of my class mates but I would like to be able to solve MATLAB problems by myself, something I tend to struggle with. I usually understand the question, but not how the structure of the script should look like, like where am I supposed to use ex. a for loop and how do I explain a solution with the help of programming.

What should I do? I understand mathematics easily but for some reason programming doesn't work for me, I'm below average in terms of intelligence so that should explain it?
 
  • #8
Whenever you encounter a problem that needs to be programmed, start with the naive solution. How would you do it by hand? Write it out step by step. If you are doing something over and over again then that may apply to a loop of some sort. There really is no way to get good at programming besides just programming. As you become familiar with the syntax and idioms within a language, the more adventurous you'll feel and the more complicated programs you can write.

Anyway, here are some tips that help me.
1. Don't immediately try to program an answer, take time to understand the problem and figure out how to do it by hand.
2. Don't be afraid to make mistakes. Programs are easy to change, so if you're not sure how something works, try it out and see for yourself.
3. In matlab, most things are done via vector type of operations, so be sure you are using the create arithmetic operator.
4. Understand that most people struggle initially with programming, so you're not alone.
 
  • #9
In programming there are two main things - state of the machine and flow control.

In mathematics, you typically don't define the state as explicitly which is why it can be confusing for mathematicians to understand code.

In a procedural computer program you start with an initial state and you somehow need to take that [initial state] and get to a destination state.

In a mathematical problem, you start with information and find a way to transform and combine it so that you get an answer that is consistent with everything you started with and provides the solution to your problem.

In a programming problem, you do the same thing but you use a different language to do the same thing.

Instead of going from a set of mathematical relations to a final set of relations that are consistent with what is given initially, you go from a memory state [which is a collection of "bits" arranged into data structures] to a final memory state [which again is a collection of bits arranged into data structures that are modified versions of the "original" or new ones derived from the "original" state].

The difference between the two is the language and in procedural programming, you are dealing with a flow-chart that deals with things based on organizing bits instead of mathematical structures like real numbers or rational numbers.

It might help you to think about stuff represented as a flow-chart and then to bridge the mathematics to computer code through the help of that flow-chart and how the information is represented inside a computer by a data variable or even by its binary representation in memory.

For MATLAB, you won't have to worry about the binary representation [which is good for you] but if you can get the flow-chart intuition then over time it will get easier to convert that to actual computer code that you can both write and evaluate.
 

1. What are some common struggles that physics majors face when learning programming?

Some common struggles that physics majors face when learning programming include understanding the syntax and logic of programming languages, debugging errors, and implementing algorithms and data structures in their code.

2. How can physics majors cope with these programming struggles?

Physics majors can cope with programming struggles by seeking out resources such as online tutorials, coding bootcamps, and peer support groups. They can also practice regularly and break down complex problems into smaller, more manageable tasks.

3. Are there any specific programming languages that physics majors should focus on?

While there are no specific programming languages that physics majors should focus on, some commonly used languages in physics research include Python, C++, and Fortran. It may also be beneficial to learn programming languages commonly used in data analysis and visualization, such as R and MATLAB.

4. How important is programming for a career in physics?

Programming is becoming increasingly important in the field of physics. Many research projects and experiments rely on data analysis and simulation, which require programming skills. Having a strong foundation in programming can also make physics majors more competitive in the job market.

5. Are there any tips for physics majors to improve their programming skills?

Some tips for physics majors to improve their programming skills include practicing regularly, seeking out real-world applications, and working on collaborative projects with other students. It can also be helpful to take courses or attend workshops specifically focused on programming for physics.

Similar threads

  • STEM Academic Advising
Replies
22
Views
2K
  • STEM Academic Advising
Replies
10
Views
1K
  • STEM Academic Advising
Replies
7
Views
1K
Replies
40
Views
2K
  • STEM Academic Advising
Replies
3
Views
442
  • STEM Academic Advising
Replies
4
Views
210
  • STEM Academic Advising
Replies
19
Views
1K
  • STEM Academic Advising
Replies
1
Views
470
  • STEM Academic Advising
Replies
21
Views
2K
Replies
6
Views
962
Back
Top