print('Solving using CK4 method......') for i in [x for x in ode.CK4([decay], 0.0, [initial_nuclei], 0.1, 50.0)]: print(','.join([str(x) for x in i])) print('') print('Solving using CK5 method......') for i in [x for x in ode.CK5([decay], 0.0, [initial_nuclei], 0.1, 50.0)]: print(','.join([str(x) for x in i])) print('') print('Solving using RKF4 method......') for i in [x for x in ode.RKF4([decay], 0.0, [initial_nuclei], 0.1, 50.0)]: print(','.join([str(x) for x in i])) print('') print('Solving using RKF5 method......') for i in [x for x in ode.RKF5([decay], 0.0, [initial_nuclei], 0.1, 50.0)]: print(','.join([str(x) for x in i])) print('') print('Solving using DP4 method......') for i in [x for x in ode.DP4([decay], 0.0, [initial_nuclei], 0.1, 50.0)]: print(','.join([str(x) for x in i])) print('') print('Solving using DP5 method......') for i in [x for x in ode.DP5([decay], 0.0, [initial_nuclei], 0.1, 50.0)]: print(','.join([str(x) for x in i])) print('')
def zombie(t, y): newly_infected = transmission * y[0] * y[1] resurrected = resurect * y[2] destroyed = destroy * y[0] * y[1] return newly_infected + resurrected - destroyed def dead(t, y): natural_death = death * y[0] destroyed_zombies = destroy * y[0] * y[1] created_zombies = resurect * y[2] return natural_death + destroyed_zombies - created_zombies def influx(y, step): y[0] = y[0] + (5 * step) return y f = [human, zombie, dead] # system of ODEs # initial human, zombie, death population, and total respectively y = [500.0, 0, 0] print('Solving using 5th order Dormand-Prince method ......') noinflux = [x for x in ode.DP5(f, 0.0, y, 0.1, 50.0)] influx = [x for x in ode.DP5(f, 0.0, y, 0.1, 50.0, influx)] for i in range(len(noinflux)): consolidated = noinflux[i] + influx[i][1:] print(','.join([str(x) for x in consolidated]))
def zombie(t, y): newly_infected = transmission * y[0] * y[1] resurrected = resurect * y[2] destroyed = destroy * y[0] * y[1] return newly_infected + resurrected - destroyed def dead(t, y): natural_death = death * y[0] destroyed_zombies = destroy * y[0] * y[1] created_zombies = resurect * y[2] return natural_death + destroyed_zombies - created_zombies f = [human, zombie, dead] # system of ODEs # initial human, zombie, death population, and total respectively y = [500.0, 0, 0] lower_bound = {0: [10.0, 10.0]} upper_bound = {1: [1000.0, 1000.0]} print('Solving using 5th order Dormand-Prince method ......') nobound = [x for x in ode.DP5(f, 0.0, y, 0.1, 50.0)] lowerbound = [x for x in ode.DP5(f, 0.0, y, 0.1, 50.0, None, lower_bound)] doublebound = [ x for x in ode.DP5(f, 0.0, y, 0.1, 50.0, None, lower_bound, upper_bound) ] for i in range(len(nobound)): consolidated = nobound[i] + lowerbound[i][1:] + doublebound[i][1:] print ','.join([str(x) for x in consolidated])
y[0] * y[1] created_zombies = resurrect * y[2] return natural_death + \ destroyed_zombies - \ created_zombies # system of ODEs bounded = [human1, zombie1, dead1] # initial human, zombie, death population # respectively y = [500.0, 0, 0] print('''Solving using 5th order Dormand-Prince method with \ bounded variables......''') for i in [x for x in ode.DP5(bounded, 0.0, y, 0.1, 50.0)]: print(','.join([str(z) for z in i])) # ----------------------------- # Case 2: Un-Bounded Variables # ----------------------------- def human2(t, y): infected = y[5] * y[0] * y[1] dead = y[4] * y[0] return y[3] - infected - dead def zombie2(t, y): newly_infected = y[5] * y[0] * y[1]