Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. function [ ] = zombieinfection2(a,b,ze,d,rho,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. % rho - rho value in model: infection rate
  10. % T - Stopping time
  11. % dt - time step for numerical solutions
  12. % Created by Philip Munz, November 12, 2008
  13.  
  14. %Initial set up of solution vectors and an initial condition
  15. N = 500; %N is the population
  16. n = T/dt;
  17. t = zeros(1,n+1);
  18. s = zeros(1,n+1);
  19. z = zeros(1,n+1);
  20. r = zeros(1,n+1);
  21. l = zeros(1,n+1);
  22.  
  23.  
  24. s(1) = N;
  25. z(1) = 0;
  26. r(1) = 0;
  27. l(1) = 0;
  28. t = 0:dt:T;
  29.  
  30. % Define the ODE’s of the model and solve numerically by Euler’s method:
  31. for i = 1:n;
  32. s(i+1) = s(i) + dt*(-b*s(i)*z(i)); %here we assume birth rate
  33. %= background deathrate, so only term is -b term
  34. l(i+1) = l(i) + dt*(b*s(i)*z(i)-rho*l(i)-d*l(i));
  35. z(i+1) = z(i) + dt*(b*s(i)*z(i) -a*s(i)*z(i) +ze*r(i));
  36. r(i+1) = r(i) + dt*(a*s(i)*z(i) +d*s(i) - ze*r(i));
  37. if s(i)<0 || s(i) >N
  38. break
  39. end
  40. if z(i) > N || z(i) < 0
  41. break
  42. end
  43. if r(i) <0 || r(i) >N
  44. break
  45. end
  46. if l(i) <0 || l(i) >N
  47. break
  48. end
  49. end
  50. hold on
  51. plot(t,s,'b');
  52. plot(t,z,'r');
  53. xlabel('Time'), ylabel('Population Value (1000s)') % label axes
  54. title('SIZR Model - R0 > 1 with I.C. = DFE', 'FontSize', 14) % title
  55. legend('Suscepties','Zombies')
  56.  
  57. zombieinfection2(0.005,0.0095,0.0001,0.0001,0.005,20,0.1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement