#447easyNumerical Methods
Bisection Method for Exponential Root
Time Limit: 2sMemory: 256MB
Problem
Implement the bisection method to find the root of on the interval .
The root is , but you must find it using bisection — not the closed-form formula.
Algorithm: Repeat times:
- Compute
- If , set ; otherwise set
After iterations, output .
Input Format
Four space-separated values: b lo hi n
Output Format
The midpoint approximation of , to 4 decimal places.
Examples
Example 1
Input(Four space-separated values: b lo hi n)
1.0 -1.0 1.0 20
Output
0.0000
ln(1) = 0. Bisection on [-1, 1] converges to 0.0000.
Example 2
Input(Four space-separated values: b lo hi n)
2.0 0.0 1.0 25
Output
0.6931
ln(2) = 0.6931. Bisection on [0, 1] converges accurately.
Constraints
- •0.01 ≤ b ≤ 10^6
- •lo < hi
- •f(lo) and f(hi) must have opposite signs
- •1 ≤ n ≤ 100
- •Output to 4 decimal places
Loading interactive editor…