用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()
相关推荐
ikun_文22 分钟前
Django框架路由Router的使用
python·pycharm·django
IvanCodes25 分钟前
Python 基础语法(二):字符串与常用操作
python
昭昭日月明31 分钟前
LangChain 生态:从链到代理,开发者需要掌握的三大核心
python·langchain·agent
Csvn38 分钟前
🐍 Day 8:面向对象编程
后端·python
程序员天天困40 分钟前
向量检索不准怎么办:混合检索与 Rerank 重排序召回优化实战
后端·python·ai编程
alphaTao2 小时前
LeetCode 每日一题 2026/8/24-2026/8/30
python·算法·leetcode
苏灿烤鱼2 小时前
当 AI Agent 遇见真实科学环境:深度拆解 Scientific Agent Skills,把"聊天机器人"变成"AI 科学家"
python·开源·agent
张文君2 小时前
ubuntu26.04坏道坏块分区隔离急速版260831-V0.12
linux·python
Interview Aid1122 小时前
TikTok OA 四题分享|半小时内 AC,题目基本都是实现题
java·开发语言·算法·面试·职场和发展
CoderIsArt10 小时前
C#中UI 线程与 Dispatcher
开发语言·ui·c#