rumor.ode 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # This example simulates the spread of a rumor through a closed
  2. # population. The percentage of people who have not heard the
  3. # rumor, as a function of time, is plotted.
  4. #
  5. # You may run this example by doing:
  6. #
  7. # ode < rumor.ode | graph -T X -C
  8. #
  9. # or alternatively, to get a real-time plot,
  10. #
  11. # ode < rumor.ode | graph -T X -C -x 0 .25 -y 0 100
  12. # The theoretical background for this model is as follows.
  13. #
  14. # Suppose a rumor spreads through a closed population of constant size
  15. # N+1. At time t the total population can be classified into three categories:
  16. # x persons who are ignorant of the rumor;
  17. # y persons who are actively spreading the rumor;
  18. # z persons who have heard the rumor but have stopped spreading it;
  19. #
  20. # Suppose that if two persons who are spreading the rumor meet then they stop
  21. # spreading it.
  22. # Suppose also that the contact rate between any two categories is constant, u.
  23. #
  24. # The equations
  25. # x' = -u * x * y,
  26. # y' = u * (x*y - y*(y - 1) - y*z)
  27. # give a deterministic model of the problem.
  28. #
  29. # When initially y = 1 and x = N, the number of people
  30. # who ultimately never hear the rumor is s, where s satisfies
  31. # 2N + 1 - 2s + N log(s/N) = 0.
  32. x' = -u * x * y
  33. y' = u * (x*y - y*(y-1) - y*( 100 + 1 - y - x))
  34. x = 100
  35. y = 1
  36. u = 1
  37. print t, x
  38. step 0, 0.25