Iterator goes infinite when changing step from 1 to 0.1
1 回表示 (過去 30 日間)
古いコメントを表示
Here is my code. The iterator works exactly as intended as long as my step size (weldInterval) is equal to 1. But if I want to change that interval to 0.1 to allow for more precision in the program and break it into smaller time chunks it will run infinitely and I do not know why.
clear; clc;
totalWelds = 100;
Welds = zeros([2, totalWelds]);
time = 0; % Counter for total time taken
rooting = 1;
done = 1;
capMax = 0;
fillMax = 0;
Welds(2,1) = 1;
%Time required to complete phases
rootSpeed = 3.0;
hotSpeed = 3.0;
fillSpeed = 5.0;
capSpeed = 4.0;
weldInterval = 1; % Step Size, errors when changed to 0.1
while Welds(2,totalWelds) ~= 5
time = time + weldInterval;
% Iterate only through the unfinished ones, up to the currently rooting
% weld
for x = done:rooting
% Increase time step
Welds(1,x) = Welds(1,x) + weldInterval;
%If weld is rooting and reached time completion
if((Welds(2,x)==1) && (Welds(1,x)==rootSpeed))
%Change weld to hot pass, reset phase time
Welds(2,x) = 2;
Welds(1,x) = 0;
%Set start point for loop to next rooting node
rooting = rooting + 1;
%Set next node to rooting
Welds(2,x+1) = 1;
disp("Rooted"); %Debugging
% else If weld is hot passing and reached time completion
elseif(Welds(2,x)==2 && Welds(1,x)==hotSpeed)
%Change weld to fill pass, reset phase time
Welds(2,x) = 3;
Welds(1,x) = 0;
% else If weld is filling and reached time completion
elseif(Welds(2,x)==3 && Welds(1,x)==fillSpeed)
%Change weld to cap pass, reset phase time
Welds(2,x) = 4;
Welds(1,x) = 0;
% else If weld is capping and reached time completion
elseif(Welds(2,x)==4 && Welds(1,x)==capSpeed)
%Change weld to completed, reset phase time
Welds(2,x) = 5;
Welds(1,x) = 0;
%Increment end of loop counter
done = done + 1;
end
end
% Count the number of concurrent fillPassers and capPassers
fillCount = 0;
capCount = 0;
for x = done:rooting
if Welds(2,x)==3
fillCount = fillCount + 1;
elseif Welds(2,x)==4
capCount = capCount + 1;
end
end
% Set the maximum concurrent Fill/Cap Passers
if fillCount > fillMax
fillMax = fillCount;
end
if capCount > capMax
capMax = capCount;
end
%Debugging disps
disp("time = " + time);
disp(Welds)
disp(Welds(1,x))
end
disp(capMax)
disp(fillMax)
disp(time);
This program is designed to simulate the assembly line process of welding and determine how many Fill and Cap Pass welders are needed to ensure no stalls and that everything is completed within the day.
It is currently running in minutes, but we want to break it into tenths of a minute to allow for more accurate timing in comparison to real life. This would allow us to eventually break it down into seconds for most accurate precision
0 件のコメント
採用された回答
the cyclist
2021 年 5 月 25 日
It's difficult to follow exactly what it going on in your code. I haven't traced the logic completely, but I figured out that when weldInterval is less than 0.5, the code never enters the section of code
if((Welds(2,x)==1) && (Welds(1,x)==rootSpeed))
%Change weld to hot pass, reset phase time
Welds(2,x) = 2;
Welds(1,x) = 0;
%Set start point for loop to next rooting node
rooting = rooting + 1;
and therefore rooting is never updated, so you never advance in your loop.
If you are not familiar with it, I suggest you use the debugger to discover why your code behaves unexpectedly when weldInterval is less than 0.5.
3 件のコメント
the cyclist
2021 年 5 月 25 日
Aaahhhhh ...
Instead of using equality, make the comparison using a tolerance, something like
tol = 1.e-6;
abs(Welds(1,1) - 1) < tol;
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!