如何在Python中求解方程式? [英] How can I solve equations in Python?

查看:120
本文介绍了如何在Python中求解方程式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个方程:

2x + 6 = 12

借助代数,我们可以看到x = 3.如何使用Python编写可以解决x的程序?我是编程的新手,我看过eval()exec(),但是我不知道如何使它们按我的意愿去做.我不想使用外部库(例如SAGE),我只想在纯Python中做到这一点.

With algebra we can see that x = 3. How can I make a program in Python that can solve for x? I'm new to programming, and I looked at eval() and exec() but I can't figure out how to make them do what I want. I do not want to use external libraries (e.g. SAGE), I want to do this in just plain Python.

推荐答案

SymPy 怎么样?他们的求解器看起来像您所需要的.如果您想自己构建库,请查看它们的源代码.

How about SymPy? Their solver looks like what you need. Have a look at their source code if you want to build the library yourself…

这篇关于如何在Python中求解方程式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆