Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am attempting to solve a system of equations with initial values in python. Th

ID: 3826102 • Letter: I

Question

I am attempting to solve a system of equations with initial values in python. The code I have is as follows.

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

flask = 3 # flask selection
R = 8.314 # J/(mol K)
E = 56000 # J/mol
DHr = -98000 # J/mol
C = 4.18 # J/ (g K)
ko = 3.083e8 # L/(mol s)
U = 280 # W/(m^2 K)
rhoP = 1.11 # g/mL
rhoKI = 1.0 # g/ml
KI = 0.033 # mol/L
Tice = 273.15 # K

# Flask data: vol, H2O2 mL, KI mL, r, U, A
flaskData = [[100, 30, 15, 2.879, 320, 0.00558],
[250, 75, 37.5, 3.908, 281, 0.01009],
[500, 150, 75, 4.924, 279, 0.01586],
[1000, 300, 150, 6.204, 230, 0.02497]]

V = (flaskData[flask][1] + flaskData[flask][2])/1000
m = flaskData[flask][1]*rhoP + flaskData[flask][2]*rhoKI
A = flaskData[flask][5]
U = flaskData[flask][4]
print(m)
print(U*A)
print(V)

def myFunc(H2O2,T):
dH2O2dt=((-ko)**(E/(R*Tice)))*KI*H2O2
dTdt=(((-0.45*DHr)*((-ko)**(E/(R*Tice)))*KI*H2O2)+(483)*(Tice-T))/(C*483)
return numpy.array([dH2O2dt,dTdt])

Given those two functions and the fact that dTdt is dependent of H2O2, where would I go as to solving the system of equations. The initial value for H2O2 is 9.77 and for T it is 273.15. I am not sure how to set this up to use the solver from the scipy library.

Explanation / Answer

Sample Code:

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

#Have used cmath to perform fractions with negative values otherwise you may get an errors like ValueError: negative number cannot be raised to a fractional power
def myFunc(H2O2,T):
    dH2O2dt=((cmath.phase(-ko))**(E/(R*Tice)))*KI*H2O2
    dTdt=(((cmath.phase(-0.45)*DHr)*((cmath.phase(-ko))**(E/(R*Tice)))*KI*H2O2)+(483)*(Tice-T))/(C*483)
    return numpy.array([dH2O2dt,dTdt])

flask = 3 # flask selection
R = 8.314 # J/(mol K)
E = 56000 # J/mol
DHr = -98000 # J/mol
C = 4.18 # J/ (g K)
ko = 3.083e8 # L/(mol s)
U = 280 # W/(m^2 K)
rhoP = 1.11 # g/mL
rhoKI = 1.0 # g/ml
KI = 0.033 # mol/L
Tice = 273.15 # K

# Flask data: vol, H2O2 mL, KI mL, r, U, A
flaskData = [[100, 30, 15, 2.879, 320, 0.00558],
          [250, 75, 37.5, 3.908, 281, 0.01009],
          [500, 150, 75, 4.924, 279, 0.01586],
          [1000, 300, 150, 6.204, 230, 0.02497]]

V = (flaskData[flask][1] + flaskData[flask][2])/1000
m = flaskData[flask][1]*rhoP + flaskData[flask][2]*rhoKI
A = flaskData[flask][5]
U = flaskData[flask][4]
print(m)
print(U*A)
print(V)

#After done above things, you can initialize H2O2 and T values in order to solve the equations
H2O2 = 9.77
T = 273.15
result_val = myFunc(H2O2,T)
print result_val