Codes
This page will grow over the course of the semester. I use these codes either for visualization or as examples of numerical methods. They are categorized by language (Matlab/Octave or Python), and ordered chronologically. Note that there are online versions of Matlab (Matlab online) and Octave (Octave Online).
Matlab: Visualization
You can use Matlab or Octave with these. (I use Octave, which is free and open source, and runs Matlab codes the same way.)
- exdirfield.m: This is just one example. To generate direction fields (slope fields) in Matlab/Octave and other languages, see the wikipedia page on slope fields.
- streamcyl.m: Generate a contour figure, showing streamlines around a cylinder, for Example 5 in the slides for section 2.4.
- census.m: Plot some US census data for an example in the slides in section 3.2.
- massspringplot.m: Used for section 5.1 slides.
- dampingcases.m: Used for section 5.1 slides. Calls massspringplot.m. Generates this figure.
- pendmovie.m: Make a movie of a nonlinear pendulum, using Matlab’s ode45. Generates this .gif movie.
- brines.m: Used for section 8.1 slides. Generates this figure and this figure.
- decays.m: From solutions to Homework 3.3. Generates this figure and this figure.
- lotkavolterra.m: From solutions to Homework 3.3. Generates this figure.
Matlab: Numerical methods
- simpleeuler.m: Solve the simplest ODE IVP (y’=y,y(0)=1) by the Euler method. See the slides for section 2.6.
- walkoutside.m: Solve a Newton’s law of cooling example by the Euler method. Produces this image. See the slides for section 2.6.
Python
You will need to know Python to use these.
- dirfield.py: Generate a direction field. I used this for images in some slides.
- quadde.py: Draw direction field and family of solutions for dy/dx = y^2 - 9, from section 2.2. Generates this image. The solution family I wrote down in lecture is correct, but many solutions blow-up in finite time.
- e1.py: Direction field and Euler solutions for E1 on Homework 2.6.
no-programming solutions
- To generate direction fields without programming, try one of these: