{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

429-2009-HW1key

# 429-2009-HW1key - cos t/10-x end Listing 4 fun4.m Steady...

This preview shows pages 1–3. Sign up to view the full content.

Systems Bioengineering III: Homework 1 Rahul Karnik September 11, 2009 To do this simulation, we need to do three basic steps: 1. Define the four ODEs 2. Define the range to simulate and the initial condition 3. Use an ODE solver and plot the results Now I will describe how to do the simulation using MATLAB. We first define the four switching functions, each in its own M-file. Note that here I have not explicitly defined that β ( t ) = 0 for t < 0, since the range over which I am simulating has t 0. It may be necessary to define this case explicitly if the simulation range is different. Listing 1: fun1.m % Fast switching % beta ( t ) = cos (10 * alpha * t ) function xprime = fun1 ( t , x) xprime = cos (10 * t ) - x end Listing 2: fun2.m % Matched switching % beta ( t ) = cos ( alpha * t ) - x function xprime = fun2 ( t , x) xprime = cos ( t ) - x end 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Listing 3: fun3.m % Slow switching % beta ( t ) = cos (( alpha /10) * t ) function xprime = fun3 ( t , x) xprime = cos ( t /10)
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: cos ( t /10)-x end Listing 4: fun4.m % Steady state % beta ( t ) = 1 function xprime = fun4 ( t , x) xprime = 1-x end Next, we set up the range over which the simulation is done (0 to 200 π at intervals of π/ 4), and deﬁne the initial value of X * as zero. Listing 5: Range and initial value tspan = [ 0 : pi /4:200 * pi ] x0 = 0 Finally, we invoke the ODE solver ode45 built into Matlab, and plot the results. Listing 6: Solve and plot [ t1 , x1 ] = ode45 (@fun1 , tspan , x0 ) ; [ t2 , x2 ] = ode45 (@fun2 , tspan , x0 ) ; [ t3 , x3 ] = ode45 (@fun3 , tspan , x0 ) ; [ t4 , x4 ] = ode45 (@fun4 , tspan , x0 ) ; plot ( t1 , x1 , ’ r-’ , t2 , x2 , ’g-’ , t3 , x3 , ’b-’ , t4 , x4 , ’--’ ) ; The plot should look like the one below. The red line is for fast switching, green for matched, blue for slow, and dotted for the steady state case. 2 3...
View Full Document

{[ snackBarMessage ]}