# How to return only the negative complex solutions of DSolve or using FindInstance?

I am using DSolve to find the solutions to two differential equations. The problem is from the first solution, I only want the solution that includes a negative complex variable (in my case omega). In the second solution I want the positive complex omega. Is there any way to specify in DSolve, or FindInstance that I want +/- complexes?

My DSolve command looks like this:

DSolve[y'[x] == Exp[Ix] + Exp[-Ix], y[x], x]


I've looked through many answers on MMSE and I also looked at the documentation, but I haven't found a satisfying answer that works for me.

• You can't really tell DSolve that. What you can do, is that after you get the solutions, simply remove the ones you do not want. If you give an example of what you have, someone can show you how to remove/filter out the solutions that you do not want from the result. Commented Sep 28, 2023 at 18:42
• Edit your question with the code; however, convert to InputForm prior to copy and paste into your question. Commented Sep 28, 2023 at 19:03
• Presumably you mean dsol1 = DSolveValue[y''[x] + (w^2 - Sech[x]^2) y[x] == 0, y[x], x]; however, you need to specify some initial conditions to resolve the arbitrary constants. What do you mean by "negative" and "positive" complex values? Are you referring to their real part, imaginary part, or both? Commented Sep 28, 2023 at 19:13
• when you solve this differential equation there will be an e^iw solution, and an e^-iw component. I would like to use DSolveValue, but only store the solution that includes e^-iw. Commented Sep 28, 2023 at 19:17
• "Negative complex variable"? What about $1 - i$? Commented Sep 28, 2023 at 21:14

Here is a solution that works:

value = DSolveValue[y'[x] == Exp[Ix] + Exp[-Ix], y[x], x] (* Here we store the solution *)

sols = {value[[1]],value[[2]]} (* We make a set from the two solutions *)

set = {value[[1,1,2,1]],value[[2,1,1]]} (* We make another set from the two solutions, only considering the exponentials *)

neg = PositionSmallest[set,1][[1]] (* Here we return which entry in the set has the smallest value,  *)

var = sols[[neg]](* We store the solution that has the negative complex exponential part *)


We have found a solution, modify as needed to fit your problem!

• The ODE in your answer does not match the one in your question, and DSolve is unable to solve it. Commented Sep 30, 2023 at 15:02
• thank you, I originally was working with a simpler version of the DiffEQ, and forgot to fix this when I copy+pasted Commented Sep 30, 2023 at 16:12
• {set[[1, 1, 2]], set[[2, 1, 2]]} generates error messages. Commented Sep 30, 2023 at 18:39