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
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;
years2double = log(2)./log(1+intRates);