so i'm looking at this web page at the moment - its a chemistry /maths question that gives you data for rate vs temp to calculate the activation energy of the substance - the data is on the page & in the code
http://faculty.weber.edu/ewalker/Chem2990/Chem3020/WebPages/1_11.htm
in it gives values for T and k(rate)
as it says you can plot 1/T vs ln(k) to calc Ea (activation energy) & A(pre-exp factor)
but rather than do that make a programme that iterates chi^2 calculations to evaluate the lowest one - which will be associated with an activation energy
Arrhenious is : // k = A * exp(-Ea/(RT))
chi^2 = ((observed - expected)^2)/expected
where observed is the values of k given on the web page and expected is the estimate made when using an estimate Ea - which starts at 100
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <string>
#include <fstream>
#include <sstream>
#include <iomanip>
using namespace std;
int main()
{
long double chi1;
long double chi2;
long double T[8] = { 400,430,460,490,510,540,610,7000, };
long double k[8] = { 0.011,0.035,0.105,0.343,0.789,2.17,20.0,145, };
long double kJ;
long double R = 8.31446;
long double ki[8];
long double OE[8];
long double dEa = 10000;
int i = 0;
int dp = 5;
// k = A * exp(-Ea/(RT))
long double Ea = 100000;
long double A = 1.100e+12;
// I’m keeping A constant at 1.1*10^12
// Then calculating Chi Squared from a starting Ea value of 100000
// k = A * exp(-Ea/(RT))
do {
do {
chi1 = 0; chi2 = 0;
i = 0;
while (i < 8) {
ki[i] = A*exp(-E / (R*T[i]));
OE[i] = pow(k[i] - ki[i], 2);
chi1 = chi1 + (OE[i]);
i++;
}
i = 0;
while (i < 8)
{
ki[i] = A*exp(-(E + dE) / (R*T[i]));
OE[i] = pow(k[i] - ki[i], 2);
chi2 = chi2 + (OE[i]);
i++;
}
if (chi1 > chi2) {
E = E + dE;
}
} while (chi2 < chi1);
do {
chi1 = 0; chi2 = 0;
i = 0;
while (i < 8)
{
ki[i] = A*exp(-E / (R*T[i]));
OE[i] = pow(k[i] - ki[i], 2);
chi1 = chi1 + (OE[i]);
i++;
}
i = 0;
while (i < 8)
{
ki[i] = A*exp(-(E - dE) / (R*T[i]));
OE[i] = pow(k[i] - ki[i], 2);
chi2 = chi2 + (OE[i]);
i++;
}
if (chi1 > chi2) {
E = E - dE;
}
} while (chi2 < chi1);
dE = dE / 10;
} while (dE > pow(10, 2 - dp));
kJ = E / 1000;
cout << dE << endl;
cout << “Ea = " << fixed << setprecision(dp) << kJ << "kJ" << endl;
cout << “Chi squared = " << chi1 << endl;
return 0;
}
basically my value for chi^2 and for Ea don't match my excel results
- any ideas?