MATLAB: How to create a while loop that can determine how many years do you have to invest $100000 at a compound interest of 5% per year to double your money

compound intrestMATLABwhile loops

I need help basically doing the same thing in the picture I have attached but using a while loop.

Best Answer

Amount = 100000 ;
Amount0 = Amount ;
yr = 0 ;
while Amount <= 2*Amount0
yr = yr+1 ;
Amount = Amount*1.05 ;
fprintf('Amount at year %d is %.2f\n',yr,Amount)
end