After Width: | Height: | Size: 403 B |
After Width: | Height: | Size: 403 B |
After Width: | Height: | Size: 4.9 KiB |
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 61 KiB |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 125 KiB |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 567 B |
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 695 B |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 808 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 1.3 KiB |
@ -0,0 +1,10 @@
|
||||
def func_save():
|
||||
···与add_func相似
|
||||
else:
|
||||
save(result1, letters, result, result2)
|
||||
subwindow.destroy() # 关闭子页面
|
||||
gl_data.Xian_index = gl_data.INDEX
|
||||
f_button()
|
||||
tk.Button(root_window, text="新增拟合曲线类型",
|
||||
bd=4, command=show_subwindow).place(
|
||||
x=int(740*screen_size), y=int(12)*screen_size)
|
After Width: | Height: | Size: 12 KiB |
@ -0,0 +1,23 @@
|
||||
import tkinter as tk
|
||||
from screeninfo import get_monitors
|
||||
|
||||
# 创建Tkinter窗口
|
||||
window = tk.Tk()
|
||||
window.title("设置按钮尺寸为当前屏幕的百分之85")
|
||||
window.geometry('190x160')
|
||||
def jis():
|
||||
# 获取当前屏幕的宽度和高度
|
||||
monitors = get_monitors()
|
||||
screen_width = monitors[0].width
|
||||
screen_height = monitors[0].height
|
||||
|
||||
# 计算按钮的宽度和高度
|
||||
button_width = int(screen_width * 0.85)
|
||||
button_height = int(screen_height * 0.85)
|
||||
# 打印按钮的宽度和高度
|
||||
print(f"按钮的尺寸:{button_width}x{button_height}")
|
||||
# 创建一个按钮,并设置尺寸
|
||||
button = tk.Button(window, text="按钮", command=jis)
|
||||
button.pack()
|
||||
# 运行Tkinter事件循环
|
||||
window.mainloop()
|
@ -0,0 +1,70 @@
|
||||
# import re
|
||||
#
|
||||
# def add_spaces(expression):
|
||||
# # 匹配运算符的正则表达式
|
||||
# pattern = r'([+\-*/])'
|
||||
# # 替换匹配到的运算符
|
||||
# new_expression = re.sub(pattern, r' \1 ', expression)
|
||||
# return new_expression
|
||||
#
|
||||
# # 示例用法
|
||||
# expression = 'a+b^c-c*d/e'
|
||||
# new_expression = add_spaces(expression)
|
||||
# print(new_expression)
|
||||
|
||||
import re
|
||||
from formula import *
|
||||
|
||||
def remove_inner_spaces(expression):
|
||||
# 匹配括号内的空格的正则表达式
|
||||
pattern = r'\((.*?)\)'
|
||||
# 替换匹配到的括号内的空格
|
||||
new_expression = re.sub(pattern, lambda match: '(' + match.group(1).replace(' ', '') + ')', expression)
|
||||
return new_expression
|
||||
|
||||
def add_spaces(expression):
|
||||
# 匹配运算符的正则表达式
|
||||
pattern = r'([+\-*/])'
|
||||
# 替换匹配到的运算符
|
||||
new_expression = re.sub(pattern, r' \1 ', expression)
|
||||
return new_expression
|
||||
# 示例用法
|
||||
expression = 'a+b^c-c*d/e+sin(x+y)+e^(0.2*x)'
|
||||
expression = add_spaces(expression)
|
||||
new_expression = remove_inner_spaces(expression)
|
||||
list_expression = new_expression.split(' ')
|
||||
conforms = ['e^', 'log', 'sin', 'cos', 'tan', '^']
|
||||
new_list = []
|
||||
# result2 = ' '.join([word for word in expression.split() if not any(word.startswith(s) for s in conforms)])
|
||||
# print(result2)
|
||||
# letters = [char for char in result2 if char.isalpha()]
|
||||
# print(letters)
|
||||
for expres in list_expression:
|
||||
new_list.append(expres)
|
||||
for i in range(6):
|
||||
if conforms[i] in expres:
|
||||
index = list_expression.index(expres)
|
||||
if i == 0:
|
||||
list_expression[index] = convert_e(expres)
|
||||
elif i==1:
|
||||
list_expression[index] = convert_log(expres)
|
||||
elif i==5:
|
||||
list_expression[index] = convert_x(expres)
|
||||
else:
|
||||
list_expression[index] = convert_trigonometric(expres)
|
||||
new_list[-1] = new_list[-1].replace(conforms[i], "")
|
||||
break
|
||||
new_list = [char for item in new_list for char in item if char.isalpha()]
|
||||
parameter =''
|
||||
for item in new_list:
|
||||
if item not in parameter:
|
||||
parameter = parameter+item+','
|
||||
print(parameter[:-1])
|
||||
for item in new_list:
|
||||
if item not in parameter:
|
||||
parameter = parameter+item+','
|
||||
str_expression = ''
|
||||
for item in list_expression:
|
||||
str_expression = str_expression + item
|
||||
print(str_expression[:-1])
|
||||
print(list_expression)
|
@ -0,0 +1,19 @@
|
||||
import re
|
||||
|
||||
|
||||
def find_letter_index(string):
|
||||
pattern = r'([a-zA-Z])x\b'
|
||||
matches = re.findall(pattern, string)
|
||||
|
||||
letter_indices = []
|
||||
for match in matches:
|
||||
letter_index = string.index(match)
|
||||
letter_indices.append(letter_index)
|
||||
|
||||
return letter_indices
|
||||
|
||||
|
||||
# 示例使用
|
||||
string = "ax+b + cx - dx + e^x"
|
||||
indices = find_letter_index(string)
|
||||
print(indices)
|
@ -0,0 +1,4 @@
|
||||
screen_size = 1.8
|
||||
r = 7.5
|
||||
rr = 2.5
|
||||
print(int((20 - rr) * screen_size))
|
@ -0,0 +1,41 @@
|
||||
import numpy as np
|
||||
from scipy.optimize import leastsq
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# 定义待拟合的函数形式
|
||||
def func(x, coeffs):
|
||||
return coeffs[0] * np.sin(coeffs[1] * x) + coeffs[2]
|
||||
|
||||
# 定义目标函数,即待拟合数据
|
||||
def target_func(x):
|
||||
return 2.5 * np.sin(0.7 * x) + 1.2
|
||||
|
||||
# 生成带噪声的待拟合数据
|
||||
np.random.seed(0)
|
||||
x_data = np.linspace(-10, 10, 100)
|
||||
y_data = target_func(x_data) + np.random.normal(0, 0.5, 100)
|
||||
|
||||
# 定义误差函数,即最小二乘法的目标函数
|
||||
def residuals(coeffs, y, x):
|
||||
return y - func(x, coeffs)
|
||||
|
||||
# 初始参数的估计值
|
||||
initial_coeffs = [1, 1, 1]
|
||||
|
||||
# 使用最小二乘法拟合函数
|
||||
result = leastsq(residuals, initial_coeffs, args=(y_data, x_data))
|
||||
best_coeffs = result[0]
|
||||
|
||||
# 打印拟合得到的系数
|
||||
print("拟合得到的系数:", best_coeffs)
|
||||
|
||||
# 绘制拟合结果
|
||||
x_fit = np.linspace(-10, 10, 100)
|
||||
y_fit = func(x_fit, best_coeffs)
|
||||
|
||||
plt.plot(x_data, y_data, 'bo', label='原始数据')
|
||||
plt.plot(x_fit, y_fit, 'r-', label='拟合曲线')
|
||||
plt.legend()
|
||||
plt.xlabel('x')
|
||||
plt.ylabel('y')
|
||||
plt.show()
|
@ -0,0 +1,51 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# 定义待拟合的函数形式
|
||||
def func(x, coeffs):
|
||||
return coeffs[0] * x + coeffs[1]
|
||||
|
||||
# 定义目标函数,即待拟合数据
|
||||
def target_func(x):
|
||||
return 2.5 * x + 1.2
|
||||
|
||||
# 生成带噪声的待拟合数据
|
||||
np.random.seed(0)
|
||||
x_data = np.linspace(0, 10, 100)
|
||||
y_data = target_func(x_data) + np.random.normal(0, 0.5, 100)
|
||||
|
||||
# 定义损失函数,即拟合函数与目标函数之间的差距
|
||||
def loss_func(coeffs, x, y):
|
||||
return np.mean((y - func(x, coeffs))**2)
|
||||
|
||||
# 定义梯度计算函数,即损失函数对于系数的偏导数
|
||||
def gradient_func(coeffs, x, y):
|
||||
gradient = np.zeros_like(coeffs)
|
||||
gradient[0] = -2 * np.mean((y - func(x, coeffs)) * x)
|
||||
gradient[1] = -2 * np.mean(y - func(x, coeffs))
|
||||
return gradient
|
||||
|
||||
# 初始化参数
|
||||
learning_rate = 0.01
|
||||
num_iterations = 1000
|
||||
initial_coeffs = np.array([1.0, 1.0], dtype=float)
|
||||
|
||||
# 使用梯度下降法拟合函数
|
||||
coeffs = initial_coeffs
|
||||
for i in range(num_iterations):
|
||||
gradient = gradient_func(coeffs, x_data, y_data)
|
||||
coeffs -= learning_rate * gradient
|
||||
|
||||
# 打印拟合得到的系数
|
||||
print("拟合得到的系数:", coeffs)
|
||||
|
||||
# 绘制拟合结果
|
||||
x_fit = np.linspace(0, 10, 100)
|
||||
y_fit = func(x_fit, coeffs)
|
||||
|
||||
plt.plot(x_data, y_data, 'bo', label='原始数据')
|
||||
plt.plot(x_fit, y_fit, 'r-', label='拟合曲线')
|
||||
plt.legend()
|
||||
plt.xlabel('x')
|
||||
plt.ylabel('y')
|
||||
plt.show()
|
@ -0,0 +1,51 @@
|
||||
# def make_func(letters,result):
|
||||
# global func_x
|
||||
# # print(letters,result)
|
||||
# draw_axis(-100, 100, 20)
|
||||
# letter = str(letters).split(',')
|
||||
# n = len(letter)-1
|
||||
# decimals = [round(random.uniform(-10, 10), 1) for _ in range(n)]
|
||||
# target_result = functional_formula(letter[1:],result,decimals)
|
||||
# # output.configure(state="normal")
|
||||
# # output.delete("1.0", tk.END) # 删除当前输出框中的所有文本
|
||||
# # output.insert(tk.END, target_result)
|
||||
# # output.configure(state="disabled")
|
||||
# code_str = fitting('x', target_result)
|
||||
# # print(code_str)
|
||||
# target_func = create_func(code_str) # 获取当前函数func
|
||||
# # # print(target_result)
|
||||
# # # 生成带噪声的待拟合数据
|
||||
# # np.random.seed(0)
|
||||
# # x_data = np.linspace(-100, 100, 50)
|
||||
# # y_data = target_func(x_data) + np.random.normal(0, 0.5, 50)
|
||||
# # # print(y_data)
|
||||
# # code_str = fitting(letters, result)
|
||||
# # print(code_str)
|
||||
# # func_x = create_func(code_str) # 获取当前函数func
|
||||
# #
|
||||
# # # 初始参数的估计值
|
||||
# # initial_coeffs = [1.0 for _ in range(n)]
|
||||
# # # 使用最小二乘法拟合函数
|
||||
# # result = leastsq(residuals, initial_coeffs, args=(y_data, x_data))
|
||||
# # best_coeffs = result[0]
|
||||
# # # 打印拟合得到的系数
|
||||
# # print("拟合得到的系数:", best_coeffs)
|
||||
#
|
||||
# # 绘制拟合结果
|
||||
# x_fit = np.linspace(-100, 100, 50)
|
||||
# y_fit = target_func(x_fit)
|
||||
#
|
||||
# # plt.plot(x_data, y_data, 'bo', label='原始数据')
|
||||
# plt.plot(x_fit, y_fit, 'r-', label='拟合曲线')
|
||||
# plt.legend()
|
||||
# plt.xlabel('x')
|
||||
# plt.ylabel('y')
|
||||
# # plt.show()
|
||||
# plt.savefig('new_line.png')
|
||||
# # 清除当前图形状态
|
||||
# plt.clf()
|
||||
# show_image()
|
||||
#
|
||||
# # 定义误差函数,即最小二乘法的目标函数
|
||||
# def residuals(coeffs, y, x):
|
||||
# return y - func_x(x, *coeffs)
|
@ -0,0 +1,17 @@
|
||||
from sympy import symbols, Eq, simplify
|
||||
|
||||
x = symbols('x')
|
||||
a = symbols('a')
|
||||
b = symbols('b')
|
||||
|
||||
expr1 = a*x + b
|
||||
expr2 = 12*x + 1.3
|
||||
|
||||
eq = Eq(expr1, expr2) # 创建一个等式表达式
|
||||
|
||||
simplified_eq = simplify(eq) # 化简等式
|
||||
|
||||
if simplified_eq == True:
|
||||
print("两个表达式相等")
|
||||
else:
|
||||
print("两个表达式不相等")
|
After Width: | Height: | Size: 16 KiB |
@ -0,0 +1,103 @@
|
||||
import re
|
||||
def convert_log(expression):
|
||||
# 匹配log(x,b)的正则表达式
|
||||
pattern = r'log\((\w+),(\w+)\)'
|
||||
match = re.match(pattern, expression)
|
||||
if match:
|
||||
x = match.group(1)
|
||||
b = match.group(2)
|
||||
# 构造新表达式
|
||||
new_expression = f'(np.log({x}) + 1e-5) / (np.log({b}) + 1e-5)'
|
||||
return new_expression
|
||||
else:
|
||||
return None
|
||||
|
||||
def convert_e(expression):
|
||||
new_expression = 'np.exp'+expression[2:]
|
||||
return new_expression
|
||||
|
||||
def convert_trigonometric(expression):
|
||||
# 构造新表达式
|
||||
new_expression = 'np.'+expression
|
||||
return new_expression
|
||||
|
||||
def convert_x(expression):
|
||||
# 匹配log(x,b)的正则表达式
|
||||
pattern = r'(\w+)\^(\w+)'
|
||||
match = re.match(pattern, expression)
|
||||
if match:
|
||||
base = match.group(1)
|
||||
exponent = match.group(2)
|
||||
# 构造新表达式
|
||||
new_expression = f'np.power({base}, {exponent})'
|
||||
return new_expression
|
||||
else:
|
||||
return None
|
||||
def remove_inner_spaces(expression):
|
||||
# 匹配括号内的空格的正则表达式
|
||||
pattern = r'\((.*?)\)'
|
||||
# 替换匹配到的括号内的空格
|
||||
new_expression = re.sub(pattern, lambda match: '(' + match.group(1).replace(' ', '') + ')', expression)
|
||||
return new_expression
|
||||
|
||||
def add_spaces(expression):
|
||||
# 匹配运算符的正则表达式
|
||||
pattern = r'([+\-*/])'
|
||||
# 替换匹配到的运算符
|
||||
new_expression = re.sub(pattern, r' \1 ', expression)
|
||||
return new_expression
|
||||
|
||||
def find_letter_index(string):
|
||||
pattern = r'([a-zA-Z])x\b'
|
||||
matches = re.findall(pattern, string)
|
||||
# print(matches)
|
||||
letter_indices = []
|
||||
for i in range(len(string)):
|
||||
if string[i] in matches:
|
||||
if string[i+1]=='x':
|
||||
letter_indices.append(i)
|
||||
return letter_indices
|
||||
|
||||
def expression_output(expression):
|
||||
# 示例使用
|
||||
modified_list = find_letter_index(expression) # 将x前没有*的加上
|
||||
index = 1
|
||||
for i in modified_list:
|
||||
expression = expression[0:index+i]+'*'+expression[index+i:]
|
||||
index += 1
|
||||
# print(expression)
|
||||
expression = add_spaces(expression)
|
||||
new_expression = remove_inner_spaces(expression)
|
||||
list_expression = new_expression.split(' ')
|
||||
conforms = ['e^', 'log', 'sin', 'cos', 'tan', '^']
|
||||
new_list = []
|
||||
for expres in list_expression:
|
||||
new_list.append(expres)
|
||||
for i in range(6):
|
||||
if conforms[i] in expres:
|
||||
index = list_expression.index(expres)
|
||||
if i == 0:
|
||||
list_expression[index] = convert_e(expres)
|
||||
elif i == 1:
|
||||
list_expression[index] = convert_log(expres)
|
||||
elif i == 5:
|
||||
list_expression[index] = convert_x(expres)
|
||||
else:
|
||||
list_expression[index] = convert_trigonometric(expres)
|
||||
new_list[-1] = new_list[-1].replace(conforms[i], "")
|
||||
break
|
||||
new_list = [char for item in new_list for char in item if char.isalpha()]
|
||||
parameter ='x,'
|
||||
for item in new_list:
|
||||
if item not in parameter and item != 'x':
|
||||
parameter = parameter+item+','
|
||||
for item in new_list:
|
||||
if item not in parameter:
|
||||
parameter = parameter+item+','
|
||||
str_expression = ''
|
||||
for item in list_expression:
|
||||
str_expression = str_expression + item
|
||||
if len(parameter[:-1]) > 1:
|
||||
return parameter[:-1], str_expression
|
||||
else:
|
||||
return None, None
|