Source: Rodriguez Sanchez (2025), Tufts University
It is a screenshot from MATLAB Script as Jose Armando was coding.
Sorry, this site is under remodeling, but think about it... it would look awesome :D!
Source: Rodriguez Sanchez (2025), Tufts University
It is a screenshot from MATLAB Script as Jose Armando was coding.
Jose Armando, E’26
School of Engineering, Tufts University
Download Code (Click Link):
Please Note that the following code is intellectual property of the author and organizations associated to it (including Jose's Portfolio: rsLab).
This project introduces INSIGHT (INsulin SImulation Glucose Homeostasis Tool), a MATLAB-based model designed to explore the physiological dynamics of glucose and insulin during meal ingestion and subcutaneous insulin delivery. INSIGHT builds on the classical Bergman minimal model by incorporating two additional subsystems: subcutaneous insulin absorption, represented through depot and transit compartments, and gut glucose appearance, modeled as a two-stage emptying process. These extensions allow the simulator to capture clinically relevant delays between insulin injection, its appearance in plasma, and its eventual metabolic effect, as well as the gradual rise of plasma glucose following a carbohydrate meal.
The tool enables users to specify meal size, insulin bolus timing and dose, and basal infusion rates to generate customized simulations of postprandial glucose profiles. Using MATLAB’s ODE45 solver, INSIGHT computes plasma glucose, insulin concentrations, insulin effect, and appearance rates, providing outputs as time-series plots and key summary metrics such as minimum, maximum, and final glucose levels. Results demonstrate the importance of timing and dose in minimizing glucose excursions, with pre-meal bolusing and basal infusion both reducing postprandial peaks. As an educational platform, INSIGHT offers a clear and interactive framework for understanding glucose–insulin homeostasis and for illustrating the principles of diabetes management.
Glucose homeostasis in humans is governed by a complex interplay of insulin secretion, tissue uptake, hepatic glucose output, and hormonal counter-regulation. Disruption of this balance leads to diabetes mellitus, a condition now affecting over 537 million adults worldwide, with projections surpassing 700 million by 2045¹. Computational modeling of glucose–insulin interaction has emerged as a powerful tool for investigating these processes, enabling in silico experiments that complement and reduce the need for invasive clinical studies².
The Bergman minimal model, first introduced in 1981, provided the earliest quantitative framework for insulin sensitivity and glucose effectiveness³. While groundbreaking, the model was limited to intravenous glucose tolerance tests and did not incorporate physiological complexities such as meal absorption or subcutaneous insulin delivery. Over the past two decades, extensions of this model have been proposed to better capture real-world scenarios, including the widely used UVA/Padova Type 1 Diabetes Simulator, which integrates subcutaneous insulin kinetics and carbohydrate absorption dynamics⁴.
Recent studies have emphasized the value of such models for artificial pancreas technologies, where closed-loop insulin delivery relies on accurate prediction of glucose responses to meals and insulin dosing⁵˒⁶. In parallel, systems biology approaches have highlighted inter-individual variability, advancing personalized simulation frameworks for type 1 and type 2 diabetes⁷˒⁸. These models are now central to research on insulin analogs, basal–bolus regimens, and pharmacodynamics of novel therapies⁹.
Educationally, computational simulations also play a critical role. They allow biomedical engineering students and clinicians to visualize delayed physiological responses—such as the lag between subcutaneous insulin injection, its plasma appearance, and eventual action on glucose uptake. Moreover, incorporating gut glucose appearance helps learners appreciate how carbohydrate load and glycemic index influence postprandial dynamics¹⁰. Simulation tools have therefore become essential not only for research validation but also for training and teaching in physiology, control engineering, and clinical decision-making¹¹˒¹².
The aim of this project is to present INSIGHT (INsulin SImulation Glucose Homeostasis Tool), a MATLAB-based simulation platform that integrates both the classical Bergman minimal model and physiologically relevant delays from subcutaneous insulin delivery and gut glucose absorption. INSIGHT enables users to explore how insulin dosing strategies, bolus timing, basal infusion, and meal size alter plasma glucose trajectories.
Mathematical modeling of glucose–insulin regulation has evolved substantially since the introduction of the Bergman minimal model in the early 1980s³. While the minimal model offered a foundational structure for quantifying insulin sensitivity and glucose effectiveness, its application was confined to intravenous glucose tolerance tests and could not represent real-world postprandial conditions. To address these limitations, more sophisticated models introduced additional compartments to simulate both subcutaneous insulin absorption and meal-related glucose appearance, processes that exhibit significant delays and variability in vivo²˒⁴.
Subcutaneous insulin kinetics have been extensively studied, with models highlighting the role of depot and transit compartments in shaping the time course of plasma insulin after injection¹³. These kinetics are critical for reproducing the delayed and prolonged effect of exogenous insulin compared to endogenous secretion. Similarly, gut glucose absorption models capture the gradual entry of carbohydrates into the bloodstream, reflecting differences in gastric emptying, intestinal transit, and glycemic index¹⁴. These extensions allow simulators to replicate real postprandial glucose excursions and to test therapy strategies under physiologically relevant conditions.
Comprehensive simulators such as the UVA/Padova Type 1 Diabetes Simulator have integrated these subsystems into robust platforms that support both research and regulatory use⁴. The simulator has been employed to evaluate artificial pancreas algorithms, optimize basal–bolus regimens, and assess pharmacokinetics of novel insulin analogs⁵˒⁶˒⁹. It is also FDA-accepted as an in silico testing environment, underscoring the credibility of such models for translational research⁴. Beyond type 1 diabetes, whole-body and multi-scale frameworks have further extended the scope of simulation to capture systemic metabolic interactions, paving the way for precision medicine applications⁷˒¹⁰.
Equally important is the educational value of simulators. Tools such as AIDA demonstrated early on that interactive software can enhance understanding of diabetes management by allowing users to experiment with meal size, insulin dosing, and timing in a risk-free environment¹¹. Modern applications continue this tradition, showing how computational tools can support biomedical engineering training, clinical education, and patient empowerment¹².
Methods Overview
The INSIGHT simulator is based on a modified Bergman minimal model of glucose–insulin dynamics³. The original model was extended to include (1) subcutaneous insulin absorption, modeled with a two-compartment structure⁴, and (2) gut glucose appearance, represented by a two-stage meal absorption process⁵. This allowed realistic simulation of the delays between insulin injection, plasma insulin kinetics, insulin action, and glucose uptake, as well as the gradual rise in blood glucose following carbohydrate ingestion.
State Variables
The model describes the evolution of seven state variables:
G (mg/dL): plasma glucose concentration.
X (1/min): insulin action compartment.
I (mU/L): plasma insulin concentration.
S1, S2 (mU): subcutaneous insulin depot and transit compartments.
Q1, Q2 (mg): gut glucose compartments.
Differential Equations
The governing equations were implemented in MATLAB (MathWorks, Natick, MA) using the ode45 solver with tolerances of RelTol = 1e-7 and AbsTol = 1e-9.
Simulation Setup
The system was initialized at fasting steady state with Gb=100 mg/dL and Ib=10 mU/L. A 6-hour simulation was conducted with:
Meal ingestion of 60 g carbohydrates in 30 minutes.
A 6 U rapid-acting insulin bolus at 20 minutes.
A basal infusion of 0.8 U/h.
Outputs included plasma glucose, plasma insulin, insulin action, and appearance rates. Metrics such as minimum, maximum, and final glucose concentrations were computed for interpretation.
In the baseline simulation, plasma glucose remained nearly constant at ~100 mg/dL throughout the 6-hour period, with no visible postprandial rise after the scheduled 60 g carbohydrate meal at 30 minutes. This outcome indicates that the meal input, modeled as an extremely narrow impulse (0.01 min width), did not generate a sustained glucose appearance signal in the plasma. Because the spike was shorter than the resolution of the output plots, it was effectively invisible at the scale of the simulation. While this artifact resulted in an apparently “perfectly flat” glucose profile, the behavior highlights an important modeling principle: realistic gut absorption must be represented with a gradual rise and decay in order to reproduce physiologic postprandial dynamics.
Plasma insulin, by contrast, behaved as expected. Following the 6 U subcutaneous bolus at 20 minutes, insulin concentrations increased from a basal level of ~10 mU/L to a plateau of approximately 60 mU/L by 150 minutes. This delayed and sustained rise reflects the absorption process through the subcutaneous compartments (S1 and S2), which slow the entry of injected insulin into the plasma. The insulin appearance curve therefore captures a clinically relevant feature of rapid-acting insulin therapy: injected insulin peaks later and lasts longer than endogenous pancreatic secretion, emphasizing the need for pre-meal dosing.
The appearance rate plots further confirm this interpretation. The insulin appearance rate rose steadily after the bolus, while the glucose appearance rate remained at zero. Together, these results show that the insulin subsystem of the model is functioning correctly, whereas the glucose subsystem requires refinement. In particular, spreading the meal absorption over time using the gut compartments would allow the simulation to generate a physiologically realistic glucose excursion.
So, the baseline run demonstrates the strengths and limitations of the current setup. The subcutaneous insulin module reproduces the expected pharmacokinetics of injected insulin, while the flat glucose curve underscores the sensitivity of system dynamics to input modeling. Therefore, this suggests that future simulations should adopt smoother gut absorption functions to properly capture postprandial responses and enable meaningful analysis of bolus timing, dosing, and basal infusion strategies.
Figure 1. Simulation of glucose–insulin dynamics with a 6 U subcutaneous bolus at 20 minutes, a 60 g carbohydrate meal at 30 minutes, and basal infusion (0.8 U/h). The top panel shows plasma glucose, which remained flat at baseline (100 mg/dL) due to the meal input being modeled as an instantaneous pulse that did not translate into sustained glucose appearance. The middle panel shows plasma insulin, which rose gradually from ~10 mU/L to ~60 mU/L, reflecting delayed absorption from the subcutaneous depot. The bottom panel compares appearance rates: insulin appearance (orange) increased steadily, while glucose appearance (blue) remained negligible, highlighting the absence of a visible postprandial excursion under this input formulation.
Now, lets do the following to the INSIGHT.m file:
Extend the params struct
Find this block (should be in the INSIGHT.m file):
params = struct('Gb',Gb,'Ib',Ib,'Vg',Vg,'VI',VI,'n',n,'p1',p1,'p2',p2,'p3',p3, ...
'ka1',ka1,'ka2',ka2,'U_to_mU',U_to_mU,'g_to_mg',g_to_mg, ...
'f_bio',f_bio,'k_g1',k_g1,'k_g2',k_g2, ...
'basal_mU_per_min',basal_mU_per_min, ...
'bolus_time',bolus_time_min,'bolus_units',bolus_units, ...
'meal_time',meal_time_min,'meal_size_g',meal_size_g);
Replace it with this version (just add two fields at the end):
params = struct('Gb',Gb,'Ib',Ib,'Vg',Vg,'VI',VI,'n',n,'p1',p1,'p2',p2,'p3',p3, ...
'ka1',ka1,'ka2',ka2,'U_to_mU',U_to_mU,'g_to_mg',g_to_mg, ...
'f_bio',f_bio,'k_g1',k_g1,'k_g2',k_g2, ...
'basal_mU_per_min',basal_mU_per_min, ...
'bolus_time',bolus_time_min,'bolus_units',bolus_units, ...
'meal_time',meal_time_min,'meal_size_g',meal_size_g, ...
'meal_mg', meal_size_g * g_to_mg * f_bio, ...
'tau_ingest', 25); % controls absorption speed
Fix the meal input in gi_ode
Scroll down to the local function gi_ode(t,y,P).
Right now, the original code should have:
% Meal glucose as a narrow pulse into Q1 (mg/min)
meal_mg = P.meal_size_g * P.g_to_mg * P.f_bio;
if abs(t - P.meal_time) <= pulse_w/2
u_meal = meal_mg / pulse_w;
else
u_meal = 0;
end
Delete that whole block, and replace it with:
% Meal ingestion rate into Q1 (mg/min), smoothed exponential
if t >= P.meal_time
u_meal = (P.meal_mg / P.tau_ingest) * exp(-(t - P.meal_time)/P.tau_ingest);
else
u_meal = 0;
end
The updated simulation using a smoothed absorption profile for the 60 g meal produced physiologically meaningful glucose and insulin dynamics. Plasma glucose remained steady near the baseline of 100 mg/dL until the meal was ingested at 30 minutes, after which a sharp postprandial excursion occurred. Glucose peaked at approximately 500–550 mg/dL around 70–80 minutes and then declined gradually over the following hours, approaching baseline again by the end of the six-hour simulation. This pattern contrasts with the flat response observed under the impulse-based meal input and highlights the importance of representing gut absorption as a gradual process rather than an instantaneous spike. The magnitude of the peak reflects both the carbohydrate load and the choice of absorption constant, while the eventual decline toward baseline illustrates the effect of insulin-mediated clearance.
Plasma insulin rose in response to the 6 U subcutaneous bolus administered at 20 minutes, increasing from a basal level of roughly 10 mU/L to a plateau of about 60 mU/L by 150 minutes. The delayed rise was due to absorption through the subcutaneous depot and transit compartments, which slow the entry of injected insulin into circulation. This behavior mirrors the pharmacokinetics of rapid-acting analogs in clinical settings, which typically peak later than endogenous pancreatic insulin secretion. Notably, the glucose peak occurred before plasma insulin reached its maximum, demonstrating the mismatch between rapid glucose appearance and delayed insulin availability that often contributes to postprandial hyperglycemia.
The appearance rate plots confirmed this observation. The glucose appearance rate peaked sharply soon after the meal and declined as gut stores were depleted, while the insulin appearance rate increased more slowly and eventually plateaued. This temporal mismatch between nutrient entry and insulin action underscores the clinical importance of bolus timing. In practice, administering insulin 10–20 minutes prior to a meal helps align plasma insulin levels with glucose absorption, thereby reducing the amplitude of postprandial peaks.
Overall, the simulation demonstrates how even a simplified glucose–insulin model can reproduce key physiological dynamics. The baseline run revealed three important points: first, glucose excursions are strongly shaped by meal absorption kinetics; second, subcutaneous insulin produces a delayed and sustained response that differs from endogenous secretion; and third, the temporal mismatch between glucose and insulin appearance drives postprandial hyperglycemia. Although the absolute glucose values were higher than those typically observed clinically due to parameter settings, the qualitative behavior illustrates the value of INSIGHT in exploring the consequences of meal size, insulin dosing, and timing strategies.
Figure 2. Simulation of glucose–insulin dynamics with a 6 U subcutaneous bolus at 20 minutes, a 60 g carbohydrate meal at 30 minutes, and basal infusion (0.8 U/h), using a smoothed meal absorption model. The top panel shows plasma glucose, which rose sharply from baseline (~100 mg/dL) to a postprandial peak of ~500–550 mg/dL around 70–80 minutes before gradually declining toward baseline over the 6-hour period. The middle panel shows plasma insulin, which increased from ~10 mU/L to ~60 mU/L with a delayed rise due to subcutaneous absorption kinetics. The bottom panel compares appearance rates: glucose appearance (blue) peaked soon after the meal, while insulin appearance (orange) rose more slowly and plateaued, illustrating the temporal mismatch between carbohydrate absorption and insulin availability that drives postprandial hyperglycemia.
Let’s now add a scenario involving exercising. Let do the following to the INSIGHT.m file:
Extend the params struct:
Find this block:
params = struct('Gb',Gb,'Ib',Ib,'Vg',Vg,'VI',VI,'n',n,'p1',p1,'p2',p2,'p3',p3, ...
'ka1',ka2,'ka2',ka2,'U_to_mU',U_to_mU,'g_to_mg',g_to_mg, ...
'f_bio',f_bio,'k_g1',k_g1,'k_g2',k_g2, ...
'basal_mU_per_min',basal_mU_per_min, ...
'bolus_time',bolus_time_min,'bolus_units',bolus_units, ...
'meal_time',meal_time_min,'meal_size_g',meal_size_g);
Replace it with this version (adds meal smoothing + exercise fields at the end):
params = struct('Gb',Gb,'Ib',Ib,'Vg',Vg,'VI',VI,'n',n,'p1',p1,'p2',p2,'p3',p3, ...
'ka1',ka1,'ka2',ka2,'U_to_mU',U_to_mU,'g_to_mg',g_to_mg, ...
'f_bio',f_bio,'k_g1',k_g1,'k_g2',k_g2, ...
'basal_mU_per_min',basal_mU_per_min, ...
'bolus_time',bolus_time_min,'bolus_units',bolus_units, ...
'meal_time',meal_time_min,'meal_size_g',meal_size_g, ...
'meal_mg', meal_size_g * g_to_mg * f_bio, ... % total mg to appear
'tau_ingest', 25, ... % controls ingestion speed
... % ---- Exercise parameters (time-windowed) ----
'ex_start', 45, ... % start of exercise [min]
'ex_dur', 45, ... % duration [min]
'ex_int', 0.7, ... % intensity 0..1 (0=off)
'ex_boost_p1', 0.50, ... % +50% p1 during exercise (scaled by intensity)
'ex_boost_p3', 0.50, ... % +50% p3 during exercise (scaled by intensity)
'k_ex', 0.01, ... % optional direct sink (1/min)*intensity
'post_gain_p3', 0.30, ...% +30% p3 immediately post-exercise
'post_tau_min', 120); % after-effect decay time [min]
(Set ex_int = 0 to disable exercise without changing code.)
Fix the meal input in gi_ode (smooth ingestion):
Find this block inside gi_ode(t,y,P):
% Meal glucose as a narrow pulse into Q1 (mg/min)
meal_mg = P.meal_size_g * P.g_to_mg * P.f_bio;
if abs(t - P.meal_time) <= pulse_w/2
u_meal = meal_mg / pulse_w;
else
u_meal = 0;
end
Delete it and replace with:
% Meal ingestion rate into Q1 (mg/min), smoothed exponential
if t >= P.meal_time
u_meal = (P.meal_mg / P.tau_ingest) * exp(-(t - P.meal_time)/P.tau_ingest);
else
u_meal = 0;
end
Add exercise effects in gi_ode (parameter shaping):
Right after you compute u_plasma_mU_per_min (and before the I, Q1/Q2, X, G derivatives), insert:
% -------- Exercise effects: time-windowed multipliers --------
in_ex = (t >= P.ex_start) && (t <= P.ex_start + P.ex_dur);
post_ex = (t > P.ex_start + P.ex_dur);
dt_post = t - (P.ex_start + P.ex_dur);
mult_p1 = 1.0; mult_p3 = 1.0; sink_ex = 0;
if in_ex
mult_p1 = mult_p1 * (1 + P.ex_boost_p1 * P.ex_int); % ↑ insulin-independent uptake
mult_p3 = mult_p3 * (1 + P.ex_boost_p3 * P.ex_int); % ↑ insulin sensitivity
sink_ex = P.k_ex * P.ex_int; % extra disposal (optional)
elseif post_ex
mult_p3 = mult_p3 * (1 + P.post_gain_p3 * exp(-dt_post / P.post_tau_min));
end
p1_eff = P.p1 * mult_p1;
p3_eff = P.p3 * mult_p3;
Then use these effective parameters in the X and G equations (replace the original lines):
% ---------- Insulin action ----------
dXdt = -P.p2*X + p3_eff*(I - P.Ib); % was: P.p3 -> p3_eff
% ---------- Glucose dynamics ----------
dGdt = -(X + p1_eff)*(G - P.Gb) + Ra_over_Vg - sink_ex*(G - P.Gb);
% ^ use p1_eff ^ exercise sink (can omit if desired)
Now with exercise, the most notable feature is the steeper decline in plasma glucose during the exercise window, beginning at 45 minutes. This reflects the dual mechanisms modeled: increased insulin-independent glucose uptake by active skeletal muscle and enhanced insulin sensitivity. With that, these effects produced a faster clearance of glucose from the circulation compared with the non-exercise condition, leading to an earlier inflection and a shortened hyperglycemic excursion. Such dynamics are consistent with clinical observations that moderate-intensity aerobic exercise facilitates more efficient postprandial glucose regulation.
Importantly, the plasma insulin trajectory remained largely unchanged by the addition of exercise, with levels continuing to rise due to subcutaneous absorption kinetics. The divergence lies in insulin effectiveness, rather than in insulin concentration. By amplifying tissue responsiveness (via p₃) and adding a modest direct disposal pathway, exercise decouples insulin action from insulin appearance. This distinction emphasizes the role of lifestyle interventions, which alter glucose handling without directly modifying pharmacokinetics.
Another key insight from Figure 3 is the potential risk of late-onset hypoglycemia. Even after the cessation of exercise at 90 minutes, the model retains a decaying post-exercise sensitivity effect, resulting in sustained efficiency of glucose clearance while insulin remains elevated. This reproduces a clinically relevant phenomenon whereby patients with diabetes may experience delayed hypoglycemia several hours after physical activity. Overall, Figure 3 demonstrates how exercise acts as a powerful modulator of postprandial glucose dynamics. By pairing simulated activity with meal absorption and insulin dosing, the model highlights both the therapeutic benefits of exercise in mitigating hyperglycemia and the clinical challenge of managing subsequent hypoglycemia risk.
Figure 3. Simulation of plasma glucose, insulin, and appearance rates with meal ingestion, subcutaneous insulin bolus, basal infusion, and a 45-minute exercise bout starting at 45 minutes. The top panel shows plasma glucose, which rose sharply after the meal, peaked above 400 mg/dL around 70 minutes, and then declined more rapidly during exercise due to enhanced insulin sensitivity and insulin-independent uptake. The middle panel displays plasma insulin, which rose gradually from baseline to ~60 mU/L, unaffected by exercise but with amplified physiological impact. The bottom panel shows appearance rates normalized by distribution volumes: glucose appearance (blue) peaked soon after the meal, while insulin appearance (orange) increased gradually; exercise accelerated clearance without altering these input profiles.
The INSIGHT (INsulin SImulation Glucose Homeostasis Tool) project demonstrated how progressive refinements in modeling can capture increasingly realistic aspects of glucose–insulin physiology. Beginning with a simplified representation of bolus and meal inputs, the model was extended to include smoothed gut absorption kinetics and later, the effects of exercise. These modifications revealed critical dynamics often observed in clinical practice: the temporal mismatch between rapid carbohydrate appearance and delayed insulin absorption, the role of exercise in accelerating glucose clearance, and the potential for late-onset hypoglycemia when post-exercise sensitivity persists alongside elevated insulin levels (without having patients or volunteers).
By integrating these physiological processes into a computational platform, INSIGHT should offer a flexible tool to explore the interplay of meal timing, insulin dosing, and physical activity on glycemic outcomes. It also serves as a visual and interactive method to understand complex metabolic dynamics that are otherwise difficult to observe experimentally. Although the current model simplifies several processes and much work is needed, such as the omission of counterregulatory hormones and inter-individual variability, it provides a foundation for future work. Expanding the framework to include adaptive control strategies, different insulin analogs, or personalized parameterization could further enhance its relevance to diabetes management and clinical decision support.
Author Contributions: J.A.R.S. conceived the project, designed the simulation framework, and implemented the MATLAB code for the INSIGHT platform. He conducted parameter selection, model refinement, and scenario testing for meal absorption, insulin dosing, and exercise effects. J.A.R.S. also generated all figures, performed the analysis, and wrote the manuscript, including the introduction, methods, results, and discussion sections.
Funding: This research received no external funding and was conducted as part of independent academic work.
Acknowledgments: The author acknowledges the use of MATLAB for model development and simulation, as well as prior modeling frameworks such as the Bergman minimal model and the UVA/Padova Type 1 Diabetes Simulator, which informed the design of the INSIGHT platform.
Conflicts of Interest: The authors declare no conflict of interest.
International Diabetes Federation. (2021). IDF Diabetes Atlas (10th ed.). Brussels: IDF.
Dalla Man, C., Raimondo, D. M., Rizza, R. A., & Cobelli, C. (2007). GIM, simulation software of meal glucose-insulin model. Journal of diabetes science and technology, 1(3), 323–330. https://doi.org/10.1177/193229680700100303
Bergman, R. N., Phillips, L. S., & Cobelli, C. (1981). Physiologic evaluation of factors controlling glucose tolerance in man: measurement of insulin sensitivity and beta-cell glucose sensitivity from the response to intravenous glucose. The Journal of clinical investigation, 68(6), 1456–1467. https://doi.org/10.1172/jci110398
Man, C. D., Micheletto, F., Lv, D., Breton, M., Kovatchev, B., & Cobelli, C. (2014). The UVA/PADOVA Type 1 Diabetes Simulator: New Features. Journal of diabetes science and technology, 8(1), 26–34. https://doi.org/10.1177/1932296813514502
Kovatchev B. (2018). Automated closed-loop control of diabetes: the artificial pancreas. Bioelectronic medicine, 4, 14. https://doi.org/10.1186/s42234-018-0015-6
Haidar, Ahmad. (2016). The Artificial Pancreas: How Closed-Loop Control Is Revolutionizing Diabetes. IEEE Control Systems. 36. 28-47. 10.1109/MCS.2016.2584318.
Dennis JM. Precision Medicine in Type 2 Diabetes: Using Individualized Prediction Models to Optimize Selection of Treatment. Diabetes. 2020 Oct;69(10):2075-2085. doi: 10.2337/dbi20-0002. Epub 2020 Aug 25. PMID: 32843566; PMCID: PMC7506836.
Boutayeb, A., Twizell, E. H., Achouayb, K., & Chetouani, A. (2004). A mathematical model for the burden of diabetes and its complications. Biomedical engineering online, 3(1), 20. https://doi.org/10.1186/1475-925X-3-20
Wilinska, Malgorzata & Hovorka, Roman. (2014). Simulation Models for In-Silico Evaluation of Closed-Loop Insulin Delivery Systems in Type 1 Diabetes. 10.1007/978-3-642-54464-4_6.
Carstensen, P. E., Bendsen, J., Reenberg, A. T., Ritschel, T. K. S., & Jørgensen, J. B. (2022). A whole-body multi-scale mathematical model for dynamic simulation of metabolism in man. IFAC-PapersOnLine, 55(23), 58–63. https://doi.org/10.1016/j.ifacol.2023.01.015
Lehmann, E. D., & Deutsch, T. (1996). Computer assisted diabetes care: a 6-year retrospective. Computer methods and programs in biomedicine, 50(3), 209–230. https://doi.org/10.1016/0169-2607(96)01751-8
AIDA interactive educational freeware diabetes simulator (Wikipedia).
Nucci, G., & Cobelli, C. (2000). Models of subcutaneous insulin kinetics. A critical review. Computer methods and programs in biomedicine, 62(3), 249–257. https://doi.org/10.1016/s0169-2607(00)00071-7
Papakonstantinou E, Oikonomou C, Nychas G, Dimitriadis GD. Effects of Diet, Lifestyle, Chrononutrition and Alternative Dietary Interventions on Postprandial Glycemia and Insulin Resistance. Nutrients. 2022 Feb 16;14(4):823. doi: 10.3390/nu14040823. PMID: 35215472; PMCID: PMC8878449.
% Glucose–insulin simulation with subcutaneous insulin absorption
% and a simple meal glucose appearance model.
clear; clc;
%% --------------------- USER SETTINGS ---------------------
T_end_min = 6*60; % total sim time [min]
dt_plot = 0.1; % plot resolution [min]
% Meal (carbohydrates)
meal_time_min = 30; % meal time [min]
meal_size_g = 60; % grams of carbs
% Insulin dosing (rapid-acting SC bolus + optional basal)
bolus_time_min = 20; % bolus time [min]
bolus_units = 6; % units
basal_U_per_hr = 0.8; % units/hour continuous basal (set 0 for none)
% Initial conditions (fasting steady-ish)
Gb = 100; % basal glucose [mg/dL]
Ib = 10; % basal plasma insulin [mU/L]
X0 = 0; % insulin action compartment
%% ------------------- MODEL PARAMETERS --------------------
Vg = 12; % glucose effective volume [dL]
VI = 12; % insulin plasma distribution volume [L]
n = 0.14; % insulin clearance rate [min^-1]
p1 = 0.028; % glucose effectiveness [min^-1]
p2 = 0.025; % insulin action decay [min^-1]
p3 = 1e-4; % insulin action sensitivity [(min^-2)/(mU/L)]
ka1 = 0.035; % SC depot -> SC transit [min^-1]
ka2 = 0.03; % SC transit -> plasma [min^-1]
U_to_mU = 6000; % 1 U = 6000 mU
% Meal appearance (two-compartment gut model)
f_bio = 0.9; % fraction of carbs that reach plasma
tau_gut = 25; % gut time constant [min]
k_g1 = 1/tau_gut; % gut emptying rate [min^-1]
k_g2 = 1/(tau_gut*1.3); % slower transit
g_to_mg = 1000; % convert g carbs -> mg glucose
% Basal insulin infusion (convert U/hr to mU/min into SC depot)
basal_mU_per_min = basal_U_per_hr * U_to_mU / 60;
%% --------------------- SIMULATION ------------------------
% State vector y = [G, X, I, S1, S2, Q1, Q2]'
y0 = [Gb; X0; Ib; 0; 0; 0; 0];
tspan = [0 T_end_min];
params = struct('Gb',Gb,'Ib',Ib,'Vg',Vg,'VI',VI,'n',n,'p1',p1,'p2',p2,'p3',p3, ...
'ka1',ka1,'ka2',ka2,'U_to_mU',U_to_mU,'g_to_mg',g_to_mg, ...
'f_bio',f_bio,'k_g1',k_g1,'k_g2',k_g2, ...
'basal_mU_per_min',basal_mU_per_min, ...
'bolus_time',bolus_time_min,'bolus_units',bolus_units, ...
'meal_time',meal_time_min,'meal_size_g',meal_size_g);
opts = odeset('RelTol',1e-7,'AbsTol',1e-9);
[t,y] = ode45(@(t,y) gi_ode(t,y,params), tspan, y0, opts);
% Interpolate for smooth plots
tq = (0:dt_plot:T_end_min).';
yq = interp1(t,y,tq,'pchip');
G = yq(:,1); X = yq(:,2); I = yq(:,3);
S1 = yq(:,4); S2 = yq(:,5); Q1 = yq(:,6); Q2 = yq(:,7);
% Compute inputs/appearance rates for plotting (vectorized)
[u_sc, u_plasma_mU_per_min, Ra_mg_per_min] = gi_inputs(tq, yq, params);
%% ----------------------- PLOTTING ------------------------
figure('Color','w');
subplot(3,1,1)
plot(tq,G,'LineWidth',1.8); grid on
ylabel('Glucose (mg/dL)'); xlabel('Time (min)')
title('Plasma Glucose')
xline(meal_time_min,'--','Meal'); xline(bolus_time_min,'--','Bolus');
subplot(3,1,2)
plot(tq,I,'LineWidth',1.8); grid on
ylabel('Insulin (mU/L)'); xlabel('Time (min)')
title('Plasma Insulin')
xline(meal_time_min,'--'); xline(bolus_time_min,'--');
subplot(3,1,3)
plot(tq, Ra_mg_per_min/params.Vg, 'LineWidth',1.8); hold on; grid on
plot(tq, u_plasma_mU_per_min/params.VI, 'LineWidth',1.8);
ylabel('Rates (per dL or per L)'); xlabel('Time (min)')
legend({'Glucose appearance / V_g','Insulin appearance / V_I'},'Location','best')
title('Appearance Rates (normalized by distribution volumes)')
xline(meal_time_min,'--'); xline(bolus_time_min,'--');
sgtitle('Insulin Activity Simulation (Meal + SC Bolus + Basal)')
%% --------------------- METRICS DISPLAY -------------------
G_min = min(G); G_max = max(G); G_end = G(end);
fprintf('--- Key Glucose Metrics ---\n');
fprintf('Min glucose: %.1f mg/dL\n', G_min);
fprintf('Max glucose: %.1f mg/dL\n', G_max);
fprintf('End glucose: %.1f mg/dL at t = %.0f min\n', G_end, T_end_min);
%% ==================== LOCAL FUNCTIONS ====================
function dy = gi_ode(t, y, P)
% ----- Unpack scalar state vector (ode45 passes 7x1) -----
G = y(1); % mg/dL
X = y(2); % 1/min
I = y(3); % mU/L
S1 = y(4); % mU
S2 = y(5); % mU
Q1 = y(6); % mg
Q2 = y(7); % mg
% ---------- Inputs ----------
% Basal SC insulin (mU/min)
u_basal = P.basal_mU_per_min;
% Bolus insulin as a narrow pulse (mU/min)
bolus_area_mU = P.bolus_units * P.U_to_mU;
pulse_w = 0.01; % min
if abs(t - P.bolus_time) <= pulse_w/2
u_bolus = bolus_area_mU / pulse_w;
else
u_bolus = 0;
end
u_sc = u_basal + u_bolus; % mU/min into S1
% Meal glucose as a narrow pulse into Q1 (mg/min)
meal_mg = P.meal_size_g * P.g_to_mg * P.f_bio;
if abs(t - P.meal_time) <= pulse_w/2
u_meal = meal_mg / pulse_w;
else
u_meal = 0;
end
% ---------- SC insulin dynamics ----------
dS1dt = -P.ka1*S1 + u_sc; % mU/min
dS2dt = P.ka1*S1 - P.ka2*S2; % mU/min
u_plasma_mU_per_min = P.ka2*S2; % mU/min into plasma
% ---------- Plasma insulin kinetics ----------
dIdt = -P.n*(I - P.Ib) + (u_plasma_mU_per_min / P.VI); % mU/L/min
% ---------- Gut glucose appearance ----------
dQ1dt = -P.k_g1*Q1 + u_meal; % mg/min
dQ2dt = P.k_g1*Q1 - P.k_g2*Q2; % mg/min
Ra_mg_per_min = P.k_g2*Q2; % mg/min
Ra_over_Vg = Ra_mg_per_min / P.Vg; % mg/dL/min
% ---------- Insulin action ----------
dXdt = -P.p2*X + P.p3*(I - P.Ib); % 1/min
% ---------- Glucose dynamics ----------
dGdt = -(X + P.p1)*(G - P.Gb) + Ra_over_Vg;
% Pack derivatives (column vector 7x1)
dy = [dGdt; dXdt; dIdt; dS1dt; dS2dt; dQ1dt; dQ2dt];
end
function [u_sc, u_plasma_mU_per_min, Ra_mg_per_min] = gi_inputs(t, Y, P)
% Vectorized helper for plotting inputs/appearance over many times t.
% Y is N x 7 matrix of states at those times.
S2 = Y(:,5);
Q2 = Y(:,7);
% Basal SC insulin (vector)
u_basal = P.basal_mU_per_min * ones(size(t));
% Bolus pulse over grid (vector)
bolus_area_mU = P.bolus_units * P.U_to_mU;
pulse_w = 0.01; % min (match ODE)
u_bolus = zeros(size(t));
u_bolus(abs(t - P.bolus_time) <= pulse_w/2) = bolus_area_mU / pulse_w;
u_sc = u_basal + u_bolus; % mU/min into S1
u_plasma_mU_per_min = P.ka2 .* S2; % mU/min into plasma
Ra_mg_per_min = P.k_g2 .* Q2; % mg/min into plasma
end
Jose Rodriguez Sanchez, E’26
School of Engineering, Tufts University