MATLAB SAMPLES, TAM 203, Fall 2000

Here are some MATLAB SAMPLE ODE solutions. The examples are to help you get started. In the end, every command you use you should know how to use on your own.

To get more help see Rudra Pratap's book pages 128-141 after doing the tutorial exercises.

Also get online help from   >help ode23   and, once you are more advanced,   >help odeset   and   >help odefile.

Each solution has two files. The names of the files are the first line. Save each group of text as a file with that name in a folder/directory where you keep your TAM 203 MATLAB things.

If you have download problems: Some students have reported problems downloading these plane text examples. The CIT help desk had no troubles downloading these files with either a mac or PC, but did make these suggestions:
1) Instead of double-clicking on the files, highlight the files and then use 'save as' (option-click on a mac, right-click on a PC).
2) If you get a file with one long line and with boxes instead of carriage returns, save it in a text editor and do search and replace to replace all boxes with carriage returns.
3) Use Netscape instead of Internet Explorer.
4) Get a newer version of Netscape.
If you have any deep insight about the solution to this download problem please let us know (

Test. Make sure that you can run simple things first by saving and running a file named 'testing123.m' that contains this:



Example 1. Here is a bare bones example that shows the solution of the ODE:   

  dy/dt = 2 y  - t   integrated from t=1 to t=3 with y(0) = 0.7.

These two files are minimally commented so that the basic simpicity is most clear.

first_driver.m      first_rhs


Example 2. Here is a bare bones second order system. Instead of plotting vs time, a phase plot of v verses x is drawn.  (Puzzle: is the plot a straight line?)

dx/dt = v,       dv/dt = - 5v    integrating from t=0  to  t=5   with x(0) = 2, v(0) = 3.

In the files below we put x and v into the two elements of the column vector z.

second_driver.m      second_rhs.m


Example 3. Exactly the same problem is solved here as the previous example, but written with many more comments and showing some other options. Cut and paste and try it out.

systems_driver.m      systems_rhs.m


Example 4. The lecture example from Thursday February 10, 2000, calculating a 2D trajectory assuming a quadratic drag law. You should run these as written and be sure you can give a detailed answer to the following question: Why are the second and 4th numbers in the answer printed in the command window so simple (0.00 and -50.00)?

cannondriver.m      cannonrhs.m