Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Exponential Curve Fitting using Python

$
0
0

I was wondering if anyone knew how to find the values of A and B in Arrhenius equation (𝑘𝑔𝑎𝑠=𝐴𝑒^(−𝐵𝑅𝑇)) using python. In this equation, 𝑇 is in Kelvin, and A has the unit of mL/min. We want to obtain a description of the rate as a function for temperature over the range from 0°C to 35°C, under the assumption that we can extrapolate.

We were given the data in the picture above. basically, we are trying to find out the activity of the yeast with temp, but first we have to find A and B. I tried a couple curve fitting techniques but all has failed

I tried a couple curve fitting techniques but all has failed. My fit was a straight line and my numbers were really off. this is the image

and this is the code/info given in the image:

import matplotlib.pyplot as pltimport numpy as npimport scipy as scipytemperature = np.array([20,25,30,33,35,37,40,45])                  # degrees Cprod_rate = np.array([6.9,9.9,21.2,26.1,32.9,30.4,18.8,18.5])/30   #mL/minplt.plot(temperature,prod_rate,'ok')plt.ylabel('Production (mL/min)')plt.xlabel('Temperature (C)')

this was my best attempt:

import matplotlib.pyplot as pltimport numpy as npimport scipy as scipydef arrhenius(T, A, B):    R = 8.314  # Gas constant, J/(mol·K)    return A * np.exp(-B / (R * T))temperature = np.array([20,25,30,33,35,37,40,45])                  # degrees Cprod_rate = np.array([6.9,9.9,21.2,26.1,32.9,30.4,18.8,18.5])/30   #mL/minplt.plot(temperature, prod_rate, 'ok')plt.ylabel('Production (mL/min)')plt.xlabel('Temperature (C)')popt, pcov = curve_fit(arrhenius, temperature, prod_rate)print(popt)A_optimal, B_optimal = poptfitted_curve = arrhenius(temperature, A_optimal, B_optimal)plt.plot(temperature, prod_rate, 'ok', label='Data')plt.plot(temperature, fitted_curve, '-r', label='Fitted Curve')plt.ylabel('Production (mL/min)')plt.xlabel('Temperature (°C)')plt.legend()plt.show()print("Optimal value for A:", A_optimal, "mL/min")print("Optimal value for B:", B_optimal)

this was the image it gave me and the numbers I got

here is the graph


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>