在 sympy 中求解微分方程组的语法 [英] syntax for solving system of differential equations in sympy

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

问题描述

我是 sympy 的新手,并且正在学习它.我正在浏览堆栈交换中关于使用 sympy 符号求解具有初始条件的微分方程组的文档和问题.

I am new to sympy and in the process of learning it. I was browsing through the documentation and questions in stack exchange regarding symbolically solving a system of differential equations with initial conditions using sympy.

我有一个简单的 ODE-s 系统

I have a simple system of ODE-s

( dV/dt )  = -(  1 / RC ) * ( V(t) ) + I(t)/C

( dI/dt )  = -( R1 /  L ) * ( I(t) ) - ( 1 / L) * V(t) + Vs/L

具有初始条件 V(0) = V0I(0) = I0

我在堆栈交换中浏览了很多问题,但没有找到合适的答案.如果有人可以向我展示输入具有初始条件的耦合微分方程系统的语法,那将是非常有帮助的.

I browsed through a lot of questions in stack exchange and not successful in finding an appropriate answer. It would be of great help if somebody can show me a syntax to enter a system of coupled differential equations with initial conditions.

推荐答案

ODE 系统支持仅在 SymPy 的开发版本中.它将在 0.7.6 中添加.语法是

System of ODEs support is only in the development version of SymPy. It will be added in 0.7.6. The syntax would be

V, I = symbols("V I", cls=Function)
RC, t, C, Vs, L, R1, V0, I0 = symbols("RC t C Vs L R1 V0 I0")
system = [Eq(V(t).diff(t), -1/RC*V(t) + I(t)/C), Eq(I(t).diff(t), -R1/L*I(t) - 1/L*V(t) + Vs/L)]
ics = {V(0): V0, I(0): I0}
dsolve(system, [V(t), I(t)], ics=ics)

似乎有一个错误阻止了它在当前的 SymPy master 中工作,除非我输入错误(https://github.com/sympy/sympy/issues/8193).

It seems that there is a bug that prevents this from working in the current SymPy master, unless I mistyped something (https://github.com/sympy/sympy/issues/8193).

这篇关于在 sympy 中求解微分方程组的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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