Python Forum
While loop - series expansion
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
While loop - series expansion
#1
Hello folks,

I've put together the following code for a series expansion for the function ln(1+x):

import numpy as np


x = float(input('Please input a number x between 0 and 1 '))
logx = np.log(x+1)
while x<=0 or x>=1:
    float(input('Please input a number between 0 and 1 '))
    
for n in range(1, 13):
    term1 = x
    term = ((-1)**(n+1))*(x**n)/n
    term1 += term
print('The sum of the Taylor expansion for ln(1+x) upto x^12 is: ', term1)
I'm stuck on the following task:

calculate and print out the value of ln(1 + x) calculated using the above series expansion using a while loop and including all terms whose magnitude are bigger than 10−8. Print out the sum to each number of terms.

Can anyone help explain how to do this?
Reply


Messages In This Thread
While loop - series expansion - by StillAnotherDave - Dec-17-2019, 06:37 PM
RE: While loop - series expansion - by ibreeden - Dec-18-2019, 06:35 PM
RE: While loop - series expansion - by scidam - Dec-19-2019, 01:50 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] How to ask Smart Questions (thread title expansion) saifalikhan9 0 441 Feb-17-2024, 11:57 AM
Last Post: saifalikhan9

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020