Skip to content

Instantly share code, notes, and snippets.

@muscovitebob
Last active March 19, 2018 18:03
Show Gist options
  • Save muscovitebob/22dda1ad60f7436ec37a84ab70995366 to your computer and use it in GitHub Desktop.
Save muscovitebob/22dda1ad60f7436ec37a84ab70995366 to your computer and use it in GitHub Desktop.
MATLAB four compartment pharmacological model with regular mass intake
sol = ode45(@CompartSysFunc, [0 10], [1.8 0 0 0]);
t = transpose(getfield(sol, 'x'));
y = transpose(getfield(sol, 'y'));
plot(t, y(:,1), 'r', t, y(:,2), 'g', t, y(:,3), 'b', t, y(:,4), 'y')
range = 10:5:30;
for i = 2:5;
sol(i) = odextend(sol(i-1), @CompartSysFunc, range(i), [sol(i-1).y(1,end)+2 sol(i-1).y(2,end) sol(i-1).y(3,end) sol(i-1).y(4,end)]);
t1 = transpose(getfield(sol(i), 'x'));
y1 = transpose(getfield(sol(i), 'y'));
hold on;
plot(t1, y1(:,1), 'r', t1, y1(:,2), 'g', t1, y1(:,3), 'b', t1, y1(:,4), 'y')
end
legend('Gut', 'Central Tissues', 'Peripheral Tissues', 'Bladder')
function s = CompartSysFunc(t, x)
ka = 5;
kc = 2;
kp = 2;
ke = 0.4;
s1 = -ka.*x(1);
s2 = ka.*x(1) -(kc + ke).*x(2) + kp.*x(3);
s3 = kc.*x(2) -kp.*x(3);
s4 = ke.*x(2);
s = transpose([s1 s2 s3 s4]);
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment