Skip to main content

Getting Started with Programming

  • Chapter
  • First Online:
Elementary Mechanics Using Matlab

Part of the book series: Undergraduate Lecture Notes in Physics ((ULNP))

  • 114k Accesses

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.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 49.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 64.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info
Hardcover Book
USD 64.99
Price excludes VAT (USA)
  • Durable hardcover edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 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. 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. 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. 4.

    http://folk.uio.no/malthe/mechbook/100m.d

  5. 5.

    http://folk.uio.no/malthe/mechbook/trajectory.dat

  6. 6.

    http://folk.uio.no/malthe/mechbook/velocityy.dat

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Anders Malthe-Sorenssen .

Rights and permissions

Reprints 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

Publish with us

Policies and ethics