- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我想找到一种优雅的方法来求解以下微分方程:
from sympy import *
init_printing()
M, phi, t, r = symbols('M phi t r')
eq = Eq(-M * phi(t).diff(t), Rational(3, 2) * m * r**2 * phi(t).diff(t) * phi(t).diff(t,t))
我假设 phi(t).diff(t) 不为零。因此,左侧和右侧被缩短了。
这就是我得到解决方案的方式:
# I assume d/dt(phi(t)) != 0
theta = symbols('theta')
eq = eq.subs({phi(t).diff(t, 2): theta}) # remove the second derivative
eq = eq.subs({phi(t).diff(t): 1}) # the first derivative is shortened
eq = eq.subs({theta: phi(t).diff(t, 2)}) # get the second derivative back
dsolve(eq, phi(t))
如何更优雅地解决这个问题?
最佳答案
理想情况下,dsolve()
能够直接求解方程,但它不知道如何求解(它需要了解它可以因式分解方程并独立求解因式)。我开了一个issue为了它。
我唯一的其他建议是直接将 phi 分开:
eq = Eq(eq.lhs/phi(t).diff(t), eq.rhs/phi(t).diff(t))
你也可以使用
eq.xreplace({phi(t).diff(t): 1})
在不修改二阶导数的情况下用 1 替换一阶导数(与 subs
不同,xreplace
没有关于它替换什么的数学知识;它只是准确地替换表达式) .
不要忘记 phi(t) = C1
也是一个解决方案(当 phi' 等于 0 时)。
关于python - Sympy:求解微分方程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33340217/
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
Julia的新手,试图测试ODE求解器的速度。我在本教程中使用了Lorenz方程 using DifferentialEquations using Plots function lorenz(t,u
我来这里是因为我一直在尝试使用 sympy 求解微分方程,不幸的是到目前为止我还没有成功。到目前为止我所做的是: 1)插入微分方程,赋值并求解: import sympy as sp from IPy
我不知道问这个地方是否合适,因为我的问题是关于如何使用微分方程增长和衰减方法计算计算机科学算法的复杂性。 我想证明的算法是二分查找排序数组,其复杂度为log2(n) 算法说:如果要搜索的目标值等于中间
我想知道是否有人可以帮助我使用 MatLab 求解 Lotka-Volterra 方程。我的代码似乎不起作用。我执行以下操作: 第 1 步 - 我创建了一个名为 pred_prey_odes.m 的文
我是一名优秀的程序员,十分优秀!