title: Taylor expansion in python
body: <p>How do I calculate and print out the value of ln(1+x) using the series expansion:</p>
  
  <p>ln(1+x) expansion</p>
  
  <p><a href="https://i.stack.imgur.com/ia3DQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ia3DQ.png" alt="enter image description here"></a></p>
  
  <p>using a while loop and including terms whose magnitude is greater than 10-8. Print out the sum to each number of terms to show the result converging.</p>
  
  <p>So far this is my code but it calculates lnsum2 to be a very large number and hence never ends. </p>
  
  <pre><code>n=1 
  lnsum2= np.cumsum((((-1)**(n+1)*(x**n)/n))) 
  while lnsum2&gt;10**-8: 
         n+=1 
         lnsum2 = lnsum2 + np.cumsum((((-1)**(n+1)*(x**n)/n))) 
  else: print('The sum of terms greater than 10^-8 is:', lnsum2)
  </code></pre>
  
  <p>Many thanks.</p>
  
  <p>Right I've now got code that works using a while loop. Thanks for all the help!!</p>