Matlab got this wrong: Limit as n goes to infinity: (1+(i/n))^(n^2). Matlab says it's exp(2), which is wrong. Pls confirm.

Matlab got this wrong: Limit as n goes to infinity: (1+(i/n))^(n^2). Matlab says it's exp(2), which is wrong.

13 Comments

I'm sorry. But we don't send you e-mail. That is not how Answers works. You will need to look to see if an answer is posted. And it is MATLAB, not Mathlab.
Anyway, are you saying the SUM over i? What are the limits of that sum? Where does i start? At 0?
We are still unsure what i is. Can you post how you calculated this in MATLAB?
i is the imaginary number.
>> limit((1 + (i)/n)^(n^2), n, inf)
ans =
exp(2)
Not sure why your last your last response and my follow up response was deleted. I am simply reporting a potential factual error, no harm or malice intended.
@Moses, I'm not sure what were deleted. But I can help you to recreate what you observed.
syms n
limit((1 + (1i)/n)^(n^2), n, inf)
ans = 
@Moses, do you think this should be correct in your view ?
syms n
limit(((1 + (1i)/n)^(n).^2), n, inf)
ans = 
@VBBV Thank you for your response. Your modified expression and the solution you presented is correct in my view. However, that is not equivalent to the expression I presented. I hope you understand.
You've made so many edits, but I'm still not sure what you're summing over i or n. Is it summing over n and i is just the imaginary constant sqrt(-1)?
Hi @Moses, Would you clarify which one is the expression that you are investigating?
syms n
expr1 = (1 + (1i)/n)^(n^2)
expr1 = 
expr2 = (1 + (1i)/n)^(n).^2
expr2 = 
@Image Analyst. Thanks for your response. Yes i is the imaginary number.
>> limit(((1 + (1i)/n)^(n*n)), n, inf)
ans =
exp(2)
The expression is a LEGITIMATE math expression, which should have a consistent intepretation.
For examble, when I did:
>> limit(((1 + (i)/n)^(n)), n, inf)
ans =
exp(1i)
MATLAB got that one correct as exp(i).
say, 1 is growing by i/n, and this happens over n times.
But in limit(((1 + (i)/n)^(n*n)), n, inf), 1 is growing by i/n, and this happens over (n^2) or (n*n) times. MATLAB said the answer was exp(2) which is not correct. I hope that makes sense.
@Moses if you are investigating the expr1 as given by @Sam Chak, then from the standard form of limit, defined for n, your expression should be
syms n
limit((1 + (1i)/n^2)^(n^2),n,inf)
ans = 

Sign in to comment.

More Answers (2)

Hi Moses,
not every expression has a limit, or should. That's the case here, as anyone can check. For large n the function zips around (nearly) a circle, and it's interesting that the circle is not the unit circle but has, for large n, radius e^(1/2) = 1.6487 as a limit.
The plot below brings up a question: why do the lines connecting the points stay near the perimeter of the circle? It seems like the line connecting point n to point n+1 could cut across the circle, but it doesn't happen. This suggests a large-n limit for the angle between point n and point n+1 and that is correct, with a value of 1 radian.
The finite limit e^2 is an error as you said.
n = 1:100;
y = (1+i./n).^(n.^2);
plot(y) % complex plane

3 Comments

@David Goodmanson Thanks for your response, and for seeing that MATLAB's output, i.e., exp(2) is wrong. This is why this community is vital, so critical mathematical bugs can be reported and fixed. No harm or malice intended. It would have been better if MATLAB gave an output of NaN (if it cannnot compute it), than to give a defintive wrong answer. Since many important engineering and scientific operations (e.g., space rockets) compute limits involving complex numbers and exponents, this mathmatical error could potentiall cause serious problems.
Actually, the correct answer is straightforward, it just requires some deep insight on the nature of limits when complex numbers or exponents are involved. The limit does NOT converge to a single value. Instead, it oscillates on the unit circle in the complex plane, taking on values of the form cos(n) + isin(n). So e.g., one of the answers is 1, but never exp(2).
I hope this information can give the developers insight on fixing it.
WolframAlpha returns the expression without modifications. This could either indicate that the software was not able to compute it or (what would be the correct answer) that the limit does not exist.
Hi Moses,
the function does move around a circle in the complex plane, but it is not the unit circle. See the direct numerical calculation in the answer above.
The absolute value of the function is
(abs(1+i/n))^(n^2)
= (sqrt(1+1/n^2))^(n^2)
= ((1+1/n^2)^(1/2))^(n^2)
= ((1+1/n^2)^(n/2))^(1^2) % since (x^a)^b = (x^b)^a = x^(ab)
and since
limit m-->inf (1+1/m)^m = e
the result, which is the radius of the circle, is e^(1/2) as stated in the answer.

Sign in to comment.

I have been looking at this for a couple of days now and have finally convinced myself that this limit doesn't exist and MATLAB is in error. Since you are raising a complex number to a potentially fractional power in this limit expression, and such operations are multi-valued for complex numbers, I would question whether the limit should exist at all simply on that basis. But suppose we restrict ourselves to integer n to avoid that discussion. Start with this expression:
(1 + i/n) ^ (n^2)
Extract the magnitude of the inner part so we are left with the form ( r * u ) ^ (n^2) where u is a unit complex number:
[ sqrt(1 + 1/n^2) * (1 + i/n) / sqrt(1 + 1/n^2) ) ] ^ (n^2)
Separate the magnitude out:
sqrt(1 + 1/n^2) ^ (n^2) * [ (1 + i/n) / sqrt(1 + 1/n^2) ) ] ^ (n^2)
Rewrite the magnitude part using 1/2 exponent instead of sqrt():
[ (1 + 1/n^2) ^ (1/2) ] ^(n^2)
Rearrange:
[ (1 + 1/n^2) ^ (n^2) ] ^(1/2)
The limit of the inside part is clearly e, so we have the magnitude converging to:
e^(1/2)
Now for the unit complex number part, we have a point on the complex unit circle raised to a positive integer power, so the result will clearly also be on the complex unit circle. The question is, does this converge to a particular point or not? To examine that, consider the triangle where it came from and just examine the angle of this triangle:
The angle x associated with our unit complex number is the same as the original triangle it came from, so we have:
tan(x) = (1/n) / 1 = 1/n
So
x = atan(1/n)
The taylor series for atan() is:
syms y
taylor(atan(y))
ans = 
So for small angles we can just use y, or in our case 1/n.
Since our complex unit vector is raised to the power n^2, we can just multiply that by our small angle to get the expected resulting angle:
(1/n) * n^2 = n
Thus, as n -> infinity, the angle grows without bound.
In conclusion, although the magnitude of the original expression converges to e^(1/2), the angle does not converge, hence the overall limit does not converge. For large n, with a magnitude of e^(1/2) and an angle of n, the original expression (1 + 1i/n)^(n^2) will be pretty close to:
exp(1/2) * (cos(n) + 1i * sin(n)) = exp(1/2 + 1i * n)

15 Comments

@James Tursa You are right, it does not converge to any point on the circle, and the angle grows without bound. However, in my calculation, it is a point on the unit circle. In my calculation, It oscillates on the unit circle in the complex plane, taking on values of the form cos(n) + isin(n). So e.g., one of the answers is 1, but never exp(2).
It turns out MATLAB have many of these errors, not just this one instance. I have informed the technical support. Hopefully, it is a small error, and not affecting their underlying mathematical engine. Thanks alot!
@Moses A test of my conclusion that the result will be close to being on a circle of radius exp(1/2) with angle n for "large" n:
format longg
n = 1e2;
[(1+1i/n)^(n^2)
exp(1/2 + 1i * n)]
ans =
1.41889741827874 - 0.839568962759479i 1.42172346686685 - 0.834855803249367i
n = 1e4;
[(1+1i/n)^(n^2)
exp(1/2 + 1i * n)]
ans =
-1.56985559566496 - 0.503820612826649i -1.56983880865995 - 0.503872943592082i
n = 1e6;
[(1+1i/n)^(n^2)
exp(1/2 + 1i * n)]
ans =
1.5444531069629 - 0.57704603671085i 1.54444315803749 - 0.577041731636642i
n = vpa(1e8);
[(1+1i/n)^(n^2)
exp(1/2 + 1i * n)]
ans = 
n = vpa(1e10);
[(1+1i/n)^(n^2)
exp(1/2 + 1i * n)]
ans = 
n = vpa(1e12);
[(1+1i/n)^(n^2)
exp(1/2 + 1i * n)]
ans = 
Looks like a good match to me. What did you find wrong with my derivation? How did you determine the result should be on the unit circle?
P.S. It may be of interest to readers for you to post other examples of MATLAB erroneous limit results. Maybe edit your original post and include them?
How did you determine the result should be on the unit circle?
Maybe like
(1+1i/n)^(n^2) = ((1+1i/n)^n)^n ~ exp(1i)^n = exp(1i*n) = cos(1i*n) + 1i*sin(1i*n)
(which is of course wrong).
@James Tursa. Thanks for your note. @Torsten. But, how is this wrong ?
exp(i)^n
= exp(i*n)
= cos(n) + i*sin(n)
Which line is wrong?
Anyways, the tech support is now moving to fix the underlying issue that caused the error in MATLAB, which was my aim of bringing this to their attention.
Which line is wrong?
You cannot let the "inner n" approach infinity and leave the "outer n" unchanged here:
((1+1i/n)^n)^n ~ exp(1i)^n
@James Tursa and @Torsten. Thanks for your comment. However, I still feel very confident in my analysis due to my insights in the infinitesimal behavior of complex functions. So now, I am very curious and looking forward to the solution the MATLAB technical developers ultimately put in their code fix. I am sure they will do a ton of testing and verification to make sure their solution is right. Thanks a lot!
What do you expect ? The limit does not exist, thus even with a bug fix, MATLAB will most probably just return the limit expression unchanged.
@Torsten. Instead of saying the limit "does not exist", a better way to say it is: that there are "many" possible answers to the expression. A reputable tool like MATLAB can output one of these answers, which will be satisfactory. As is currently done in Wolfram Mathematica.
E.g., the cube root of 8 has 3 answers, but an answer of 2 is correct/satisfactory.
For our case, we all agree the limit is a point on circle. The bone of contention is the radius of such circle. So say the radius is exp(1/2) as @James Tursa said, then MATLAB can output exp(1/2), which is one of the answers. exp(1/2 + i.pi) is another answer, and so on. I hope you see point in what I am saying, but suppose MATLAB just returns back the limit as you suggested, its still better than the current exp(2) answer being outputed by MATLAB. Anyways, its all good, I love the conversation and I have learned a lot here. We just want our math tools to give us correct answers.
The only statement I agree with is
suppose MATLAB just returns back the limit as you suggested, its still better than the current exp(2) answer being outputed by MATLAB.
How can there be many possible answers for a limit of a sequence?
From "Complex Variables and Applications" by Churchill and Brown:
"a limit [of a sequence] is unique if it exists."
@Moses " ... For our case, we all agree the limit is a point on circle ..."
No, we don't agree at all with this statement. The limit does not exist, period. That is the best way to say it. There are not many possible answers in this case that MATLAB can pick from and return one of them, because there are no possible answers. The limit of the magnitude of the expression exists and is exp(1/2), but the limit of the expression does not exist. You could say that there is a limiting asymptotic-like behavior to the sequence, but the limit itself does not exist. In order for a limit of a function or sequence to exist in general, the expression has to get arbitrarily close to the limit L for large enough n. For every ϵ > 0, there must exist an N > 0 such that |f(n)-L| < ϵ for all n > N (emphasis on the all). Clearly that cannot be satisfied in this case. E.g., you suggested exp(1/2) is one of the "possible answers" that MATLAB could return for this limit. For that to be true, the expression must remain arbitrarily close to exp(1/2) for all large enough n. But we know this is not the case. Suppose I pick ϵ = 1/2 and we managed to find a value of n such that the expression was very close to exp(1/2) for this n. Then we know that the expression for n+1 is going to be about 1 radian away from this in angle near a circle of radius exp(1/2), clearly violating our ϵ = 1/2. It doesn't matter how large n is, we know the distance to the next number in the sequence is going to be approximately the length of a chord of radius exp(1/2) and angle 1 radian away from it (much larger than our ϵ = 1/2):
exp(1/2) * 2 * sin(1/2)
ans = 1.5809
A graph of the first million differences flatlines and never gets small:
n = 1:1e6;
z = (1 + 1i./n) .^ (n.^2);
plot(abs(diff(z)));
The expression just keeps spinning around the circle of radius exp(1/2) as n increases. The only correct thing for MATLAB to do is return something that indicates this, e.g., NaN if it can verify that the limit does not exist or just return the expression indicating that it doesn't know. Any tool that indicates a limit exists for this is just plain wrong.
Your cube root of 8 example where there are three possible answers is not a valid comparison to this limit problem. Even if you were to pick an example where there are an infinitely number of possible solutions and MATLAB returns one of them as the answer (e.g., not full rank linear algebra problem, complex number raised to fractional power, etc.), that still would not be a valid comparison to the limit problem above. The following is a valid comparison to the limit problem above:
What is the limit of the following sequence? +1, -1, +1, -1, +1, -1, ...
According to your reasoning, there are two possible valid answers, +1 and -1, and we can pick one for our answer. But this is clearly incorrect. There is no answer to this problem. The limit doesn't exist. The sequence never converges. The sequence never gets arbitrarily close to either +1 or -1 no matter how far in the sequence you go. MATLAB figures this out in this case:
syms n
limit( (-1)^n, n, inf )
ans = 
NaN
And if we feed MATLAB our approximate expression, it figures that one out too:
limit( exp(1/2 + 1i * n), n, inf )
ans = 
NaN
For those who are interested:
My conjecture for the case given is that each point on the circle with radius exp(1/2) is an accumulation point of the sequence
z_n = (1 + 1i/n)^(n^2)
which means that given a point z* = exp(1/2)*exp(i*phi) on the circle, there exists a subsequence z_n_k such that z_n_k -> z* for k -> Inf.
@Torsten Yes I did find that link interesting! And I suspect you are correct as it probably wouldn't be too hard to massage the proof in that link to fit our case (e.g., pick n large enough so that magnitude being close to exp(1/2) is sufficiently < ϵ and then copy the rest of the proof from there). As a consequence, it is also interesting that even though the original set (sequence of points) is countable (since they map to the positive integers), the set of all subsets must be uncountable since a portion of them map to a real dense set of points.
As a consequence, it is also interesting that even though the original set (sequence of points) is countable (since they map to the positive integers), the set of all subsets must be uncountable since a portion of them map to a real dense set of points.
Yes, like the rationals are dense in the reals. Each element of the uncountable set of reals can be approximated by the countable set of the rationals with arbitrary precision.

Sign in to comment.

Tags

Asked:

on 22 May 2024

Edited:

on 27 May 2024

Community Treasure Hunt

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

Start Hunting!