Académique Documents
Professionnel Documents
Culture Documents
Program Code
clc;
clear workspace;
%disp('----------------------------------------------------------------------------
-');
%disp(' Project in Numerical Methods');
%disp(' (NMTL04X)');
%disp('----------------------------------------------------------------------------
-');
%disp('----------------------------------------------------------------------------
-');
%disp('Project Objectives:');
%disp('~ When the vehicle is filled with waste, to its designed weight capacity, no
more waste should be loaded.');
%disp('~ The compactor is uniquely designed as part of the loading area. The
compactor pivots from the horizontal to vertical. Then it is diven to the front of
the vehicle, compacting stored waste.');
%disp('~ When compacting is taking place, the operator must not be able to access
the loading area. This is to be closed off with a steel shutter.');
%disp('~ The steel shutter must be prevented from closing if the operator is
trapped between the closing shutter and the vehicle to body work.');
%disp('~ The whole truck body is raised when emptying takes place.');
%disp('~ Provide an emergency stop.');
%disp('----------------------------------------------------------------------------
-');
while L2==1
%disp(' ____________________
% /| /|
% / | / |
% / | / |
% / | / |
% / |______________/ |
% / / / /
% |~~~~~~~~~~~~~~~~~~~| /
% | | /
% | | /
% | | /
% |___________________|/
% /');
Load=input('Input Load(kg): ','s');
ch=1;
while ch<2
LET=is_letter(Load);
EMP=isempty(Load);
if LET==1
%disp(' ____________________
% /| /|
% / | / |
% / | / |
% / | / |
% / |______________/ |
% / / / /
% |~~~~~~~~~~~~~~~~~~~| /
% | | /
% | | /
% | | /
% |___________________|/
% /');
Load=input('Alert! INPUT IS NOT A NUMBER.
Input Load(kg):','s');
ch=1;
end
if EMP==1
%disp(' ____________________
% /| /|
% / | / |
% / | / |
% / | / |
% / |______________/ |
% / / / /
% |~~~~~~~~~~~~~~~~~~~| /
% | | /
% | | /
% | | /
% |___________________|/
% /');
Load=input('No input.
Input Load(kg):','s');
ch=1;
end
if LET==0
%disp(' ____________________
% /| /|
% / | / |
% / | / |
% / | / |
% / |______________/ |
% / / / /
% |~~~~~~~~~~~~~~~~~~~| /
% | | /
% | | /
% | | /
% |___________________|/
% /');
b1=str_to_num(Load);
ch=10;
end
end
disp('Press [1] to retry input');
disp('Enter any character or press ENTER to continue');
while ch<2
LET=is_letter(Load);
EMP=isempty(Load);
if LET==1
%disp(' ____________________
% /| /|
% / | / |
% / | / |
% / | / |
% / |______________/ |
% / / / /
% |~~~~~~~~~~~~~~~~~~~| /
% | | /
% | | /
% | | /
% |___________________|/
% /');
Load=input('Alert! INPUT IS NOT A NUMBER.
Input Load(kg):','s');
ch=1;
end
if EMP==1
%disp(' ____________________
% /| /|
% / | / |
% / | / |
% / | / |
% / |______________/ |
% / / / /
% |~~~~~~~~~~~~~~~~~~~| /
% | | /
% | | /
% | | /
% |___________________|/
% /');
Load=input('No input.
Input Load(kg):','s');
ch=1;
end
if LET==0
%disp(' ____________________
% /| /|
% / | / |
% / | / |
% / | / |
% / | / |
% / |______________/ |
% / / / /
% |~~~~~~~~~~~~~~~~~~~| /
% | | /
% | | /
% | | /
% |___________________|/
% /');
b1=str_to_num(Load);
ch=10;
end
end
end
Load=b1;
if Load<=CAP
disp('WARNING! Steel shutter is now closing...');
pause(1);
%disp('
%.=========================================.
%|| / \ / \ ||
%|/=======================================\|
%||_______________________________________||
%|| ||
%|| _______________________________ ||
%|| / \ ||
%|| | | ||
%|| | | ||
%|| | | ||
%|| | | ||
%|| | | ||
%|| | | ||
%|\=======================================/|
%|| ||
%|| ||
%\=========================================/ ');
disp('...');
pause(.3);
disp('...');
pause(.3);
disp('...');
pause(.3);
%disp('
%.=========================================.
%|| / \ / \ ||
%|/=======================================\|
%|| ||
%||_______________________________________||
%|| ||
%||_______________________________________||
%|| ||
%||_______/__\_______________/__\_________||
%|| ||
%||_______________________________________||
%||_______________________________________||
%|| ||
%||_______________________________________||
%|\=======================================/|
%|| ||
%|| ||
%\=========================================/ ');
disp('Steel shutter is now closed.');
pause(1);
%disp('
%======================. .============.
% || || ||
%_____________________||___||___ ||
%______________________________/ ||
% || || ||
%===========((0)(0))==|/ \|__________|/
%');
pause(.3);
disp('Compacting...');
%disp('
%======================. .============.
% || || ||
%_____________________||___||___ ||
%______________________< < < < / ||
% || || ||
%===========((0)(0))==|/ \|__________|/
%');
pause(.3);
disp('...');
%disp('
%======================. .============.
% || || ||
%_____________________||___||___ ||
%___________ < < < < < < < < < / ||
% || || ||
%===========((0)(0))==|/ \|__________|/
%');
pause(.3);
disp('...');
%disp('
%======================. .============.
% || || ||
%_____________________||___||___ ||
%___< < < < << < < < < < < < < / ||
% || || ||
%===========((0)(0))==|/ \|__________|/
%');
pause(.3);
disp('...');
%disp('
%======================. .============.
% || || ||
%_____________________||___||___ ||
% < < < < < << < < < < < < < < / ||
% || || ||
%===========((0)(0))==|/ \|__________|/
%');
pause(.3);
disp('Done Compacting!');
disp('Compacted.');
pause(1);
%disp('
%======================. .============.
% || || ||
%_____________________||___||___ ||
%______________________________/ ||
% || || ||
%===========((0)(0))==|/ \|__________|/
%');
pause(1);
%disp('
%.=========================================.
%|| / \ / \ ||
%|/=======================================\|
%|| ||
%||_______________________________________||
%|| ||
%||_______________________________________||
%|| ||
%||_______/__\_______________/__\_________||
%|| _______________________________ ||
%||___| |___||
%|| | | ||
%||__/ \__||
%|\=======================================/|
%|| ||
%|| ||
%\=========================================/ ');
disp('Steel shutter is now opening...');
pause(.3);
disp('...');
pause(.3);
disp('...');
pause(.3);
disp('...');
pause(.3);
%disp('
%.=========================================.
%|| / \ / \ ||
%|/=======================================\|
%|| /=================================\ ||
%|| | | ||
%|| | | ||
%|| | | ||
%|| | | ||
%|| | | ||
%|| | | ||
%|| | | ||
%|| | | ||
%|| | | ||
%|\=======================================/|
%|| ||
%|| ||
%\=========================================/ ');
disp('Steel shutter is now open.');
pause(1);
%disp(' ____________________
% /| /|
% / | / |
% /#####,,,,,,,,,#####/ |
% /#,,,,,......#######/ |
% /######,,,, #####/ |
% /___________________/ /
% | | /
% | | /
% | | /
% | | /
% |___________________|/
% /');
Load1=Load;
SPACE=CAP-Load1;
fprintf('Maximum Capacity(kg) = %f\n', CAP);
fprintf('Input load(kg) = %f\n', Load);
fprintf('Remaining Space(kg) = %f\n', SPACE);
L2=0;
end
if Load>CAP
%disp(' ____________________
% /###################/|
% /###################/ |
% /###################/ |
% /###################/ |
% /###################/ |
% /###################/ /
% |~~~~~~~~~~~~~~~~~~~| /
% | | /
% | | /
% | | /
% |___________________|/
% /');
fprintf('Alert! Input load exceeded.');
L2=1;
end
end
L1=1;
while L1==1
if Load1<=CAP
Load1=Load1;
if Load1<CAP
disp(' ');
disp('Input Load(kg) again: Type [1] then ENTER');
disp('Unload the Truck: Type [2] the ENTER');
disp('Stop the program: TYPE [3] the ENTER');
if (sscanf(N,'%f'))==1
N1=1;
while N1==1 && Load1<CAP
R1=1;
if R1==1
%disp(' ____________________
% /| /|
% / | / |
% /#####,,,,,,,,,#####/ |
% /#,,,,,......#######/ |
% /######,,,, #####/ |
% /___________________/ /
% | | /
% | | /
% | | /
% | | /
% |___________________|/
% /');
Load2=input('Input Load(kg): ','s');
ch=2;
while ch<3
LET=is_letter(Load2);
EMP=isempty(Load2);
if LET==1
Load2=input('Alert! Input is not a number.
Input Load(kg): ','s');
ch=1;
end
if EMP==1
Load2=input('Alert! No input.
Input Load(kg): ','s');
ch=1;
end
if LET==0
%disp(' ____________________
% /| /|
% / | / |
% / | / |
% / | / |
% / |______________/ |
% / / / /
% |~~~~~~~~~~~~~~~~~~~| /
% | | /
% | | /
% | | /
% |___________________|/
% /');
p1=str_to_num(Load2);
ch=10;
end
end
while ch<2
LET=is_letter(Load2);
EMP=isempty(Load2);
if LET==1
Load2=input('Alert! INPUT IS NOT A NUMBER.
Input Load(kg):','s');
ch=1;
end
if EMP==1
Load2=input('Alert! No input.
Input Load(kg):','s');
ch=1;
end
if LET==0
%disp(' ____________________
% /| /|
% / | / |
% / | / |
% / | / |
% / |______________/ |
% / / / /
% |~~~~~~~~~~~~~~~~~~~| /
% | | /
% | | /
% | | /
% |___________________|/
% /');
p1=str_to_num(Load2);
ch=10;
end
end
end
Load2=p1;
Load1=Load1+Load2;
SPACE=CAP-Load1;
%O=Load+Load2;
if Load1<CAP
disp('WARNING! Steel shutter is now closing...');
pause(1);
%disp('
%.=========================================.
%|| / \ / \ ||
%|/=======================================\|
%||_______________________________________||
%|| ||
%|| _______________________________ ||
%|| / \ ||
%|| | | ||
%|| | | ||
%|| | | ||
%|| | | ||
%|| | | ||
%|| | | ||
%|\=======================================/|
%|| ||
%|| ||
%\=========================================/ ');
disp('...');
pause(.3);
disp('...');
pause(.3);
disp('...');
pause(.3);
%disp('
%.=========================================.
%|| / \ / \ ||
%|/=======================================\|
%|| ||
%||_______________________________________||
%|| ||
%||_______________________________________||
%|| ||
%||_______/__\_______________/__\_________||
%|| ||
%||_______________________________________||
%|| ||
%||_______________________________________||
%|\=======================================/|
%|| ||
%|| ||
%\=========================================/ ');
disp('Steel shutter is now closed.');
pause(1);
%disp('
%======================. .============.
% || || ||
%_____________________||___||___ ||
%______________________________/ ||
% || || ||
%===========((0)(0))==|/ \|__________|/
%');
pause(.3);
disp('Compacting...');
%disp('
%======================. .============.
% || || ||
%_____________________||___||___ ||
%______________________< < < < / ||
% || || ||
%===========((0)(0))==|/ \|__________|/
%');
pause(.3);
disp('...');
%disp('
%======================. .============.
% || || ||
%_____________________||___||___ ||
%___________ < < < < < < < < < / ||
% || || ||
%===========((0)(0))==|/ \|__________|/
%');
pause(.3);
disp('...');
%disp('
%======================. .============.
% || || ||
%_____________________||___||___ ||
%___< < < < << < < < < < < < < / ||
% || || ||
%===========((0)(0))==|/ \|__________|/
%');
pause(.3);
disp('...');
%disp('
%======================. .============.
% || || ||
%_____________________||___||___ ||
% < < < < < << < < < < < < < < / ||
% || || ||
%===========((0)(0))==|/ \|__________|/
%');
pause(.3);
disp('Done Compacting!');
disp('Compacted.');
pause(1);
%disp('
%======================. .============.
% || || ||
%_____________________||___||___ ||
%______________________________/ ||
% || || ||
%===========((0)(0))==|/ \|__________|/
%');
pause(1);
%disp('
%.=========================================.
%|| / \ / \ ||
%|/=======================================\|
%|| ||
%||_______________________________________||
%|| ||
%||_______________________________________||
%|| ||
%||_______/__\_______________/__\_________||
%|| _______________________________ ||
%||___| |___||
%|| | | ||
%||__/ \__||
%|\=======================================/|
%|| ||
%|| ||
%\=========================================/ ');
disp('Steel shutter is now opening...');
pause(.3);
disp('...');
pause(.3);
disp('...');
pause(.3);
disp('...');
pause(.3);
%disp('
%.=========================================.
%|| / \ / \ ||
%|/=======================================\|
%|| /=================================\ ||
%|| | | ||
%|| | | ||
%|| | | ||
%|| | | ||
%|| | | ||
%|| | | ||
%|| | | ||
%|| | | ||
%|| | | ||
%|\=======================================/|
%|| ||
%|| ||
%\=========================================/ ');
disp('Steel shutter is now open.');
pause(1);
%disp(' ____________________
% /| /|
% / | / |
% /#####,,,,,,,,,#####/ |
% /#,,,,,......#######/ |
% /######,,,, #####/ |
% /___________________/ /
% | | /
% | | /
% | | /
% | | /
% |___________________|/
% /');
H=1;
%disp(' ____________________
% /#####,,,,,..#######/|
% /,,,#########....###/ |
% /#####,,,,,,,,,#####/ |
% /#,,,,,......#######/ |
% /######,,,, #####/ |
% /#############,,,,,,/ /
% |~~~~~~~~~~~~~~~~~~~| /
% | | /
% | | /
% | | /
% |___________________|/
% /');
disp('Alert! Partially Full.');
disp(' ');
fprintf('Input Load(kg) = %f\n', Load2);
fprintf('Available Space(kg) = %f\n', SPACE);
%O=Load;
N1=0;
Load1=Load1;
end
if Load1>CAP
%disp(' ____________________
% /###################/|
% /###################/ |
% /###################/ |
% /###################/ |
% /###################/ |
% /###################/ /
% |~~~~~~~~~~~~~~~~~~~| /
% | | /
% | | /
% | | /
% |___________________|/
% /');
disp('Warning!FULL LOAD!');
disp('Warning! OVERLOAD!');
Load1=Load1-Load2;
SPACE=CAP-Load1;
N1=1;
end
end
end
end
if (sscanf(N,'%f'))==2
disp('Unloading...');
%disp('
%======================. .============.
% || || ||
%_____________________||___||___ ||
%______________________________/ ||
% || || ||
%===========((0)(0))==|/ \|__________|/
%');
pause(1);
disp('...');
%disp('
%.==============.
%||============||
%|| ___ ||
%|| / / ||
%|| / / ||
%\|___/ / ___|/
% / /
% / / ');
pause(1);
disp('...');
%disp('
% || ___ ||
% \|_/ /__|/
%======================./ /
% |/ /
%_____________________/ /
%> > > > > > > > > > > /
% ||
%===========((0)(0))==|/
%');
pause(1);
disp('...');
%disp('
%======================. .============.
% || || ||
%_____________________||___||___ ||
%____________> > > > > > > > > / ||
% || || ||
%===========((0)(0))==|/ \|__________|/
%');
pause(1);
%disp('
%======================. .============.
% || || ||
%_____________________||___||___ ||
%______________________________/ ||
% || || ||
%===========((0)(0))==|/ \|__________|/
%');
pause(1);
%disp(' ____________________
% /| /|
% / | / |
% / | / |
% / | / |
% / |______________/ |
% / / / /
% |~~~~~~~~~~~~~~~~~~~| /
% | | /
% | | /
% | | /
% |___________________|/
% /');
disp('Alert! The truck is now EMPTY.');
fprintf('Maximum Capacity(kg): %f\n', CAP);
fprintf('Free Space = %f\n', CAP);
Load1=0;
O=0;
L1=1;
Load=0;
end
if isempty(sscanf(N,'%f'))==1 || is_letter(sscanf(N,'%f'))==1 ||
(sscanf(N,'%f'))~=1 && (sscanf(N,'%f'))~=2 && (sscanf(N,'%f'))~=3;
disp('Warning! INVALID RESPONSE');
Load1=Load1;
L1=1;
end
if (sscanf(N,'%f'))==3
disp('Program Stopped.');
L1=-1;
end
L1=L1;
end
L1=L1;
if Load1==CAP
if G==H
%disp('
%.=========================================.
%|| / \ / \ ||
%|/=======================================\|
%||_______________________________________||
%|| ||
%|| _______________________________ ||
%|| / \ ||
%|| | | ||
%|| | | ||
%|| | | ||
%|| | | ||
%|| | | ||
%|| | | ||
%|\=======================================/|
%|| ||
%|| ||
%\=========================================/ ');
disp('...');
pause(.3);
disp('...');
pause(.3);
disp('...');
pause(.3);
%disp('
%.=========================================.
%|| / \ / \ ||
%|/=======================================\|
%|| ||
%||_______________________________________||
%|| ||
%||_______________________________________||
%|| ||
%||_______/__\_______________/__\_________||
%|| ||
%||_______________________________________||
%|| ||
%||_______________________________________||
%|\=======================================/|
%|| ||
%|| ||
%\=========================================/ ');
disp('Steel shutter is now closed.');
pause(1);
%disp('
%======================. .============.
% || || ||
%_____________________||___||___ ||
%______________________________/ ||
% || || ||
%===========((0)(0))==|/ \|__________|/
%');
pause(.3);
disp('Compacting...');
%disp('
%======================. .============.
% || || ||
%_____________________||___||___ ||
%______________________< < < < / ||
% || || ||
%===========((0)(0))==|/ \|__________|/
%');
pause(.3);
disp('...');
%disp('
%======================. .============.
% || || ||
%_____________________||___||___ ||
%___________ < < < < < < < < < / ||
% || || ||
%===========((0)(0))==|/ \|__________|/
%');
pause(.3);
disp('...');
%disp('
%======================. .============.
% || || ||
%_____________________||___||___ ||
%___< < < < << < < < < < < < < / ||
% || || ||
%===========((0)(0))==|/ \|__________|/
%');
pause(.3);
disp('...');
%disp('
%======================. .============.
% || || ||
%_____________________||___||___ ||
% < < < < < << < < < < < < < < / ||
% || || ||
%===========((0)(0))==|/ \|__________|/
%');
pause(.3);
disp('Done Compacting!');
disp('Compacted.');
pause(1);
%disp('
%======================. .============.
% || || ||
%_____________________||___||___ ||
%______________________________/ ||
% || || ||
%===========((0)(0))==|/ \|__________|/
%');
pause(1);
%disp('
%.=========================================.
%|| / \ / \ ||
%|/=======================================\|
%|| ||
%||_______________________________________||
%|| ||
%||_______________________________________||
%|| ||
%||_______/__\_______________/__\_________||
%|| _______________________________ ||
%||___| |___||
%|| | | ||
%||__/ \__||
%|\=======================================/|
%|| ||
%|| ||
%\=========================================/ ');
disp('Steel shutter is now opening...');
pause(.3);
disp('...');
pause(.3);
disp('...');
pause(.3);
disp('...');
pause(.3);
%disp('
%.=========================================.
%|| / \ / \ ||
%|/=======================================\|
%|| /=================================\ ||
%|| | | ||
%|| | | ||
%|| | | ||
%|| | | ||
%|| | | ||
%|| | | ||
%|| | | ||
%|| | | ||
%|| | | ||
%|\=======================================/|
%|| ||
%|| ||
%\=========================================/ ');
disp('Steel shutter is now open.');
pause(1);
end
%disp(' ____________________
% /###################/|
% /###################/ |
% /###################/ |
% /###################/ |
% /###################/ |
% /###################/ /
% |~~~~~~~~~~~~~~~~~~~| /
% | | /
% | | /
% | | /
% |___________________|/
% /');
disp('Alert! FULLY LOADED!');
disp(' ');
disp('Unload All: type [1] then ENTER');
disp('Terminate the Program: type [2] then ENTER');
BF=input('Input response: ', 's');
if (sscanf(BF,'%f'))==1
disp('Unloading...');
%disp('
%======================. .============.
% || || ||
%_____________________||___||___ ||
%______________________________/ ||
% || || ||
%===========((0)(0))==|/ \|__________|/
%');
pause(1);
disp('...');
%disp('
%.==============.
%||============||
%|| ___ ||
%|| / / ||
%|| / / ||
%\|___/ / ___|/
% / /
% / / ');
pause(1);
disp('...');
%disp('
% || ___ ||
% \|_/ /__|/
%======================./ /
% |/ /
%_____________________/ /
%> > > > > > > > > > > /
% ||
%===========((0)(0))==|/
%');
pause(1);
disp('...');
%disp('
%======================. .============.
% || || ||
%_____________________||___||___ ||
%____________> > > > > > > > > / ||
% || || ||
%===========((0)(0))==|/ \|__________|/
%');
pause(1);
%disp('
%======================. .============.
% || || ||
%_____________________||___||___ ||
%______________________________/ ||
% || || ||
%===========((0)(0))==|/ \|__________|/
%');
pause(1);
%disp(' ____________________
% /| /|
% / | / |
% / | / |
% / | / |
% / |______________/ |
% / / / /
% |~~~~~~~~~~~~~~~~~~~| /
% | | /
% | | /
% | | /
% |___________________|/
% /');
disp('Alert! Done Unloading.');
disp('EMPTY!');
fprintf('Maximum Capacity(kg): %f\n', CAP);
fprintf('Free Space = %f\n', CAP);
Load1=0;
L1=1;
Load=0;
end
if isempty(sscanf(BF,'%f'))==1||is_letter(sscanf(BF,'%f'))==1||(sscanf(BF,'%f'))~=1
&& (sscanf(BF,'%f'))~=0 && (sscanf(BF,'%f'))~=2;
disp('invalid response');
L1=1;
H=0;
end
if (sscanf(BF,'%f'))==2
disp('Program Stopped');
quit;
L1=0;
end
end
L1=L1;
end
end