繁体   English   中英

如何求解二阶微分方程?

[英]How to solve second degree differential equation?

对于微分方程mx'' + kx = 0 (其中x''x相对于t二阶导数),如何解决x(t) 我的意思是如何得到这个等式:

x(t) = c1*cos(sqrt(k/m)*t) + c2*sin(sqrt(k/m)*t)  

我试过的

t, g, k, m, w0, a_0, b_0, c1, c2 = symbols('t g k m w0 a_0 b_0 c1 c2')
x = symbols('x', cls=Function)
w0 = sqrt(k/m)
diffeq = Eq(x(t).diff(t, t) + k*x, 0)

但是语句diffeq = Eq(x(t).diff(t, t) + k*x, 0)会引发错误:

TypeError: unbound method as_base_exp() must be called with x instance as first argument (got nothing instead)

我使它起作用并能够求解系数C1C2的方程式。 这是代码:

t, a0, b0, k, m, g = symbols('t a0 b0 k m g')
x = Function('f')
diffeq = m*Derivative(x(t), t, t) + k*x(t) + m*g
# print(diffeq)
x_sl30 = dsolve(diffeq, x(t)).rhs
print(x_sl30)

# Initial condition, x(0) = a0 and x'(0) = b0
c_0 = Eq(x_sl30.subs(t, 0), a0)
c_1 = Eq(x_sl30.diff(t).subs(t, 0), b0)
# print(c_0)
# print(c_1)
C1, C2 = symbols("C1, C2")
C1C2_sl = solve([c_0, c_1], (C1, C2))
#Substitute the value of C1 and C2 in the original equation
x_sl31 = x_sl30.subs(C1C2_sl)
print(x_sl31)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM