This commit is contained in:
jianxin committed 2023-11-01 13:49:53 +08:00
commit 7177a07538
5 files changed
+159

No files matched your search

Binary file not shown.
+29
View File
@@ -0,0 +1,29 @@
import http.client
import json
def get_data(raw_data=[100, 101]):
conn = http.client.HTTPSConnection("www.zhishuyao.com")
payload = "type=jyzs"
for item in raw_data:
payload += f"&val[]={item}"
headers = {
"authority": "www.zhishuyao.com",
"content-type": "application/x-www-form-urlencoded",
"origin": "https://www.zhishuyao.com",
}
conn.request("POST", "/decode.php", payload, headers)
res = conn.getresponse()
data = res.read()
return json.loads(data.decode("utf-8"))["data"]
if __name__ == "__main__":
raw_data = list(range(0, 1001, 20))
res = get_data(raw_data)
for raw, new in zip(raw_data, res):
print(raw, new)
+75
View File
@@ -0,0 +1,75 @@
import numpy as np
from scipy.optimize import curve_fit
# Define the function to fit
def func(x, a, b, c):
return a * np.exp(-b * x) + c
# Load the data
data = np.array(
[
[0, 0],
[20, 0],
[40, 1],
[60, 2],
[80, 3],
[100, 5],
[120, 6],
[140, 7],
[160, 9],
[180, 11],
[200, 13],
[220, 15],
[240, 17],
[260, 19],
[280, 21],
[300, 23],
[320, 26],
[340, 28],
[360, 31],
[380, 34],
[400, 36],
[420, 39],
[440, 42],
[460, 45],
[480, 48],
[500, 52],
[520, 55],
[540, 58],
[560, 62],
[580, 65],
[600, 69],
[620, 72],
[640, 76],
[660, 80],
[680, 84],
[700, 88],
[720, 92],
[740, 96],
[760, 100],
[780, 104],
[800, 108],
[820, 112],
[840, 117],
[860, 121],
[880, 126],
[900, 130],
[920, 135],
[940, 140],
[960, 145],
[980, 150],
[1000, 154],
]
)
# Separate the data into x and y arrays
xdata = data[:, 0]
ydata = data[:, 1]
# Fit the curve to the data
popt, pcov = curve_fit(func, xdata, ydata)
# Print the fitted parameters
print(popt)
+18
View File
@@ -0,0 +1,18 @@
import numpy as np
from get_data import get_data
parm_1000 = [-61.4400001, 1402438300.0, 61.4400001]
def reduct(x, parm):
a, b, c = parm
return a * np.exp(-b * x) + c
def check_data(data):
fit_data = reduct(data, parm_1000)
real_data = get_data([data])
print(f"拟合数据: {fit_data}, 实际数据: {real_data}, 误差: {fit_data - real_data}")
check_data(1000)
+37
View File
@@ -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)