Untitled

 avatar
unknown
python
4 years ago
424 B
4
Indexable
import sys


def function(x):
    return 4 * x ** 4 - 4 * x ** 3 - 24 * x ** 2 + 16 * x + 52
    
def gradient(x):
    return 16 * x ** 3 - 12 * x ** 2 - 48 * x + 16

def gradient_2(x):
    return 48 * x ** 2 - 24 * x - 48

x0 = -sys.maxsize - 1
temp = x0 - gradient(x0) / gradient_2(x0)
while abs(temp - x0) > 1e-14:
    x0 = temp
    temp = x0 - gradient(x0) / gradient_2(x0)
    
print(x0, function(x0))
Editor is loading...