MTH 480 LAB 4

In this lab you will learn quantitative (numerical) techniques for ODEs.

Turning in part of your work is mandatory. The other part can be used for extra credit. Please make sure all the steps are labelled properly and described well. A bunch of graphs stapled together does not constitute a solution worthy of extra credit.

Instructions follow below. Please note approximate timing of the steps and demonstrations.
Set-up phase: (14:00-14:05)
  1. Log in to the computer using your ONID account and start MATLAB.

Solving an ODE numerically in MATLAB: DEMONSTRATION 14:05-14:15
  1. how to set up a function (in an M-file)
    % this should be typed up in a myode.m file
    function [dx] = myode (t,x)
    dx = zeros(1,1);
    dx = -x./(1+x);
    end
    % this should be typed in in the command window
    [T,Y]=ode45(@myode,[0,1],[4]);
    plot(T,Y(:));

    Now explore on your own. Try different initial conditions (replace 4 by something else) or on a different interval (replace [0,1] by something different ...) Also, try a different function.


  2. Now we solve numerically a system of ODEs. First, try the pendulum example.

    You have to code the function that describes the right hand side of the system X'=F(X) so that x(1) is the first component, and x(2) is the second.


    % save in the file myode2.m
    function [dx] = myode2 (t,x)
    dx = zeros(2,1);
    dx(1) = x(2);
    dx(2) = -x(1);
    end

    Now solve the system with initial condtions x(0)=6, y(0)=-3 and plot both components of the solution.
    Type this in a command window
    [T,Y]=ode45(@myode2,[0,10],[6,-3]);
    plot(T,Y(:,1),T,Y(:,2)); legend('X','Y');

    Now you want to see both components of the solution, and maybe also part of the phase plot. Try the first in figure 1, and the second in figure 2.

    figure(1);plot(T,Y(:,1),T,Y(:,2)); legend('X','Y');figure(2);plot(Y(:,1),Y(:,2)); axis([ -5 5 -5 5]);


  3. Now solve numerically the following problems
    1. x'=-y-xy,y'=x+x^2 (We discussed this one in class). Confirm the behavior ! (Pick at least 5 qualitatively different sets of initial conditions to confirm the behavior of x(t), y(t) with respect to the equilibrium line x=-1.)
      Print the trajectories. phase plots etc. [On Figure window, click on "File" to see "print").
    2. x'=-y+xy.^2, y'=x+y^3 (This is assigned as Pbm 3 in HW 7 so you can use this part of the assignment as an opportunity to check your work).

    You can also use PPLANE in parallel to ode45 for more complete understanding of the solution to the system. However, PPLANE sometimes "takes over" the plotting windows so make sure you have your MATLAB figures started before you start PPLANE.

    More on numerical ODE solvers: The routine ode45 is best overall. However, there are other functions that do a good job and/or are better tailored to particular types of ODEs. See doc ode45 for more about this. Or take MTH 452/552.


Explore models that were given to you on "Modeling" worksheet.
  1. POPULATION DYNAMICS (with carrying capacity and more)
  2. PHYSICS (free fall and skydiving, with particular attention paid to terminal velocity)
  3. CHEMICAL REACTIONS


To get my attention, please raise your hand.