Ask Your Question

Revision history [back]

How to fit data to an arrhenius equation

Hi, I'm pretty new to sage and am currently trying it out with cloud.sagemath and sage on ubuntu. I'm trying to fit some data to an arrhenius equation of a continuous stirred tank reactor-model. So far, I've managed to import data from a .csv-file and convert it into a matrix:

import numpy as np
import csv
R = 8.314462 [J/mol/K]

yield = []
temp = []
t_res = [] #residence time
conc_init = [] #initial concentration

data2 = list(csv.reader(file('manuel2.csv'), delimiter=';'))
m = matrix([[ float(_) for _ in line] for line in data2])

n = np.vstack(m)

##now I'm converting the matrix into single numpy-arrays:
yield = n[:,0]
temp = n[:,1]
t_res = n[:,2]
conc_init = n[:,4]
conc = conc_init - yield/100*conc_init #calculate actual concentrations

from here I tried to use the find_fit function to fit my data to the arrhenius-equation

var('E_A,A')
model(conc)=conc_init - A*exp(-E_A/(R*temp))*conc*t_res
data=(conc,conc_init,temp,t_res)
fit=find_fit(data,model)

when I finally evaluate I get this error:

(E_A, k_inf) Error in lines 36-36 Traceback (most recent call last): File "/projects/b9085414-cff2-4e5a-9c3b-872f47d41a7c/.sagemathcloud/sage_server.py", line 736, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> File "/usr/local/sage/sage-6.3.beta6/local/lib/python2.7/site-packages/sage/calculus/all.py", line 96, in symbolic_expression return SR(x) File "parent.pyx", line 1083, in sage.structure.parent.Parent.__call__ (build/cythonized/sage/structure/parent.c:8902) File "coerce_maps.pyx", line 95, in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4203) File "coerce_maps.pyx", line 90, in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4110) File "ring.pyx", line 289, in sage.symbolic.ring.SymbolicRing._element_constructor_ (build/cythonized/sage/symbolic/ring.cpp:5332) TypeError

I actually don't have a clue what that means or how I can get this to work.