用python计算积分

先安装这个包

bash 复制代码
pip install scipy

运行

bash 复制代码
import tkinter as tk
from scipy.integrate import quad

# 创建主窗口
root = tk.Tk()
root.title("积分计算器")

# 定义计算积分的函数
def calculate_integral():
    # 获取用户输入的函数表达式
    function = function_entry.get()
    # 获取积分下限和上限
    lower_limit = float(lower_limit_entry.get())
    upper_limit = float(upper_limit_entry.get())
    
    # 使用SciPy的quad函数计算积分
    result, _ = quad(lambda x: eval(function), lower_limit, upper_limit)
    
    # 显示积分结果
    result_label.config(text=f"积分结果: {result}")

# 创建GUI元素
function_label = tk.Label(root, text="函数表达式:")
function_label.pack()
function_entry = tk.Entry(root)
function_entry.pack()

lower_limit_label = tk.Label(root, text="下限:")
lower_limit_label.pack()
lower_limit_entry = tk.Entry(root)
lower_limit_entry.pack()

upper_limit_label = tk.Label(root, text="上限:")
upper_limit_label.pack()
upper_limit_entry = tk.Entry(root)
upper_limit_entry.pack()

calculate_button = tk.Button(root, text="计算积分", command=calculate_integral)
calculate_button.pack()

result_label = tk.Label(root, text="")
result_label.pack()

# 运行主事件循环
root.mainloop()
相关推荐
花酒锄作田1 小时前
Pydantic校验配置文件
python
hboot2 小时前
AI工程师第四课 - 深度学习入门
pytorch·python·神经网络
ZhengEnCi12 小时前
P2M-Matplotlib折线图完全指南-从数据可视化到趋势分析的Python绘图利器
python·matlab·数据可视化
ZhengEnCi14 小时前
P2L-Matplotlib饼图完全指南-从数据可视化到图表定制的Python绘图利器
python·matlab
曲幽14 小时前
你的REST接口还在“过度投喂”数据吗?——FastAPI + GraphQL实战避坑指南
python·fastapi·web·graphql·route·cors·rest·strawberry
用户83580861879115 小时前
基于 Self-RAG 与列表级重排序的进阶 RAG 系统设计与实现
python
Warson_L1 天前
Python `Annotated` 与 LangGraph Reducer 学习笔记
python
韩师傅1 天前
海天线算法的前世今生
python·计算机视觉
韩师傅1 天前
当你的甲方设备过烂,要如何快速出效果?
python·计算机视觉
Warson_L1 天前
LangGraph的MessageState and HumanMessage
python