# Numerical Solutions

$$\newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} }$$ $$\newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}}$$$$\newcommand{\id}{\mathrm{id}}$$ $$\newcommand{\Span}{\mathrm{span}}$$ $$\newcommand{\kernel}{\mathrm{null}\,}$$ $$\newcommand{\range}{\mathrm{range}\,}$$ $$\newcommand{\RealPart}{\mathrm{Re}}$$ $$\newcommand{\ImaginaryPart}{\mathrm{Im}}$$ $$\newcommand{\Argument}{\mathrm{Arg}}$$ $$\newcommand{\norm}[1]{\| #1 \|}$$ $$\newcommand{\inner}[2]{\langle #1, #2 \rangle}$$ $$\newcommand{\Span}{\mathrm{span}}$$ $$\newcommand{\id}{\mathrm{id}}$$ $$\newcommand{\Span}{\mathrm{span}}$$ $$\newcommand{\kernel}{\mathrm{null}\,}$$ $$\newcommand{\range}{\mathrm{range}\,}$$ $$\newcommand{\RealPart}{\mathrm{Re}}$$ $$\newcommand{\ImaginaryPart}{\mathrm{Im}}$$ $$\newcommand{\Argument}{\mathrm{Arg}}$$ $$\newcommand{\norm}[1]{\| #1 \|}$$ $$\newcommand{\inner}[2]{\langle #1, #2 \rangle}$$ $$\newcommand{\Span}{\mathrm{span}}$$$$\newcommand{\AA}{\unicode[.8,0]{x212B}}$$

Code $$\PageIndex{1}$$ (Python):

%%python3

import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt

def rxn1st(C,t,*k):

r1=k[0]*C[0] #k[0]*(concentation of A)

dAdt=-r1 #rate of change of A decreased by forward reaction and increased by reverse reaction
dBdt=r1 #rate of change of B increased by forward reaction and decreased by reverse reaction

t=np.linspace(0,10,101) #the first number is the beginning point, the second number is the end, and the third is the number of points.
C0=[1,0] #initial concentrations of A and B
k1=1
k2=0
k=[k1]
C=odeint(rxn1st,C0,t,(k1,k2))

cA=C[:,0] #define cA to give the concentration from the first (zeroth) column of the C array
cB=C[:,1] #define cB to give the concentration from the second column of the C array



Numerical Solutions is shared under a not declared license and was authored, remixed, and/or curated by LibreTexts.