How many years to double initial investment with various interest rates

1 view (last 30 days)
S = P(1+i)^n
trying to create a table that shows interest rates and how many years too double

Answers (1)

David K.
David K. on 2 Aug 2019
If I understand the equation you posted correctly lets walk through this. S = total amount after n years if P was initially invested at i interest rate.
So first off we want this equation to be n = function of i.
To get rid of P and S we state that P needs to be double so S = 2P and if we divide P over we get the equation
2P = P(1+i)^n
2 = (1+i)^n
Now we take the log of both side, I am going to use the natural log, ln, because Matlab's basic log function is actually the natural log. Then use a log property that lets me remove the exponent and then divide to both sides:
ln(2) = ln((1+i)^n)
ln(2) = n*ln(1+i)
n = ln(2)/ln(1+i)
Now that we have an equation we can put it into Matlab for various interest rates
intRates = .01:.01:.20; % array Interest rates from 1 to 20%
years2double = log(2)./log(1+intRates); % Calculate years to double
% This will create a table with whatever names you want
table(intRates',years2double','VariableNames',{'intRates','years2double'})
% Here is a plot if you want that
plot(intRates,years2double)

Categories

Find more on Variables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!