I am trying to calculate how many years it would take to save a million dollars given certain expenses and wage. Also, my rent increases $200 every 5 years and my salary increases 2% annually. Here is my code:
% input statements
monthlyWageAfterTaxes = 2700
savingsGoal= 1E6
%Expenses
rent=800;
utilities=300;
insurance=200;
auto=250;
food_misc=325;
totalSavings=0;
numMonths=0;
while totalSavings < savingsGoal
if rem(numMonths,60)==1;
rent = rent + 200;
end
if rem(numMonths,12)==1;
monthlyWageAfterTaxes = monthlyWageAfterTaxes * 1.02;
end
monthlyBills= rent+utilities+insurance+auto+food_misc;
totalSavings = totalSavings + monthlyWageAfterTaxes - monthlyBills
numMonths= (numMonths+1)
end
numYears=(numMonths/12)
I worked out the problem by hand and came up with 48.1667 years, but the code gives me 49.8333. Can anyone see what might be the problem because I have been trying to debug it for 3 days now. Thanks.
Problem with calculations in MATLAB while loop
Page 1 of 11 Replies - 958 Views - Last Post: 05 November 2012 - 09:36 PM
Replies To: Problem with calculations in MATLAB while loop
#2
Re: Problem with calculations in MATLAB while loop
Posted 05 November 2012 - 09:36 PM
Should there be a semicolon after the if expessions?
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|