Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- x = 1
- e = 0.01
- n = 100
- def f(x):
- return (1/2)*((x-1)**3)-2*(x-1)
- # def df(x,ea):
- # h = 0.5
- # return (f(x + h * ea) - f(x - h * ea)) / ea
- def df(x):
- return 3/2*((x-1)**2) - 2
- def rozw(r,ea,iter):
- for k in range (0,iter):
- r0 = r
- r = r - f(r) / df(r)#df(r,ea)
- er = abs((r-r0)/r)*100
- print(f"\n\n{r} {er}\n\n")
- if er < ea:
- break
- return r,er,k
- x0,err,k = rozw(x,e,n)
- print(f'x = {x}\n x0 = {x0}\nerr = {err}\nk = {k}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement