Optimization: I cant figure out why my while loop doesn't stop?
Afficher commentaires plus anciens
I have a for function inside of a for loop which is inside of a while loop. The loop should be stopping before it reaches the 10,000.
%% Declaration
a = 10;
b = 9.5;
r = 0;
i = 1;
s = 92101;
h = 0.5;
n = s + i + r;
yes = 0;
inc = 0;
numberBeds = 267.093;
%% Get numbers
while yes == 0
% Get infected
for k = 1:1:1000
[ sN, iN, rN ] = DiseaseStep( s, i, r, n, a, b, h );
sN(k) = sN;
iN(k) = iN;
rN(k) = rN;
[m,~] = max(iN);
m = m * 0.024;
end
% Stop loop if
if m >= numberBeds
yes = 0;
else
yes = 1;
end
% Increment
inc = inc + 1;
% end loop
if inc == 10000
yes = 1;
else
yes = 0;
end
% Increase beds
numberBeds = numberBeds + 0.001;
% Adjust budget
budget = budget + (0.001 * 5000);
% Decrease a
a = a - 0.001;
end
function [ SOut, IOut, ROut ] = DiseaseStep( s, IIn, RIn, n, a, b, h )
%DiseaseStep This function is going to take in the values needed to
%calculate change over time and then change. Then, it is going to calculate
%the values of I,S,R after one step
n = s + IIn + RIn;
IOut= IIn+(h*(((a.*s.*IIn)./n)-(IIn/b))); %equation
SOut= s+(h*((-a.*s.*IIn)./n));
ROut= RIn+(h*(IIn/b));
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Function Creation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!