Math Problem Statement

# 动态输入P并根据P值绘制图像 def update_plot_with_P(): x_vals = [row[0] for row in c_curves] tx_vals = [row[1] for row in c_curves] sx_vals = [row[2] for row in c_curves] Px_vals = [row[3] for row in c_curves] max_value = np.max(Px_vals) try: P_value = float(p_entry.get()) if P_value <= 0 or P_value > max_value: messagebox.showerror("错误", f"P 值应在 0 到{max_value}之间") return except ValueError: messagebox.showerror("错误", "无效的 L 值输入") return # 计算每个元素与目标值的差的绝对值 Px_vals_np = np.array(Px_vals) diffs = np.abs(Px_vals_np - P_value) # 找到最小差值的索引 closest_index = np.argmin(diffs) # 根据索引找到最接近的值 #寻找离P_value最近的值的序列 L = x_vals[closest_index] print(L) P = Px_vals[closest_index] print(P) P_pdiff, ss_pdiff, xx_pdiff, t_pdiff = [], [], [], [] if L <= 9: # 当 x <= p,计算 P(x) - P(0) 和 s(x) - s(0) for i, p_val in enumerate(Px_vals): if p_val <= P_value: P_pdiff.append(Px_vals[i]) xx_pdiff.append(L - x_vals[i]) t_pdiff.append(tx_vals[i]) ss_pdiff.append(sx_vals[i]) else: continue # 保存曲线数据到全局变量 else: for i in range(len(x_vals)): try: j = np.where(x_vals == x_vals[i] + 9)[0][0] # 找到 x[i] + L 的索引 j except IndexError: # 如果没有找到满足条件的 x[i] + L,则跳过 continue # 检查对应的 y 差值是否满足条件 if Px_vals[j] - Px_vals[i] >= P_value: # 找到第一个满足条件的 x, y 段 #xx_pdiff = x_vals[i:j+1] # 获取 x[i] 到 x[j] 段 P_pdiff.append(Px_vals[i:j + 1]) print(P_pdiff) t_pdiff.append(tx_vals[i:j + 1]) print(t_pdiff) ss_pdiff.append(sx_vals[i:j + 1]) print(ss_pdiff) for val in x_vals[i:j + 1]: result = 9 + x_vals[i] - val xx_pdiff.append(result) print(xx_pdiff) p_curves.append((P_value, ss_pdiff, P_pdiff, xx_pdiff, t_pdiff)) plt.close('all') # 更新图像 plot_px_vs_x() L大于9m时p_curves添加数据不对,检查并改正,并未9设置输入框

Solution

Ask a new question for Free

By Image

Drop file here or Click Here to upload

Math Problem Analysis

Mathematical Concepts

Numerical Analysis
Curve Fitting
Optimization

Formulas

Px_vals[j] - Px_vals[i] >= P_value
L = x_vals[closest_index]
diffs = np.abs(Px_vals - P_value)

Theorems

Numerical approximation
Optimization methods

Suitable Grade Level

University Level (Numerical Methods/Computational Mathematics)