-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTwoTubesSimple.m
More file actions
134 lines (80 loc) · 2.46 KB
/
TwoTubesSimple.m
File metadata and controls
134 lines (80 loc) · 2.46 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
% This implements a simpler 2-ODe model
% where the key assumption is that the interaction with
% surfaces equilibrates rapidly
classdef TwoTubesSimple < model & ConstructableHandle
properties
end % props
methods
function self = TwoTubesSimple(varargin)
self = self@ConstructableHandle(varargin{:});
if isempty(self.Parameters)
self.Parameters = struct;
self.Parameters.t_offset = 1;
self.Parameters.k_d = 1;
self.Parameters.w = 1;
self.Parameters.tau_s = 1e-1;
end
end % constructor
function evaluate(self)
assert(~isempty(self.Parameters),'Parameters should not be empty')
assert(~isempty(self.Stimulus),'Stimulus should not be empty')
% geometrical parameters
q1 = 3; % mL/s
q2 = 30; % mL/s
r2 = 2.425; % mm
r1 = 2.7; % mm
V2 = pi*r2*r2*90/1000; % mL, /1000 comes from converting to mL
% Pasteur pipette
V1 = pi*r1*r1*90/1000; % mL
% fixed parameters
phi = q1/q2; % 3mL/s / 30 mL/s
tau_2 = (V2/q2); % seconds
L = V1/V2;
L = 1;
% unpack parameters
w = self.Parameters.w;
k_d = self.Parameters.k_d;
tau_s = self.Parameters.tau_s;
ic = [1 0];
S = self.Stimulus;
time = 1e-2*(1:length(S)); % 10 ms timestep
Tspan = [min(time) max(time)];
options = odeset('MaxStep',.1);
warning off
[T, Y] = ode23t(@(t,y) SimplifedODE(t,y,time,S),Tspan,ic,options); % Solve ODE
warning on
% re-interpolate the solution to fit the stimulus
x2 = corelib.vectorise(interp1(T,Y(:,2),time));
x1 = corelib.vectorise(interp1(T,Y(:,1),time));
% normalise
if max(x2) == 0
else
x2 = x2/max(x2(find(time>1,1,'first'):find(time<3,1,'last')));
end
% allow for some offset in time
x1 = circshift(x1,floor(self.Parameters.t_offset));
x2 = circshift(x2,floor(self.Parameters.t_offset));
f2 = (1 + S(:)*phi).*x2(:);
if max(f2) == 0
else
f2 = f2/max(f2(find(time>1,1,'first'):find(time<3,1,'last')));
end
self.Prediction = f2;
function dy = SimplifedODE(t,y,time,odor)
% calculate the odor at the time point
stim = interp1(time,odor,t); % Interpolate the data set (ft,f) at time t
% unpack variables
x2 = y(2);
x1 = y(1);
effective_tau = tau_2*(1 + (w/k_d)/((1+(x2/k_d))^2));
dx2 = (stim*phi*x1 - ((1 + stim*phi)*x2))/effective_tau;
effective_tau = 1 + (w/k_d)/((1+(x1/k_d))^2);
dx1 = ((1-x1)/tau_s - (stim*phi*x1)/(tau_2*L))/effective_tau;
dy = 0*y;
dy(2) = dx2;
dy(1) = dx1;
dy = dy(:);
end
end % evaluate
end % methods
end % classdef