I'm solving a system of ODEs using DSolve. I'm having a hard time keeping track of the number of undetermined constants that are still left in the solution. Is there a way to count or list the constants (C[1], C[2], etc.) that are present in a typical DSolve solution? This would give me a lot of insight into which boundary conditions I might need to supply, change or rethink, in order to solve for the constants.


1 Answer 1


Maybe this will help:

sol = DSolve[{y'[x] == x^2 y[x], z'[x] == 5 z[x]}, {y[x], z[x]}, x]

{{y[x] -> E^(x^3/3) C[1], z[x] -> E^(5 x) C[2]}}

Cases[sol, C[x_] -> C[x], Infinity]

{C[1], C[2]}

or just

Cases[sol, C[_], Infinity]
  • 2
    $\begingroup$ Or just Cases[sol, C[_], Infinity]. In some cases you might want to add //Union $\endgroup$
    – Bob Hanlon
    Commented Oct 19, 2016 at 13:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.