Skip to content
Snippets Groups Projects
Commit 3acf51d9 authored by Tu, Ethan's avatar Tu, Ethan
Browse files

Upload New File

parent c4b51dd5
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id: tags:
``` python
# Put your code here
# Import commands
from scipy.stats import gamma
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from scipy.integrate import odeint
import math as math
# Derivative function
def derivs(curr_vals, time):
# Unpack the current values of the variables we wish to "update" from the curr_vals list
Cp, Cisf = curr_vals
# Define value of input function Cin
Cin = rv.pdf(time)
# Right-hand side of odes, which are used to computer the derivative
dCp_dt = (flow/Vp)*(Cin - Cp) + (PS/Vp)*(Cisf - Cp)
dCisf_dt = (PS/Visf)*(Cp - Cisf)
return dCp_dt, dCisf_dt
# Declare Variables for initial conditions
flow = 1/60 # Flow into capillary
Vp = 0.05 # Volume of plasma
Visf = 0.15 # Volume of interstitial space
PS = 1/60 # Permeability-Surface area product
Cp0 = 0 # Initial concentration of tracer in plasma
Cisf0 = 0 # Initial concentration of tracer in interstitial space
tmax = 10 #Time in seconds
dt = 0.1 #Time step
a = 2. # Alpha for gamma distribution
rv = gamma(a, loc = 2, scale = 0.55) #input function
# Define the time array
time = np.arange(0, tmax + dt, dt)
# Store the initial values in a list
init = [Cp0, Cisf0]
# Solve the odes with odeint
sol = odeint(derivs, init, time)
Mass_plasma = Vp * sol[:,0] #mass of tracer in plasma
Mass_isf = Visf * sol[:,1] #mass of tracer in isf
Tp = Vp/(flow + PS) # mean transit time
E = 1 - np.exp(-PS/flow) #extraction fraction
Q = Mass_plasma + Mass_isf
print('The mean transit time is ' + str(Tp))
print('The extraction fraction is ' + str(E))
# Plot the results using the values stored in the solution variable, "sol"
# Plot Cp using the "0" element from the solution
plt.figure(1)
plt.plot(time, rv.pdf(time), color = 'blue', label = 'Input Function')
plt.plot(time, sol[:,0],color="green", label = 'Cp')
# Plot Cisf using the "1" element from the solution
plt.plot(time, sol[:,1],color="purple", label = 'Cisf')
plt.xlabel('Time [s]')
plt.ylabel('Concentration [mM]')
plt.legend(loc = 'best')
plt.grid()
# Plot mass of tracer using the "2" element from the solution
plt.figure(2)
plt.plot(time, Mass_plasma,color="red", label = 'Plasma')
# Plot mass of tracer in tissue using the "3" element from the solution
plt.plot(time, Mass_isf,color="black", label = 'Interstitial Space')
plt.plot(time, Q, color="blue", label = 'Total mass')
plt.xlabel('Time [s]')
plt.ylabel('Mass [mg]')
plt.legend(loc = 'best')
plt.grid()
print('Cp at 10 sec is ' + str(sol[100,0]))
print('Cisf at 10 sec is ' + str(sol[100,1]))
```
%% Output
The mean transit time is 1.5
The extraction fraction is 0.6321205588285577
Cp at 10 sec is 0.023400076577464173
Cisf at 10 sec is 0.038131979959528696
%% Cell type:code id: tags:
``` python
Q[99]
```
%% Output
0.007018384196576239
%% Cell type:code id: tags:
``` python
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment