My Question in Matlab program is : * (Use if - else, for loop and vectors) The e
ID: 3631318 • Letter: M
Question
My Question in Matlab program is :* (Use if - else, for loop and vectors)
The electricity accounts of residents in a small town are calculated as follows:
a. If 500 units of fewer are used, the cost is 2 cents per unit.
b. If more than 500 but no more than 1000 units are used, the cost is $10 for the
First 500 units and 5 cents for every unit in excess of 500.
c. 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.
d. A basic service fee of $5 is charged, no matter how much electricity is used.
Write a program that enter the following five data into a vector and uses a for loop to calculate and display the total charges for each one: 200, 500, 700, 1000, 1500.
Explanation / Answer
Here is the exact code: clear;clc; x = [200, 500, 700, 1000, 1500]; cost = zeros(1,numel(x)); for i = 1:numel(x) if x(i) 500 & x(i) 1000 cost(i) = 5 + 35 + (x(i)-1000)*0.10; end end for j = 1:numel(x) fprintf('Cost no. %d: $%.2f ',j,cost(j)); endRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.