Extrapolating rate constants from reaction data

4 views (last 30 days)
Below is the code I have written to extrapolate rate constants from a consecutive two step reaction (second step reversible). The code runs but when I try to solve my for my rate constants it returns only zeros. Can anybody see the error?
L = ('Lspan');
t = ('tspan');
syms L(t) k l m g h L0
eqn = L(t) == k*L0*((m/(g*h))+((h-m)/(g*(g-h))*exp(-h*t))+((m-g)/(g*(g-h)))*exp(-g*t))+2*k*l*L0*(1/(g*h)+(exp(-g*t)/(g*(g-h)))-(exp(-h*t)/(h*(g-h))));
cond = L(0) == L0;
cond = g*h == k*(l+m);
cond = g+h == k+l+m;
solve(l)
solve(k)
solve(m)
plot(tspan,Lspan,'o')

Answers (1)

John D'Errico
John D'Errico on 1 Nov 2019
Edited: John D'Errico on 1 Nov 2019
l,k, m are just scalar symbolic variables. When you write
solve(k)
for example, it solves the problem
k == 0
What is the solution to that problem? I would bet it is k=0. MATLAB does not know that you actually want it to solve some equation for k.
As well, when you write things like:
cond = L(0) == L0;
cond = g*h == k*(l+m);
cond = g+h == k+l+m;
what happens is MATLAB first creates a variable called cond. Then it creates a variable named cond, overwriting the first one. Finally, it creates a variable named cond for the THIRD time, overwriting the previous version.
What else? I see this:
L = ('Lspan');
t = ('tspan');
That just creates two character vectors. I'm not sure what you think they will do, since then you immediately overwrite them with symbolic variables L and t in the syms command.
So I would seriously suggest you need to read the getting started tutorials, since you seem not to even remotely understand how a language like MATLAB works. You are creating things, then immediately overwriting them. You are assuming that MATLAB will know what it is you want to do. Read the manual.
If I had to make a wild guess as to what you want to do, it might be that you have three equations, in three unknowns.
syms k l m g h L0 t
L(t) = k*L0*((m/(g*h))+((h-m)/(g*(g-h))*exp(-h*t))+((m-g)/(g*(g-h)))*exp(-g*t))+2*k*l*L0*(1/(g*h)+(exp(-g*t)/(g*(g-h)))-(exp(-h*t)/(h*(g-h))));
eqn(1) = L(0) == L0;
eqn(2) = g*h == k*(l+m);
eqn(3) = g+h == k+l+m;
sol = solve(eqn,l,k,m)
sol =
struct with fields:
l: [2×1 sym]
k: [2×1 sym]
m: [2×1 sym]
>> sol.l
ans =
-h
-h
>> sol.k
ans =
g
h
>> sol.m
ans =
2*h
g + h
So there are two solutions apparently. Again, it is just a wild guess.

Categories

Find more on Chemistry in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!