init
This commit is contained in:
commit
7177a07538
5 files changed
+159
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import math
|
||||
|
||||
|
||||
def calculate_y(x):
|
||||
y = (10 * math.log(x + 1) + 30) * math.sqrt(x)
|
||||
return y
|
||||
|
||||
|
||||
def calculate_x(y):
|
||||
# Define the function to find the root of
|
||||
def f(x):
|
||||
return (10 * math.log(x + 1) + 30) * math.sqrt(x) - y
|
||||
|
||||
# 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 = 10000000
|
||||
x = calculate_y(y)
|
||||
print(x)
|
||||
Reference in new issue
Block a user