MATLAB Skills for Physics


Physics 290, Spring 2011
Regener Hall, Rm 118

Instructor: STP Boyd, stpboyd@unm.edu, Office Hours: after class in Regener Hall 118 and by appointment
TA: Kyle Martin, kmartin1@unm.edu, Office Hours: Thursdays 10am-12 noon, Physics Department Lobby

Week Monday Wednesday Friday
1 Holiday

1/19: Class 01

  • Getting Started

Notes
Movie

1/21: Class 02

in-class lab: making and plotting vectors

Lab 1 Problems / Lab 1 Solutions
HW01 problems / HW01 solutions

2

1/24: Class 03
Movie
class03_ex.html



1/26: Class 04

  • From vectors to matrices
  • meshgrid
  • surf
  • develop kinematic eqs in MuPad
  • implement kinematic eqs in a MATLAB function

Notes
Movie
MATLAB exercise
MuPad exercise

1/28: Class 05

Lab/HW: Electrostatic Potential

Lab2/HW2

Lab2 Solutions

last day to add courses or change sections

3

1/31: Class 06

Number Formatting, sprintf and fprintf, Debugging Functions, Basic Subscripting

Movie
Notes
class06_ex.html
HW03

HW03 Solutions

2/2: Snow Day

 

2/4: Snow Day

Last day to drop a course without a grade

4

2/7: Class 07

Subscripting, Indexing, Logical Indexing, Part I

Movie
Notes
class07_ex.html

2/9: Class 08

Subscripting, Indexing, Logical Indexing, Part II

Movie
see Class 07 for notes
class08_ex.html

2/11: Class 09

Lab 3: Image and Function Manipulation Using Subscripting and Indexing

Lab 3 Solutions

Last day to change grading options

5

2/14: Class 10

MuPad Basics 1

  • Clear the workspace
  • Assignment
  • Equality, Equations
  • Simple Plotting
  • Finding Roots with "solve"
  • Differentiation

Movie
Class10.html

2/16: Class 11

MuPad Basics 2:

  • Representation
  • Accuracy
  • Functions versus Expressions
  • Substitution and Evaluation
  • GUI Plotting Tools
  • Units

Movie
Class11.html

2/18: Class 12

Lab 4: plots and animation in MuPad
Lab 4 solutions (MuPad file, can see animations)
Lab 4 solutions as html (don't need to open MuPad)

6

2/21: Class 13

MuPad Basics 3:

making assumptions

Movie
Class13.html

2/23: Class 14

  • From Solving Equations to Linear Algebra

MuPad Exercise

No Movie due to laptop meltdown

2/25: Class 15

  • Understanding Linear Algebra as N-dimensional Mapping

MuPad Exercise
MATLAB Exercise

No Movie due to annoying technical problems

7

2/28: Class 16

  • Finishing Up Linear Algebra in MuPad and MATLAB

Movie
MuPad Exercise
MATLAB Exercise

3/2: Class 17

  • Basic Dynamics: ODE IVP in MuPad/MATLAB
  • Prof. Boyd Eats it Setting Up the Simplest Possible ODE

Movie
MuPad Exercise
MATLAB Exercise

3/5: Class 18

  • Magic Rule: RTFM
  • Solving the ODE IVP for the Simple Harmonic Oscillator
  • Using Conservation of Energy to Assess Performance
  • Comparing the Seven Different ODE Integrators

Movie
MATLAB Exercise

8

3/7: Class 19

  • Developing a Gravitational N-Body ODE IVP Solver using Element-by-Element Math

Function List (Study Guide for Midterm)
Movie
MuPad Exercise
MATLAB Exercise

3/9: Class 20

  • Coding the Gravitational N-Body ODE IVP Solver in MATLAB

homework04_matlab.zip (due before class on 3/21)
homework04 solutions

Movie
n_body_derivs.m
Nbodyderivs_development.m

3/11: Class 21

Lab 5: 2-Body Gravitation

lab5 problems (due before class on 3/25)

9 3/14 Spring Break 3/16 Spring Break 3/18 Spring Break
10

3/21: Class 22: MATLAB Nuts and Bolts

  • Creating Arrays with Dimension > 2: cat, dynamic dimensioning, rand etc.
  • max and min
  • sum and cumsum
  • dot and cross products

Movie
MATLAB Exercise

3/23: Class 23: More Nuts and Bolts, Interpolation

  • prod and cumprod
  • sort and sortrows
  • interp1

Movie
MATLAB Exercise

3/25: Class 24

MIDTERM
MATLAB Solutions
MuPad Solutions

11

3/28: Class 25: filtering uniformly-spaced time-series data

  • filter
  • window functions
  • normalization
  • compensating for phase-shift

MATLAB Exercise
Movie

3/30: Class 26: more on filtering

  • comparing performance of Hann and Boxcar filters
  • creating a filtering function filter290

MATLAB Exercise
filter290.m
Movie

4/1: Class 27: Polynomial Fitting Lab

Lab 06 Problems

Lab 06 Solutions

12

4/4: Class 28: Frequency Analysis of Filter Windows

  • improving coding of filter290
    • "help" comments
    • string functions
    • multiple matches per switch case
    • adding error statements to trap problems
  • observing the effect of filter windows on sine waves of different frequencies
    • amplitude
    • phase
    • startup transient

MATLAB Exercise
Movie

4/6: Class 29: Frequency Analysis of Filter Windows, Part II

  • creating a frequency vector
  • using a for loop to step through frequencies and develop a spectrum

MATLAB Exercise
Movie

4/8: Class 30: Lab on Linearity and Aliasing

Lab 7 Problems

Lab 7 Solutions

 

 

 

13

4/11: Class 31: Lab 8: Fourier Synthesis

Movie

Lab 8 Problems

Lab 8 Solutions (published file, no animations)

lab08_solutions.m (download and run to see animations)

4/13: Class 32: Fourier Analysis Ideas

homework05 problems, due 4/20

Homework05 Solutions

 

 

4/15: Class 33: DFT of Real Functions

  • basics of data structures
  • transform a function to frequency space by projecting it onto orthogonal cosine and sine vectors in N-space
  • show sine and cosine amplitudes versus frequency
  • transform it back to real space
  • see how much it changed

dft_simple.m (cosine and sine version)
idft_simple.m (cosine and sine version)
class33.m
MATLAB Exercise

Movie

Last day to withdraw without approval of college dean

14

4/18: Class 34: Applying the DFT

  • converting from sines and cosines to amplitude and phase
  • looking at the real-space <--> frequency space mapping for some illustrative cases

class today starts from the final version of the files we developed in Class 33

dft_simple (amplitude and phase version)
idft_simple (amplitude and phase version)
MATLAB Exercise

Movie

 


4/20: No Class

4/22: Class 35: How to Use MATLAB to Fit Any Curve to Any Data Using Any Fit Criteria

  • fminsearch: a function-function that minimizes a function of N parameters
  • using randperm to choose random points from vectors

Movie

generalized_fitting.m
least_squares.m
straight_line.m
wiggly_line.m
animation_fn.m

15 4/25: No Class

4/27: Class 36: Data Analysis using Optimization, Polynomial Fitting, and Plot Annotations

  • fminbnd: find minima of functions of 1 variable
  • fzero: find zero-crossings of functions of 1 variable
  • text: place annotations on plots

Movie
MATLAB Exercise

 

4/29: Class 37: Lab 9

Lab 9: Importing and Analyzing a Data File

Data File

Lab9 Solutions

16

5/2: Class 38: Numerical Integration in MuPad and MATLAB

  • float
  • quad
  • quadgk
  • dblquad
  • triplquad
  • quad2d

Movie
MATLAB Exercise
MuPad Exercise

5/4: Class 39: Review

Final Exam Study Guide

Movie

class39.m (includes aliasing animation)

5/6

Last day to withdraw from a course with approval of college dean

17 5/9 Finals Week 5/11 Finals Week

5/13 Final Exam 7:30-9:30 am

MATLAB Solutions for Final Exam
MuPad Solutions for Final Exam