Guest User

Untitled

a guest
Apr 28th, 2015
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. function [ ] = zombies2(a,b,ze,d,T,dt)
  2. % This function will solve the system of ODE’s for the basic model used in
  3. % the Zombie Dynamics project for MAT 5187. It will then plot the curve of
  4. % the zombie population based on time.
  5. % Function Inputs: a - alpha value in model: "zombie destruction" rate
  6. % b - beta value in model: "new zombie" rate
  7. % ze - zeta value in model: zombie resurrection rate
  8. % d - delta value in model: background death rate
  9. % T - Stopping time
  10. % dt - time step for numerical solutions
  11. % Created by Philip Munz, November 12, 2008
  12.  
  13. %Initial set up of solution vectors and an initial condition
  14. N = 500; %N is the population
  15. n = T/dt;
  16. t = zeros(1,n+1);
  17. s = zeros(1,n+1);
  18. z = zeros(1,n+1);
  19. r = zeros(1,n+1);
  20.  
  21. s(1) = N;
  22. z(1) = 0;
  23. r(1) = 0;
  24. t = 0:dt:T;
  25.  
  26. % Define the ODE’s of the model and solve numerically by Euler’s method:
  27. for i = 1:n;
  28. s(i+1) = s(i) + dt*(-b*s(i)*z(i)); %here we assume birth rate
  29. %= background deathrate, so only term is -b term
  30. z(i+1) = z(i) + dt*(b*s(i)*z(i)+ze*r(i)-a*s(i)*z(i));
  31. r(i+1) = r(i) + dt*(a*s(i)*z(i)+d*s(i)-ze*r(i));
  32. if s(i)<0 || s(i) >N
  33. break
  34. end
  35. if z(i) > N || z(i) < 0
  36. break
  37. end
  38. if r(i) <0 || r(i) >N
  39. break
  40. end
  41. end
  42. hold on
  43. plot(t,s,'b');
  44. plot(t,z,'r');
  45. xlabel('Time'), ylabel('Population Value (1000s)') % label axes
  46. title('Basic Model - R0 > 1 with I.C. = DFE', 'FontSize', 14) % title
  47. legend('Suscepties','Zombies')
Advertisement
Add Comment
Please, Sign In to add comment