One of the misunderstandings that students have when they are learning computational science is that students don’t grasp how powerful programming languages are at calculating large sets of data.

One of the problems I often run across with Matlab in my Physics I class. If I ask students to plot a function, such as y(x) = x2 + 5x or to find the slope. Novice students will calculate the values directly with their calculator and put it into a table. (This one was easy, I didn’t even need the calculator.)

So then the students manually type the information into Matlab. For example:

x = [0 1 2 3]
y = [0 6 14 24]

plot (x,y)

This completely works. But it doesn’t scale. For example, if I ask you to do the same plot with a 100 points from 0 to 5, are you going to sit there and calculate each point in your calculator? You could. And it would work. But (1) You might make a mistake. That’s a lot of points. Mistakes will happen. (2) It would take an annoying amount of time.

Just let Matlab do all the work for you. It is so fast and perfect!

x = 0:0.01:5;    
y = x.^2 + 5 * x

plot (x,y)

Line 1 builds an object with a shit ton of boxes in it. The first box has the value of 0. The second box has the value of 0.01. The third box 0.02, the fourth box 0.03, all the way up until you get to 5.

Line 2 then calculates the equation for y, creating a box for each value of x.

Boom done. Calculator time = 0!

Posted in

Leave a Reply


Cosmic Pathways, Lab for Kids, and many of the other research activities discussed on this website is supported by the National Science Foundation and the Physics Teacher Education Coalition (PhysTEC) under grant no. 2325980. Any opinions, findings, and conclusions, or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation.

Discover more from Cosmic Pathways

Subscribe now to keep reading and get access to the full archive.

Continue reading