-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ9.m
74 lines (52 loc) · 1.49 KB
/
Q9.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
% Rate constant consistency
close all;
clear all;
%format long;
% top line is forward rate, bottom line is backward rate
% column n is rates for reaction n
forward = [1.0 1.0 1.0];
backward = [ 0.5, 0.2, 2.0];
identifiers = {'a' 'b' 'c'};
arrow = '->';
rxns = {strsplit('a -> b');
strsplit('a -> c');
strsplit('b -> c')};
rxnidentifiers = cellfun(@strjoin, rxns, 'UniformOutput', false);
model = modelbuilder(identifiers, arrow, rxns, forward, backward);
initial_y = [ 1 0 0 ];
tspan = [ 0 20 ];
[t, Y] = ode45(model, tspan, initial_y);
% calclulate the instantaneous rates
rates = zeros(length(t), length(rxns));
for i = 1:length(t)
[temp, rates(i, :) ] = model(t(i), Y(i, :));
end
figure
plot(t, Y);
legend(identifiers);
title('Concentration With Arbitrary Rates')
figure
plot(t, rates);
legend(rxnidentifiers);
title('Elementary rxn rates (Arbitrary)')
% but the rates aint zero!
% let's fix that
%% Rates, the internally consistent way
backward(3) = forward(3)*backward(2)*forward(1)/(backward(1)*forward(2));
model = modelbuilder(identifiers, arrow, rxns, forward, backward);
initial_y = [ 1 0 0 ];
tspan = [ 0 20 ];
[t, Y] = ode45(model, tspan, initial_y);
% calclulate the instantaneous rates
rates = zeros(length(t), length(rxns));
for i = 1:length(t)
[temp, rates(i, :) ] = model(t(i), Y(i, :));
end
figure
plot(t, Y);
legend(identifiers);
title('Consistent Rates');
figure
plot(t, rates);
legend(rxnidentifiers);
title('Elementary rxn rates (Consistent)');