```python
from sympy import *
import numpy as np
from matplotlib import pyplot as plt

x = Symbol('x')

# Function
y = x**2
# First derivative with respect to x
yprime = y.diff(x)


# Initial sequence
theta = 2
theta2 = 0

# Initiale the step size
alpha = .001

iterations = 0
check = 0
precision = 1/100000
iterationsMax = 100000

while True:
    theta2 = theta - alpha*yprime.evalf(subs={x:theta})
    iterations += 1
    
    # If we make too much iterations our program
    # stops and we need to check it to be sure the
    # parameters are correct and it is working properly
    if iterations > iterationsMax:
        print("Too many iterations")
        break
        
    if abs(theta - theta2) < precision:
        break
    
    theta = theta2


print("Number of iterations:",iterations,"value of theta:",theta2,sep=" ")
plt.plot(theta,y.evalf(subs={x:theta}),marker='o',color='r')
space = np.linspace(-5,5,100)
data = np.array([y.evalf(subs={x: value}) for value in space])
plt.plot(space, data)
plt.show()

```


```python

```

0361b23a28d37973896a1d899b465b06865f3814
ipynb
Jupyter Notebook
NotesAndTutorials/Gradient_univ.ipynb
ChristopherDaigle/ConvexOptimizationWithPython
b7a1b5126b076d06ec03e906b19930bf324272ff
Unlicense
NotesAndTutorials/Gradient_univ.ipynb
ChristopherDaigle/ConvexOptimizationWithPython
b7a1b5126b076d06ec03e906b19930bf324272ff
Unlicense
NotesAndTutorials/Gradient_univ.ipynb
ChristopherDaigle/ConvexOptimizationWithPython
b7a1b5126b076d06ec03e906b19930bf324272ff
Unlicense
Qwen/Qwen-72B
1. YES
2. YES