Could someone please point out the error in my code?

조회 수: 1 (최근 30일)
Subramanian Mahadevan
Subramanian Mahadevan 2016년 10월 16일
댓글: Subramanian Mahadevan 2016년 10월 17일
Write a function called income that takes two row vectors of the same length as input arguments. The first vector, rate contains the number of various products a company manufactures per hour simultaneously. The second vector, price includes the corresponding per item price they sell the given product for. The function must return the overall income the company generates in a week assuming a 6-day work week and two 8-hour long shifts per day.
This was my code:
function [x] = income( rate,price )
c = 0;
d = 0;
rate = [1 1];
price = [2 3];
d = rate.*price;
c = sum(d);
x = 96*c;
end
  댓글 수: 1
John D'Errico
John D'Errico 2016년 10월 16일
Please learn to format your code so it is readable.
1. Select the block of code as you pasted it in.
2. Click on the "{} Code" button.
Done for you today.

댓글을 달려면 로그인하십시오.

채택된 답변

Marc Jakobi
Marc Jakobi 2016년 10월 16일
If you want to find out if it is correct, look at the units. What you want as a result is currency, let's say £.
rate = units/h
price = £/unit
rate.*price = £/h
96 h .* rate.*price = h*£/h = £.
Everything is correct. The only thing I would point out is that you don't have to initialize c = 0 or d = 0.
And why are you defining rate and price within the function? take the lines
rate = [1 1];
price = [1 2];
out or the result will be the same, no matter what the user inputs.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by