#446easyNumerical Methods
Newton-Raphson Cube Root
Time Limit: 2sMemory: 256MB
Problem
Implement Newton-Raphson root finding to compute the cube root of a positive number .
Define . The root of is . Newton's method iterates:
Starting from initial guess , run exactly num_iterations iterations and output the final .
Input Format
Three space-separated values: a x0 num_iterations
Output Format
The final approximation of , to 4 decimal places.
Examples
Example 1
Input(Three space-separated values: a x0 numiterations)
8.0 1.0 10
Output
2.0000
Cube root of 8 is 2.0. Starting from x0=1.0, Newton converges quickly.
Example 2
Input(Three space-separated values: a x0 numiterations)
2.0 1.0 6
Output
1.2599
Cube root of 2 is approximately 1.2599.
Constraints
- •0.001 ≤ a ≤ 10^6
- •x0 > 0
- •1 ≤ num_iterations ≤ 100
- •Output to 4 decimal places
Loading interactive editor…