You are on page 1of 5

In[10]:= H∗ Evaluate HShift + EnterL this cell and click yes ∗L

ü Code follows

itrbc@8r0_, m0_<, 8c_, f_, g_, γ_<D := K O.8r0, m0< + 80, c<
1−f 1
In[2]:=
γfg 1−g

H∗ returns the asymptotic count of rbcs for the whole day Hr+μL ∗L
c H1 + fL
In[3]:=

f g H1 − γL
asymptrbc@c_, f_, g_, γ_D :=

In[4]:= currentspeedrbc@8r0_, m0_<, 8c_, f_, g_, γ_<D := γ f g r0 − g m0 + c

In[5]:= initializeAgents@n_D := Table@RandomReal@80.05, 0.95<, 2D, 8n<D

In[6]:= visualize@agents_, noise_D :=

agentsMoved = Table@RandomReal@8− noise, noise<, 2D, 8Length@agentsD<D + agents


Module@8

<,

H∗ Plotting particles ∗L
Show@

Graphics@8AbsolutePointSize@10D, RGBColor@1, 0, 0D,

If@agents ≠ 8<,
Style@

Point ê@ agentsMoved,
Point@8− 1, − 1<D
D,
Antialiasing → TrueD
<,
ImageSize → 8350, 350<,
AspectRatio → Automatic,
Frame → False,
Axes → False,
PlotRange → 880, 1<, 80, 1<<,
Background → RGBColor@0.25, 0, 0D
D
D
D
2 023-rbc-homeostatic-simulation.nb

8elements = count − Length@agentsD


In[7]:= updateAgents@agents_, count_D := Module@

<,

H∗ return an empty list ∗L


If@count 0,

8<,
If@elements ≠ 0,
H∗ there's something to do ∗L
If@elements > 0,
H∗ add ∗L
agents ∼ Join ∼ Table@RandomReal@80.1, 0.9<, 2D, 8elements<D,
H∗ remove ∗L

D,
Drop@agents, elementsD

H∗ nothing changed: return the same list ∗L

D
agents

D
D
023-rbc-homeostatic-simulation.nb 3

simulation = Deploy@Module@
8moving = False,
In[8]:=

count = 866.6667, 33.3333<,


asympt = 100,
cellcount = 99, cellspeed = 0,
c = 2, f = 0.5, g = 0.15, γ = 0.6,
newcells = 0,
newcellsadded1 = 0,
newcellsadded2 = 0,
agents = initializeAgents@99D
<,
Panel@
Grid@88
Dynamic@

cellspeed = currentspeedrbc@count, 8c, f, g, γ<D;


Refresh@

newcellsadded1 = count@@1DD + newcells;


newcellsadded2 = count@@2DD + newcells;
count = itrbc@8
If@newcellsadded1 > 0, newcellsadded1, 0D,
If@newcellsadded2 > 0, newcellsadded2, 0D
<, 8c, f, g, γ<D;
newcells = 0;
cellcount = Floor@Plus @@ countD;
agents = updateAgents@agents, cellcountD;
H∗ Length@agentsD ∗L

H∗ Style@"Working!",RGBColor@RandomReal@80.5,1<D,0,0DD ∗L
visualize@agents, 0.01D

H∗ "Count: " <> ToString@Length@agentsDD ∗L

TrackedSymbols → 8c<,
,

UpdateInterval → If@moving, 0.2, ∞D


D
D
<,
8<,
8Grid@8
8Grid@88Style@"RBC Current Count: " , 28D,

8Grid@88Style@"RBC Normal Count:", 28D, Style@Dynamic@


Style@Dynamic@ToString@cellcountDD, 28, Bold, RedD<<D<,

ToString@Floor@asymptrbc@c, f, g, γDDDD, 28, BoldD<<D<,


8Grid@88Style@"RBC Speed: ", 28D, Dynamic@
If@Abs@cellspeedD > 0.01,
Style@ToString@NumberForm@cellspeed, 82, 2<DD, 28, Bold, OrangeD,
Style@"stopped", 28, Bold, GreenDDD<<D<
4 023-rbc-homeostatic-simulation.nb

<, Frame → FalseD<

8<,
,

8"Parameters"<,
8

8"c", Slider@Dynamic@cD, 81.8, 2.2<D, Dynamic@cD<,


Grid@8

8"f", Slider@Dynamic@fD, 80.4, 0.6<D, Dynamic@fD<,


8"g", Slider@Dynamic@gD, 80.1, 0.2<D, Dynamic@gD<,
8"γ", Slider@Dynamic@γD, 80.5, 0.7<D, Dynamic@γD<
<, Frame → TrueD
<,
8<,
8Grid@88"Run Simulation", Checkbox@Dynamic@movingDD<<D<,
8<,
8Grid@88
Button@"Give Blood →", newcells = − asympt ê 4D,
Button@"Take Blood ←", newcells = asympt ê 4D,

count = 866.6667, 33.3333<;


Button@"Reset",

asympt = 100;
cellcount = 99; cellspeed = 0;
c = 2; f = 0.5; g = 0.15; γ = 0.6;
newcells = 0;
agents = initializeAgents@99D;
D<<D<
<
D
H∗ Options ∗L
D
D
D;

ü Simulation only

In[9]:= simulation
023-rbc-homeostatic-simulation.nb 5

Out[9]=

RBC Current Count: 99


RBC Normal Count: 100
RBC Speed: stopped
Parameters

c 2

f 0.5

g 0.15

g 0.6

Run Simulation

Give Blood Ø Take Blood ≠ Reset

You might also like