MATLAB Answers

Iterator goes infinite when changing step from 1 to 0.1

1 view (last 30 days)
Jadon Latta
Jadon Latta on 25 May 2021
Commented: Jadon Latta on 26 May 2021
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

Accepted Answer

the cyclist
the cyclist on 25 May 2021
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 Comments
Jadon Latta
Jadon Latta on 26 May 2021
Thank you! I had thought it might be something along those lines, but was honestly struggling with remembering how to deal with fixing it. I appreciate the help :)

Sign in to comment.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by