Borrar filtros
Borrar filtros

Solving ODE with 2 unknowns

2 visualizaciones (últimos 30 días)
Sudhaunsh Deshpande
Sudhaunsh Deshpande el 30 de Abr. de 2021
Respondida: Nipun el 22 de Mayo de 2024
In this code i have been given:
  • Start time = 0 min
  • End time = 180 min
  • Time Step = 0.5 min
  • Initial Glucose Value = 6000 mg
  • Initial Insulin Value = 9000 mg
  • Usage_Fraction: use equation above
  • Insulin Secretion Rate: use equation above
  • Glucose Release Rate: using the in-built menu function in MATLAB, provide the following options for glucose release rate:
o Normal Meal: 110 mg/min
o Pasta Meal: 330 mg/min
The equations provided are:
>> Glucose_Used(t) = Glucose(t) * Usage_Fraction(t)
>> Glucose(t+dt) = Glucose(t) + [Glucose_Released(t) – Glucose_Used(t)]*dt
>> Insulin_Breakdown(t) = Insulin(t)/k
>> Insulin(t+dt) = Insulin(t) + [Insulin_Secreted(t) – Insulin _Breakdown(t)]*dt
The problem
Glucose_Used and Usage_Fraction are set to zero and the values don't change. This means that the Glucose value keeps on increasing (which is NOT desireable)
Here's The code
%%
%Initializing
clear; clc;
figure;
dt = 0.5;
t = 0:dt:180;
Glucose_Released = zeros(1,361);
k = 17.5+0;
Usage_Fraction = zeros(1,361);
%Usage_Fraction = [];
Glucose(1) = 6000;
Insulin(1) = 9000;
Insulin_Secreted = zeros(1,361);
Insulin_Used = zeros(1,361);
Blood_volume = zeros(1,362);
Blood_volume(1,:) = 60;
Hypoglycemia = 40;
HyperGlycemia = 210;
%Glucose_Used = zeros(1,361);
%%
%Creating a choice
choice = menu('Please select a Glucose level','Normal meal', 'Pasta meal');
if choice == 1
Glucose_Released(1,:) = 110;
else
Glucose_Released(1,:) = 330;
end
%%
%Euler's Explicit Method
for i = 1:length(t)
Glucose_Used(i) = Glucose(i) * Usage_Fraction(i);
Glucose(i+1) = Glucose(i) + [Glucose_Released(i) - Glucose_Used(i)]*dt;
end
for i = 1:length(t)
Insulin_breakdown(i) = Insulin(i)/k;
Insulin(i+1) = Insulin(i) + [Insulin_Secreted(i) - Insulin_breakdown(i)]*dt;
end
%%
%Plotting
Blood_glucose = Glucose./Blood_volume;
Blood_glucose_plot = Blood_glucose(2:362);
subplot(2,1,1)
plot(t,Glucose_Released)
xlabel ('Time(min)');
ylabel ('Glucose released into blood (mg/min)');
title ('Glucose Release Profile');
subplot(2,1,2)
plot(t,Blood_glucose_plot)
xlabel ('Time(min)');
ylabel ('Blood Glucose Level (mg/dl)');
title('Blood Glucose Profile');
Please help :[
  2 comentarios
Sudhaunsh Deshpande
Sudhaunsh Deshpande el 30 de Abr. de 2021
ellierose
ellierose el 16 de Mayo de 2023
@Sudhaunsh Deshpande did you solve it in the end?

Iniciar sesión para comentar.

Respuestas (1)

Nipun
Nipun el 22 de Mayo de 2024
Hi Sudhaunsh,
I understand that you are trying to simulate the dynamics of glucose and insulin levels in the body over time, considering the consumption of different types of meals. The key issue in your code is that the Usage_Fraction remains zero, leading to unrealistic simulation results where glucose levels continuously increase without any usage.
To address this, I recommend implementing a mechanism to update the Usage_Fraction dynamically based on the model's requirements. Below is a concise MATLAB code snippet that introduces a basic structure for updating the Usage_Fraction and includes the insulin secretion dynamics which were missing from the original description.
% Initialization
clear; clc;
dt = 0.5; % Time step in minutes
t = 0:dt:180; % Time from 0 to 180 minutes
Glucose = zeros(1, length(t) + 1); % Initialize Glucose array
Glucose(1) = 6000; % Initial Glucose Value in mg
Insulin = zeros(1, length(t) + 1); % Initialize Insulin array
Insulin(1) = 9000; % Initial Insulin Value in mg
k = 17.5; % Given constant for Insulin breakdown
% User Choice for Glucose Release Rate
choice = menu('Please select a meal type:', 'Normal Meal', 'Pasta Meal');
if choice == 1
Glucose_Released = 110; % Normal Meal: 110 mg/min
else
Glucose_Released = 330; % Pasta Meal: 330 mg/min
end
% Simulation Loop (Euler's Method)
for i = 1:length(t)
% Placeholder for dynamic update of Usage_Fraction based on your model
Usage_Fraction = 0.01; % This should be replaced with your specific equation
% Assuming Insulin_Secreted dynamically changes, placeholder equation
Insulin_Secreted = 50; % This should be replaced with your specific equation
% Calculate Glucose and Insulin dynamics
Glucose_Used = Glucose(i) * Usage_Fraction;
Glucose(i+1) = Glucose(i) + (Glucose_Released - Glucose_Used) * dt;
Insulin_Breakdown = Insulin(i) / k;
Insulin(i+1) = Insulin(i) + (Insulin_Secreted - Insulin_Breakdown) * dt;
end
% Plotting Results
figure;
subplot(2,1,1);
plot(t, Glucose(1:end-1));
xlabel('Time (min)');
ylabel('Glucose Level (mg)');
title('Glucose Level Over Time');
subplot(2,1,2);
plot(t, Insulin(1:end-1));
xlabel('Time (min)');
ylabel('Insulin Level (mg)');
title('Insulin Level Over Time');
This code initializes the glucose and insulin levels and simulates their changes over time, considering the effect of meal type on glucose release rate. The Usage_Fraction and Insulin_Secreted are placeholders in this script and should be replaced with specific equations that reflect how glucose usage and insulin secretion change in response to the levels of glucose and insulin in the body.
Hope this helps.
Regards,
Nipun

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Productos


Versión

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by