# How to test if DSolve can solve equation

I have a rather generic system of n first order ODE to solve, of the type

$v_i'[t] + \frac{A}{t}v_i[t] = \sum_jI_{ij}[v_i[t],v_j[t]]$,   $I_{ij}=-I_{ji}$.

Depending on the form of interaction terms $I_{ij}$, some of the $v_i$'s may either decouple completely from the system or couple in such a way that an analytical solution is available for some of them.

My idea was first to search the system to find analytical solutions, and then run NDSolve only if necessary. For this I need DSolve to return some kind of error message if a solution is not found. However, as much as I can tell, it only returns the code unevaluated. Is there a way to get it to return some kind of detectable error message? Or is there a way to detect the unevaluated code, thus using it as the error message?

• r + s == Unevaluated[r + s] – Dr. belisarius Nov 25 '15 at 22:23
• Welcome to Mathematica.SE! I suggest the following: 0) Browse the common pitfalls question 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Dr. belisarius Nov 25 '15 at 22:23
• You could use FreeQ[] to detect if there is still a DSolve[] present in your output. – J. M. will be back soon Nov 26 '15 at 0:07
• Thanks! FreeQ[] works just fine for what I need. – João Morais Nov 27 '15 at 13:06

A typical way to test the result of a function is to set

res = DSolve[...]


and then test

FreeQ[res, DSolve]


to see if the result is free of any DSolve command.

Now, DSolve might solve a differential equation in terms of Solve:

DSolve[D[ ExpIntegralEi[x + y[x]] == x, x], y, x]
(*  Solve[-x + ExpIntegralEi[x + y[x]] == C[1], y[x]]  *)


This might not be counted an explicit solution by some, and an NDSolve approach might be preferred.

Similarly, sometimes a DSolve solution is expressed in terms of InverseFunction. Often this should be considered an acceptable symbolic solution, but sometimes some find it dissatisfying. Here's an example:

DSolve[D[y[x] + Exp[-y[x]^2] == x, x], y, x]
(*  {{y -> Function[{x}, InverseFunction[E^-#1^2 + #1 &][x + C[1]]]}}  *)


So depending on what you consider a solution, you can test the result res of DSolve with one of the following:

FreeQ[res, DSolve]
FreeQ[res, DSolve | Solve]
FreeQ[res, DSolve | Solve | InverseFunction]


And so forth. (Note | is short for Alternatives.)