# -*- coding: utf-8 -*-
"""
Created on Sat May 11 22:30:52 2013

@author: Alain
"""
from math import *
import matplotlib.pyplot as plt

""" Réactions successives  A -> B -> C """

def euler(C0,k1,k2,tmax, dt):
    # j'initialise
    a = C0 # les variables courantes
    b = 0
    c = 0
    t = 0
    A = [a] # les tableaux de stockage
    B = [b]
    C = [c]
    T = [t]
    while t <= tmax : # la boucle d'itération
        # je calcule les incréments
        da = -k1*a*dt
        db = (k1*a-k2*b)*dt
        dc = k2*b*dt
        # j'incrémente 
        a = a + da
        b = b + db
        c = c + dc
        t = t + dt
        #je stocke
        A.append(a)
        B.append(b)
        C.append(c)
        T.append(t)
    #on retourne T, A, B, C
    return T, A, B, C

T, A, B, C = euler(1,1,1,5,0.01)

plt.plot(T,A,'r')
plt.plot(T,B,'b')
plt.plot(T,C,'g')
plt.show()
