Try using a while loop instead of a for loop.
Info
此问题已关闭。 请重新打开它进行编辑或回答。
Basic Looping Help Please?
1 次查看(过去 30 天)
显示 更早的评论
Problem: Need to reach a downpayment of $50,000. Have 2,000 dollars already. ROI is 4%. Inflation is 2.5%. Need to calculate present value and future value of money saved and need to figure out how long both will take in years. So Future Value = (Money Saved*ROI) + Money added. I add $10,000 a year. So the "money saved" is what changes every year. Present Value = Future Value/(1+inflation)^years
Heres my code I currently have for that portion:
for i = 1:length(years)
if (amount_start_with < amount_needed_present_dollars);
future_value(i) = amount_start_with*(1/ROI*100) + amount_add_every_year;
present_value = future_value./(1 + inflation).^years
end
end
So I have 2 weeks experience with matlab so I have little idea as to what I'm doing. I defined the input variables as the amount_start_with, etc. I keep getting errors that I'm not defining "years". The problem is I don't know how many years it will take to reach the goal for the downpayment. I also got an error about matrix dimensions. Also should the "years" in my present_value equation be defined as the same as I have in the first line? Please Help
0 个评论
回答(1 个)
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!