Calculating the maintenance costs over (x) amount of years
2 ビュー (過去 30 日間)
古いコメントを表示
Hey forum This is my first time using Mat-lab and the forums. I have been having trouble with both the conceptual aspect, Mat-lab syntax and the debugging the final solution the problem.
The question is asked as follows
A machine requires $2,000 in maintenance every 2 years, $3,500 maintenance every 5 years, and a major overhaul costing $11,300 every 7 years. Use a for-loop to determine the accumulated maintenance costs of the machine over the next x years. Assume that you are starting at Year 0 (i.e. first expense occurs at Year 2). Ex. accumYears(5) = 7500
Here is my attempt at a solution function
function sum = accumYears(x)
for i = 1:1:x
[q, r] = quorem(i,sym(2));
if r == 0
a(i) = 2000;
end
[q, r] = quorem(i,sym(5));
if r == 0
a(i) = a(i) + 5000;
end
[q, r] = quorem(i,sym(7));
if r == 0
a(i) = a(i) + 11300;
end
end
sum = sum(a);
end
I receive the error Undefined function or variable "sum".
Error in faccumYears (line 16) sum = sum(a);
0 件のコメント
回答 (2 件)
MA
2014 年 11 月 22 日
sum is a built-in matlab function, you should name your function or matric something else like cost
cost = accumYears(x)
cost = sum(a)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Data Type Identification についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!