Homework_3_2011

Homework_3_2011 - RK2 and one plotting the numerical and...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 111 - Introduction to Computational Science Homework 3 1. Recall that a system of ODEs can be written as: d Y dt = F ( t, Y ,par ) , (1) where t is the variable, par is a list of parameters and Y is a vector whose components are the solutions of the system, i.e. Y = y 1 y 2 . . . y n , where n is the number of components. Likewise, F is a vector function, i.e. F = f 1 f 2 . . . f n . (a) Write a function that is able to apply one Euler step to the i th component of equation (1). This code should therefore take in dt , f i , t , Y , i and the list of parameters (you can use the varargin cell array in Matlab) and apply one Euler step to the i th component. For example a user will call your function with i = 2 if he/she wants to solve for y 2 . Check the accuracy of your function using an exact solution of your choice. (b) Same question using a RK2 step. (c) Same question using a RK4 step. What to turn in : your codes as well as 3 graphs (one plotting the numerical and exact solutions using the Euler’s method, one plotting the numerical and exact solutions using
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: RK2 and one plotting the numerical and exact solutions using RK4). 2. Consider the Predator-Prey model: dN dt = N-PN, (2) dP dt =-P + PN, (3) where P is the number of predators and N the number of prey (or nutrients). Write a code that solves these equations from t = 0 to t = 20. Use a time step of .1 and take initially P = 5 and N = 10. The parameters are = 1 . 5, = 1, = 3 and = 1. Plot the solutions P and N as a function of t on a single graph. Do this using Eulers method, RK2 and RK4. Comment on your results, i.e. explain the dynamics of interaction between predators and prey. What to turn in : your codes as well as a 3 graphs (one plotting P and N using the Eulers method, one plotting P and N using RK2 and one plotting P and N using RK4) and a paragraph on your explanation of the dynamics between predators and prey. 1...
View Full Document

Ask a homework question - tutors are online