1. Udeme Eyoh
Question:
The electrical accounts of residents in a very small rural community are calculated
as follows:
if 500 units or less are used the cost is 2 cents per unit;
if more than 500 units but less than 1000 units are used, the cost is $10 for the first
500 units, and 5 cents for every unit in excess of 500;
if more than 1000 units are used, the cost is $35 for the first 1000 units plus 10
cents for every unit in excess of 1000; in addition, a basic service charge of $5 is
applicable for all users.
the five residents use the following amounts (units) of electricity in a certain
month: 200, 500, 700, 1000 and 1500. write a MATLAB program using logical
vectors to calculate how much they must pay. display the results in two columns:
one for electricty used in case and the other amount owed.
solution
clc
disp(['PROGRAM TO CALCULATE ELECTRICITY BILL'])
disp(['Compiled By Udeme Eyoh'])
disp(['----------------------------------------------------------- '])
disp([' '])
units = [200,500,700,1000,1500];
for x = 1:5
2. if units(x)<=500;
bill = (0.02*units(x)+5);
elseif units(x)>500 && units(x)<1000;
bill = ((units(x)-500)*0.05+10+5);
else bill = ((units(x)-1000)*0.1+35+5);
end
disp(['UNITS= ',num2str(units(x)),' BILL = Dallars',num2str(bill)])
end