Problems
Loading...
1 / 1

Implement Gradient Descent for a 1D Quadratic

Optimization
Easy

Implement vanilla gradient descent to minimize a 1-D quadratic:

f(x)=ax2+bx+cf(x) = ax^2 + bx + c
Loading visualization...

Examples

Input: a = 1, b = -4, c = 3, x0 = 0, lr = 0.1, steps = 50

Output: ≈ 2.0

Input: a = 0.5, b = -1, c = 0, x0 = -5, lr = 0.2, steps = 100

Output: ≈ 1.0

Hint 1

Use a loop to update x repeatedly.

Requirements

  • Use the update:x=xlrf(x)x=xlrf(x) x=x−lr⋅f′(x)x=x−lr⋅f′(x) repeated steps times (where lr is the learning rate)
  • Do not use the closed-form minimizer during updates
  • Return a Python float (not list/array)
  • Assume a > 0, lr > 0, steps >= 1

Constraints

  • Time limit: 200 ms; Memory: 64 MB
  • Pure Python / NumPy (no ML libs)
Try Similar Problems