Neural Mastery
← Practice
Newton-Raphson Optimization Stepmedium

Newton-Raphson Optimization Step

medium Math for ML 10-15 min

NumPy allowed · plain Python earns 10 bonus points

Linear algebra step 1/4

A vector transforms

Matrix multiplication is the first computation behind every model.
Open lesson →
01vector
02matrix
03transform
04result
[2, −1] × [[1, 2], [−.5, 1]] = [0, −2]

Computed matrix × vector transformation

Execute a second-order Newton-Raphson optimization step.

Related Skills

Task

Implement newton_raphson_step(x, f_prime, f_double_prime): calculate x_next = x - f_prime / f_double_prime. If abs(f_double_prime) < 1e-9, return x unchanged. Return float rounded to 4 decimals.

Function Signature

newton_raphson_step(x: float, f_prime: float, f_double_prime: float) -> float

Examples

Example 1: Simple Parabola Optimum
Input: x = 2 f_prime = 4 f_double_prime = 2
Output: 0
Explanation: One step to minimum of x^2.
Example 2: Cubic Descent
Input: x = 1 f_prime = 3 f_double_prime = 6
Output: 0.5
Explanation: Newton step on cubic function.

Constraints

  • Scalar values.
Python3Saved ✓
def newton_raphson_step(x: float, f_prime: float, f_double_prime: float) -> float:
"""Compute single Newton-Raphson minimization step x_next = x - f'(x) / f''(x).
If |f''(x)| < 1e-9, return x unchanged. Return float rounded to 4 decimals."""
# Your implementation here
pass

Case 1: Simple Parabola Optimum
Input: x = 2 f_prime = 4 f_double_prime = 2
Expected: 0
Case 2: Cubic Descent
Input: x = 1 f_prime = 3 f_double_prime = 6
Expected: 0.5