Problems
Loading...
1 / 1
Implement Gradient Descent for a 1D Quadratic
Implement Gradient Descent for a 1D Quadratic
Optimization
Easy
Implement vanilla gradient descent to minimize a 1-D quadratic:
f(x)=ax2+bx+cLoading 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=x−lr⋅f′(x)x=x−lr⋅f′(x) repeated
stepstimes (wherelris 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
Log in to take notes on this problem
Case 1
Case 2
Accepts: number
Accepts: number
Accepts: number
Accepts: number
Accepts: number
Accepts: number
You must run your code first.
Implement Gradient Descent for a 1D Quadratic
Implement Gradient Descent for a 1D Quadratic
Optimization
Easy
Implement vanilla gradient descent to minimize a 1-D quadratic:
f(x)=ax2+bx+cLoading 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=x−lr⋅f′(x)x=x−lr⋅f′(x) repeated
stepstimes (wherelris 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
Log in to take notes on this problem
Case 1
Case 2
Accepts: number
Accepts: number
Accepts: number
Accepts: number
Accepts: number
Accepts: number
You must run your code first.