Abstract
This chapter provides a rapid introduction to the basic skills needed in matlab programming in the context of basic physics. We introduce matlab as an advanced, programmable calculator. You learn to write and execute scripts and functions. We introduce how to represent data as vectors and how to plot data-sets and functions. Loop-structures including for and while loops are explained. Simple vectorization is explained, and we show the strong similarity between the mathematical notation and the implementation in matlab. We also introduce random numbers and conditional statements and use this to generate random walkers. Finally, we show how to read and plot real data as found on NASA servers.
Keywords
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
In matlab it is not necessary to define the size of the array before it is filled. We could just fill it as we go along, but this is not good coding practice, it will lead to very slow codes for large arrays, and may cause surprising errors in your programs. We will therefore always predefine the size of arrays.
- 2.
Notice the small difference between the two methods: Using linspace ensures that the first and the last numbers are included in the list, but when you use (0:0.3:10.0) the last number is 9.9 and not 10.0!
- 3.
But sometimes you may by accident succeed in doing a matrix multiplication, and you may get rather surprising errors. This is a type of error that may be difficult to track down.
- 4.
- 5.
- 6.
Author information
Authors and Affiliations
Corresponding author
Rights and permissions
Copyright information
© 2015 Springer International Publishing Switzerland
About this chapter
Cite this chapter
Malthe-Sorenssen, A. (2015). Getting Started with Programming. In: Elementary Mechanics Using Matlab. Undergraduate Lecture Notes in Physics. Springer, Cham. https://doi.org/10.1007/978-3-319-19587-2_2
Download citation
DOI: https://doi.org/10.1007/978-3-319-19587-2_2
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-319-19586-5
Online ISBN: 978-3-319-19587-2
eBook Packages: Physics and AstronomyPhysics and Astronomy (R0)