1180:Lab5 James Moore February 5th, 2012

advertisement

1180:Lab5

James Moore

February 5th, 2012

Goals For This Week

We’ll learn how to solve ODEs with more than one state variable. As an example, we’ll look at a predator prey model. The fitzugh-nagumo model is desribed in section 5.8.

1 Two-dimensional differential Equations

We’re finally ready to solve a system of differential equations with multiple parameters. This is the predator-prey system we talked about in class.

db dt dp dt

= (

= (

λ

δ ǫp

+

)

ηb b

) p

There are two state variables : b and p ; and four parameters : λ , ǫ , δ and η (that’s ‘lambda’,‘epsilon’,‘delta’ and ‘eta’). First, we shall write the right hand side of our equation. We’ll start with the skeleton-I’ll call the function predprey.

predprey<-function(t,y,p){

}

Then we should code up the right hand side of each individual equation.

predprey<-function(t,y,p){ db=(l-e*p)*b dp=(-d+n*b)*p

}

Now we return the result, but this is tricky as we have to combine db and dp and then designate it as a list.

1

predprey<-function(t,y,pars){ db=(l-e*p)*b dp=(-d+n*b)*p list(c(db,dp))

}

The problem with this code is that it uses all of these variables that we haven’t yet defined (l,e,...etc).

The values for these variables are stored in y and p,but we have to use with to ‘extract’ them.

This is our final function.

predprey<-function(t,y,pars){ with(as.list(c(y,pars)),{ db=(l-e*p)*b dp=(-d+n*b)*p list(c(db,dp))

})

}

Now we can run the function yini=c(b=100,p=2000) tlist=seq(0,20,.1) parameters<-c(l=1,d=1,n=.001,e=.001) result=ode(func=predprey,y=yini,t=tlist,parms=parameters) plot(result)

2 Plotting:Time Series and Phase Planes

Over the last couple of weeks I’ve had you combine the output of many runs into a single graph using the lines command. In truth, plot is smarter than that.

yini1=c(b=100,p=2000) yini2=c(b=100,p=1000) yini3=c(b=500,p=500) tlist=seq(0,20,.1) parameters<-c(l=1,d=1,n=.001,e=.001) result1=ode(func=predprey,y=yini1,t=tlist,parms=parameters) result2=ode(func=predprey,y=yini2,t=tlist,parms=parameters) result3=ode(func=predprey,y=yini3,t=tlist,parms=parameters) plot(result1,result2,result3)

2

This will only work when we are plotting a data frame (which result1,result2 and result3 are because they were made for us by ODE).

Save this Plot

Another way to visualize this data is with a phase plane. We’ll plot the prey on the horizontal and the predator on the vertical. The code below creates a phase plane picture with all three results.

plot(result1[,"b"],result1[,"p"],type=’l’,xlab=’Bacteria(Prey)’,ylab=’Amoeba(Predator)’) lines(result2[,"b"],result2[,"p"],lty=2,col=’red’) lines(result3[,"b"],result3[,"p"],lty=3,col=’green’)

If the plot only fills half the window close the plot window and try again.

Save this Plot

3 Questions for This Week

1.

Predator Prey System

Include time series and phase plane plot from above.

On the phase plane, does the population travel clockwise or anticlockwise.

Describe what is happening to the populations and why they cycle.

2.

Fitzugh-Nagumo Equation dv dt dw dt

=

=

− ǫ ( v v

( v

− a

γw )

)( v

1)

− w + I

Let I = 0, ǫ = .

01, a = .

3 and γ = 2 .

5. Solve with ode from t=0 to t=100. Use 3 sets of initial conditions.Let

w (0) = 0 and let v (0) = .

2, .

4 and .

6.

Plot the time series together.

Plot the phase portraits together.

With these parameters, this system has an activation threshold. Based, on your graphs, what is meant by that?

Now let v (0) = .

2 and change I to .01,.05 then .1. This represents a constant input current.

Plot the time series together

Plot the phase portraits of these results together.

What happens when you increase the input current?

3

Download