38 lines
710 B
Python
38 lines
710 B
Python
import math
|
|
|
|
|
|
def calculate_y(x):
|
|
y = (10 * math.log(x + 1) + 30) * math.sqrt(x)
|
|
return y
|
|
|
|
|
|
def reduce_index(index):
|
|
# Define the function to find the root of
|
|
def f(x):
|
|
return (10 * math.log(x + 1) + 30) * math.sqrt(x) - index
|
|
|
|
# Set the initial bounds for the bisection method
|
|
a = 0
|
|
b = 1e6
|
|
|
|
# Set the tolerance for the root-finding algorithm
|
|
tol = 1e-6
|
|
|
|
# Perform the bisection method to find the root
|
|
while (b - a) / 2 > tol:
|
|
c = (a + b) / 2
|
|
if f(c) == 0:
|
|
return c
|
|
elif f(a) * f(c) < 0:
|
|
b = c
|
|
else:
|
|
a = c
|
|
|
|
return (a + b) / 2
|
|
|
|
|
|
# Example usage
|
|
y = 100000
|
|
x = reduce_index(y)
|
|
print(x)
|