Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def f(x):
- return 4*x - 1.8*x*x + 1.2*x*x*x + - 0.3*x*x*x*x
- def f_prime(x):
- return -1.2*x*x*x + 3.6*x*x - 3.6*x + 4
- def f_prime_prime(x):
- return -3.6*x*x + 7.2*x - 3.6
- def newton(x0, max_error, iterations):
- x = x0
- error = 1
- ite = 0
- while error > max_error and ite < iterations:
- temp = x
- x = x - f_prime(x) / f_prime_prime(x)
- ite += 1
- error = abs(x - temp) / x
- return [x, f(x), error, ite]
- res = newton(0, 1e-2, 100)
- print('The maximum of function f(x) is', res[1], 'at x =', res[0])
- exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement