extra_credit_lab4.pdf

Extra Credit Assignment

October 20, 2015

1 Criteria

The extra credit opportunity is very simple, the guidelines for which are as follows:

(1) The assignment must be completed using the template I provide for lab 4.

(2) ALL output that is asked for must be displayed.

(3) ZERO unnecessary output must be displayed, that is, any output that is not the main goal of the exercise must be deleted.

(4) ALL function-file code must be displayed using the type command.

(5) All function files must be documented as described in example M-files in the notes, or, similar to the style shown below.

Partial credit will be given for each of the criteria.

NOTE: Recall that Euler’s method computes y1 using y0, then y2 using y1, and so on until all N +1 numerical solution values are obtained. That is, Euler’s method computes yn+1 using yn for n = 0, 1, 2, ..., N − 1. However, Euler’s method also requires the slope at grid point (tn, yn) given by f(tn, yn) for dy/dt = f(t, y). It then multiplies the slope by the timestep and adds yn to compute yn+1. The important point here is: the slope of vector field at the grid point (tn, yn) is required. Similarly, ode45 computes yn+1 using the slopes and solution values from previous timesteps. In LAB04ex1, for each timestep using ode45, the function f below computes the slopes at grid points (tn, yn) and (tn, vn) to compute yn+1 and vn+1. The output of ode45 is then a matrix given by

Y =

 

y0 v0 y1 v1 y2 v2 ...

... yN−1 vN−1 yN vN

 

(1)

Hopefully this helps to explain why the code below is commented as such.

1

2 LABO4ex1.m

1 function LAB04ex1 2 % LAB04EX1 numerically solves an IVP with system of 2 ODEs using ode45 3 % and displays time plots for each solution and the phase plot. 4

5 % Define time interval. 6 <code> 7 % Define initial conditions. 8 <code> 9 % Compute numerical solution to IVP using ode45.

10 <code> 11 % Extract solutions from solution matrix. 12 <code> 13 % Display time plots. 14 <code> 15 % Display phase plot. 16 <code> 17 end 18 %---------------------------------------------------------------------- 19 function dYdt= f(t,Y) 20 % F computes the slopes dy/dt and dv/dt at time t. 21 % Input: 22 % t scalar time value 23 % Y 2x1 column vector containing scalar values y and v at time t 24 % Output: 25 % dYdt 2x1 column vector containing slopes of y and v at time t 26

27 % Extract ODE solution values y(t) and v(t) from input vector Y. 28 <code> 29 % Define slopes of y and v at time t. 30 <code> 31 end

This article was created in LATEX.

2

  • Criteria
  • [basicstyle=]|LABO4ex1.m|