如何求解二次微分方程?

时间:2017-04-23 07:34:41

标签: python sympy ode

对于微分方程private Map<String,String> values; (其中mx'' + kx = 0x''相对于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)

1 个答案:

答案 0 :(得分:0)

我使其工作并且能够解决系数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)