I am trying to solve simple first order differential equation using Sympy. But it does not give a closed form solution i.e., still have integral inside the solution. Same happens even after applying initial condition i.e., Q(0) = 5. Although Wolfram alpha solves it without throwing back integral into the solution. The equation is:
\frac{d}{d t} Q{\left(t \right)} = 1.8 \cos{\left(t \right)} + 1.8 - \frac{6 Q{\left(t \right)}}{3 t + 600}
I tried to take help from ChatGPT but no success. My code is below:
t = sm.symbols('t', real = True, positive = True)
Q = sm.symbols('Q', cls = sm.Function)
Q = Q(t)
eq = sm.Eq(Q.diff(t), 9/5*(1+ sm.cos(t)) - (6*Q)/(600+3*t))
sol_g = sm.dsolve(eq, Q)
sol_p = sm.dsolve(eq, Q, ics = {Q.subs(t, 0): 5})
The dsolve function can has a hint parameter that chooses which method to use to generate a solution. You can see the available possibilities for a given ODE by calling
classify_ode:The solution that you see comes from
1st_exactbut the solution from1st_linearis better in this case: