clc; clear;
dt = 0.5;
Glucose = zeros(1,361);
Glucose(1,1) = 6000;
Glucose_Released = 110;
Glucose_Used = zeros(1,361);
Usage_Fraction = zeros(1,361);
t = 0:dt:180; % We need to generate a time vector for our plot
for k = 2:length(t)
Glucose_Used(k) = Glucose(k) * Usage_Fraction(k); % Based on Euler?sformula
Glucose(k-1) = Glucose(k) + [Glucose_Released(k) - Glucose_Used(k)]*dt;
end
Please help!!

댓글 수: 3

Sudhaunsh Deshpande
Sudhaunsh Deshpande 2021년 4월 28일
@Adam Danz Here it is
Adam Danz
Adam Danz 2021년 4월 28일
Question edited to format code.
@Sudhaunsh Deshpande, looks like David hit the nail on the head. Let us know if you have any other questions.
Sudhaunsh Deshpande
Sudhaunsh Deshpande 2021년 4월 28일
It did kinda work, the values are now zero which means that my guy is dead, but hey atleast the damn thing runs!

댓글을 달려면 로그인하십시오.

 채택된 답변

David Fletcher
David Fletcher 2021년 4월 28일

0 개 추천

You have defined Glucose_Released as a scaler value
Glucose_Released = 110;
You are then trying to index it, which will cause an error
Glucose_Released(k)

댓글 수: 6

Sudhaunsh Deshpande
Sudhaunsh Deshpande 2021년 4월 28일
The thing is Glucose_Released is the rate of glucose being released.
So the only option is:
Glucose_Released a matrix of (361X1) with the value 110
is that what you mean?
David Fletcher
David Fletcher 2021년 4월 28일
It is your calculation - I am merely pointing out that trying to index a scaler is the cause of your error. If the rate of glucose release is invariant, do you need to index it at all - or does Glucose_Released really represent the amount of glucose released over time? I don't know - as I say I have no idea what you are doing, you asked for the source of the error: I provided it.
Sudhaunsh Deshpande
Sudhaunsh Deshpande 2021년 4월 28일
Okay that actually makes sense
thank you :)
ellierose
ellierose 2023년 5월 16일
so how did you modify the script in the end to make it work?
Sudhaunsh Deshpande
Sudhaunsh Deshpande 2023년 5월 16일
Pardon my text editing:)
for i=1: length (t) Glucose Used(i) = Glucose(i) * Usage_Fraction(i); Glucose(i+1) = Glucose(i) + (G lucose_Released(i) Glucose_Used(i)) *dt; Insulin breakdown(i) = Insulin(i)/k; Insulin(i+1) Insulin(1) [Insulin_Secreted(i) Insulin_breakdown (1)] *dt;
You have
Glucose(i+1) = Glucose(i) + (G lucose_Released(i) Glucose_Used(i)) *dt
We can assume an accidental space,
Glucose(i+1) = Glucose(i) + (Glucose_Released(i) Glucose_Used(i)) *dt
but there needs to be something between Glucose_Released(i) and Glucose_Used(i)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by