I have a homogeneous solution of a simple second-order ODE, which, when I try to solve the initial values ββwith Sympy, returns the same solution. It should substitute y (0) and y '(0) and give a solution without constants, but this is not so. Here is the code for setting the equation (this is the balance equation of spring, k = spring constant and m = mass). Some redundant characters that I use elsewhere, sorry.
%matplotlib inline from sympy import * m,k, x,t,s,T, omega,A,B = symbols('mkxts T omega A B',float=True) a = symbols('a', positive=True) f,y,g,H,delta,S=symbols('fyg H delta S',cls=Function) Eq1 = Eq(m*diff(y(t),t,2)+k*y(t)) Eq1
Result (correct): $ y {\ left (t \ right)} = C_ {1} e ^ {- t \ sqrt {- \ frac {k} {m}}} + C_ {2} e ^ {t \ sqrt {- \ frac {k} {t}}} $
y (t) = C1e ^ (- tβ (-k / m)) + C2e ^ (tβ (-km)), which also has y_n = c1.cos (β (-k / m) t) + c2 .sin (β (-k / m) t).
When this equation is solved analytically and converted into a solution using sines and cosines with omega = sqrt (-k / m), then c1 = y (0) and c2 = y '(0) / omega. So, although the solution is partially related to complex numbers, of course, dsolve simply returns the original homogeneous equation, as indicated above. My code for evaluating ODE with y (0) and y '(0):
Eq1_soln_IVP =dsolve(Eq1,y(t),x0=0, ics={y(0): a, y(t).diff(t).subs(t, 0): a})
I understand that dsolve simply cannot handle this IVP analytically, but I would be surprised if it were based on its other ability. Any help regarding how this problem and, therefore, other analytical problems of the second order can be solved, would be highly appreciated. The question is:
ics={y(0): a, y(t).diff(t).subs(t, 0): a}
So, the solution I tried, confirmed by Dietrich, was:
#Create IVP for y(0) expr = Eq(Eq1_soln_IVP.rhs.subs(sqrt(-k/m),I*omega),y(0)) #Create IVP for y'(0) expr2 = Eq(diff(y(t),t).subs(t,0),expr.lhs.diff(t)) #Maps all free variables and solves for each where t = 0. solve([expr.subs(t,0),expr2.subs(t,0)])
Although this is an βaβ solution, it seems like a very confusing way to find y (t) = y (0) cos (omega * t - phi) ... which answers the implicit question about some of the limitations of this solver and the direct question about how enabled by ics arg. Thank you