As a hint, I might wonder if your instructor expected this problem, perhaps this is why the problem was assigned?
Your formula for the series seems at a quick glance correct. However, you might consider if that series is convergent for x = 2.71828...
That is, will terms that look like
ever approach zero? Or, is it possible that those terms do blow up, as you have seen? What does that tell you about the values of x for which this series will be convergent?
Note that there are ways to repair this problem, most notably via transformations. For example, a simple idea is if x > 1, then what is the value of -ln(x)? Consider the transformation
Now the terms in your series will look like
Clearly they will approach zero. I'm too lazy to write a loop, so consider this:
N = (1:25)';
S = cumsum((mod(N,2)*2-1).*(u-1).^N./N)
S =
-0.63212
-0.83191
-0.9161
-0.95602
-0.9762
-0.98684
-0.9926
-0.99578
-0.99757
-0.99859
-0.99918
-0.99952
-0.99971
-0.99983
-0.9999
-0.99994
-0.99996
-0.99998
-0.99999
-0.99999
-1
-1
-1
-1
-1
When you negate the above result, that simply recovers our hoped for value for log(exp(1)).
So when you see a problem with a series like this, consider not only if your formula is correct, but if there are other considerations one must satisfy for that formula to be of any use. Here, convergence radius is what matters.
Best Answer