Info

This question is closed. Reopen it to edit or answer.

Basic Looping Help Please?

1 view (last 30 days)
Darren
Darren on 19 Sep 2014
Closed: MATLAB Answer Bot on 20 Aug 2021
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

Answers (1)

Rick Rosson
Rick Rosson on 19 Sep 2014
Try using a while loop instead of a for loop.

Tags

Community Treasure Hunt

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

Start Hunting!