# DSolve + basis solution

DSolve can't solve this system of differential equation by DSolve. But the basis solution is known. How I can help DSolve to use this basis solution?

WM code:

DSolve[{
x1'[t] == x2[t],
x2'[t] == 2Cos[t]/(3+2Sin[t])x1[t]-x2[t](3-2Cos[t]+2Sin[t])/(3+2 Sin[t])},
{x1[t], x2[t]},t]


System of equations:

$x_1'(t)=x_2(t)$

$x_2'(t)=\frac{2cos(t)}{3+2sin(t)}x_1(t)-x_2(t)\frac{3-2cos(t)+2sin(t)} {3+2sin(t)}$

Basis solution:

$e^{-t}\{-1,1\}\ and\ \{3-cos(t)+sin(t),sin(t)+cos(t)\}$

• I'm not sure I understand the question. If you already know the solution space, what do you want to use DSolve for? The problem is solved; what else is there to do? – AccidentalFourierTransform Apr 27 '18 at 14:20
• {x1[t] -> -Exp[-t] (3 - Cos[t] + Sin[t]) , x2[t] -> Exp[-t] ( Cos[t] + Sin[t] )} don't solve your differential equations – Ulrich Neumann Apr 27 '18 at 14:47
• @UlrichNeumann Use {x1 -> (-Exp[-#] &), x2 -> (Exp[-#] &)} and {x1 -> (3 - Cos[#] + Sin[#] &), x2 -> (Sin[#] + Cos[#] &)} – AccidentalFourierTransform Apr 27 '18 at 15:08
• @AccidentalFourierTransform The main question is how to solve this type of equations when only basis solution is known. Is there any way to introduce assumption about basis solution in DSolve? It is necessary when author by own construct a differential equations. – Андрей Кротких Apr 27 '18 at 15:44
• @АндрейКротких I still don't understand the question. If the basis solution is known, the equation is solved. – AccidentalFourierTransform Apr 27 '18 at 15:54

Here's a way to automate the solution of a system that, like the OP's, is a linear system whose coefficient matrix happens to have a constant eigenvector (constant in that it is independent of $t$). If $\dot x = Ax$ and $A$ is an $n \times n$ matrix that has some constant eigenvectors $v_1,v_2,\dots,v_k$, then completing them to a basis $v_1,v_2,\dots,v_k,v_{k+1},\dots,v_n$, we can form the transition matrix $$P = \left( v1 \mid v_2 \mid \cdots \mid v_n \right) \,.$$ Then with $x = Pu$, we get the transformed ODE $\dot u = P^{-1}AP\,u$, which hopefully DSolve can deal with. It should be able to find the first $k$ solutions, but it might fail to find the last $n-k$.

vars = {x1, x2};
ode = {x1'[t] == x2[t],
x2'[t] == 2 Cos[t]/(3 + 2 Sin[t]) x1[t] -
x2[t] (3 - 2 Cos[t] + 2 Sin[t])/(3 + 2 Sin[t])};
rhs = D[Through[vars[t]], t] /. First@Solve[ode, D[Through[vars[t]], t]];
If[AllTrue[rhs, InternalLinearQ[#, Through[vars[t]]] &],   (* check linearity *)
rhsA = CoefficientArrays[rhs, Through[vars[t]]][],
rhsA = Failure["nonlinear", <||>]
]
(*  SparseArray[<<4>>]    < check: was linear > *)

ev = Cases[Eigenvectors[rhsA], v_ /; FreeQ[v, t]]
If[Length[ev] < 1, Print["Bummer. No constant eigenvectors."]]
(*  {{-1, 1}}    < check: got a constant eigenvector > *)

pp = Transpose@Join[ev, NullSpace[ev]];  (* transition matrix *)
aa = Inverse[pp].rhsA.pp // Simplify;    (* transform coefficient matrix *)
dsol = DSolve[{u'[t], v'[t]} == aa.{u[t], v[t]}, {u, v}, t]  (* check DSolve works *)
(*  check: DSolve found a solution
{{u -> Function[{t}, E^-t C + C (-3 + 2 Cos[t])],
v -> Function[{t}, C (3 + 2 Sin[t])]}}
*)

pp.{u[t], v[t]} /. First[dsol] // Simplify;  (* pp.{u, v} yields {x1, x2} *)
xsol = Thread[vars -> (Function @@ {t, #} & /@ %)]
(*
{x1 -> Function[t, 6 C - E^-t C - 2 C Cos[t] + 2 C Sin[t]],
x2 -> Function[t, E^-t C + 2 C Cos[t] + 2 C Sin[t]]}
*)

ode /. xsol // Simplify    (* check solution *)
(*  {True, True}  *)

• Very nice solution of general interest (+1). Perhaps, you should post it as its own Q/A, so that it will get some visibility. You might also suggest to Wolfram, Inc. that it include this method in its next release of DSolve. – bbgodfrey Apr 29 '18 at 13:03
• @bbgodfrey Thanks. When I get some time I will check its actual generality. I fear DSolve might automatically balk at high order/dimension systems. It might be better to reduce the order before feeding it back to DSolve in that case. But I think it’ll work on 2D systems. – Michael E2 Apr 29 '18 at 13:42

An alternative approach is to solve the system of ODEs with DSolve without knowing a particular solution. As a first try, eliminate x2 to obtain and attempt to solve the resulting single ODE.

DSolve[x1''[t] == x1[t] 2 Cos[t]/(3 + 2 Sin[t]) -
x1'[t] (3 - 2 Cos[t] + 2 Sin[t])/(3 + 2 Sin[t]), x1[t], t]


Unfortunately, it returns unevaluated. Next, reorder terms in the ODE and again attempt to solve it.

DSolve[x1''[t] + x1'[t])/(x1'[t] + x1[t]) == (2 Cos[t])/(3 + 2 Sin[t]), x1[t], t]


It, too, returns unevaluated, even though the ODE has a now obvious first integral, x1'[t] + x1[t] == C (3 + 2 Sin[t]). Only when the auxiliary variable, v[t], is introduced can DSolve obtain a solution.

DSolve[{v'[t]/v[t] == (2 Cos[t])/(3 + 2 Sin[t]),
x1'[t] + x1[t] == v[t]}, {x1[t], v[t]}, t]
(* {{v[t] -> C (3 + 2 Sin[t]),
x1[t] -> E^-t C + C (3 - Cos[t] + Sin[t])}} *)


and x2[t] follows immediately from x2[t] == x1'[t]. Incidentally, introducing v[t] directly into the original ODEs also yields this result.

Simplify[{x1'[t] == x2[t], x2'[t] == 2 Cos[t]/(3 + 2 Sin[t]) x1[t] -
x2[t] (3 - 2 Cos[t] + 2 Sin[t])/(3 + 2 Sin[t])} /. x2 -> Function[t, -x1[t] + v[t]]]
(* {v[t] == x1[t] + x1'[t], ((-3 + 2 Cos[t] - 2 Sin[t]) v[t])/
(3 + 2 Sin[t]) + x1[t] + x1'[t] == v'[t]} *)
DSolve[%, {x1[t], v[t]}, t]


I am also not fully understanding the question. Since you already know the basis solutions. But May be you are looking for reduction of order method?

If one basis solution is known, a second one can be found using reduction of order. For example, let $x_1=-e^{-t}$ be one basis solution. The second one can be found by assuming the solution of the ODE has the form $x_2(t)= x_1(t) v(t)$ and substituting this back into the ODE and solving for $v(t)$.

ClearAll[u,x1,x2,v,x,t]

(*this is the orginal ODE. Assume we know only one solution for it *)
ode =x''[t]==2*(Cos[t]/(3+2*Sin[t]))*x[t]-x'[t]*((3-2*Cos[t]+2*Sin[t])/(3+2*Sin[t])); x1[t_]:=-Exp[-t]; (*this is one solution we know *)
u[t_]:=x1[t]*v[t];
newODE=ode/.{x[t]->u[t],x'[t]->u'[t],x''[t]->u''[t]}//Simplify Now find v[t]

sol = v[t]/.First@DSolve[newODE,v[t],t] Therefore the second solution is

   x2[t_] = sol*x1[t] Verify

 ode/.{x''[t]->x2''[t],x'[t]->x2'[t],x[t]->x2[t]}//Simplify
` This way, you now have both solutions. so you kinda helped Mathematica, since it could not find both solutions before, but it can find one solution, given the other.

If this is not what you want, then I will delete this.