! Decay, version 1a. ! John Wise, initiated 2001/01/12, last updated 2001/01/12. ! Based on "Decay" in "Computational Physics" by N. Giordano. program Decay1 library "IrGraphics*" option nolet dim t(0), n(0) call Init(nt, dt, t0, n0, r) mat redim t(0:nt), n(0:nt) t(0) = t0 n(0) = n0 call Calc(nt, dt, t(), n(), r) id$ = "JHW: Decay1, nt:50, r:2" call Graph1A(id$, "time", "number", t(), n(), 1) print " t = "; t(nt) print " n = "; n(nt) print "Done" end sub Init(nt, dt, t0, n0, r) nt = 50 ! number of time steps dt = 0.01 ! time step t0 = 0 ! initial time n0 = 1 ! initial value r = 2 ! decay rate end sub sub Calc(nt, dt, t(), n(), r) for i = 1 to nt nd = - r*n(i-1) t(i) = t(i-1) + dt n(i) = n(i-1) + nd*dt next i end sub