def y(x, a):
return (x**2 - a) ** 2
def dy_dx(x, a):
return 2 * (x**2 - a) * 2 * x
def dx(x, a, alpha):
return - dy_dx(x, a) * alpha
import numpy as np
x = np.random.uniform(0.1, 2)
for _ in range(1000):
x += dx(x, 2, 0.01)
print(x)
D:\Anaconda\python.exe D:/AI20/06_codes/deeplearning_20/p14_sqrt.py
1.4142135623730956
Process finished with exit code 0