2
$\begingroup$

After solving a set of equations I got a solution like the following using Solve[] function.

{{X0 -> 0,X1 -> 0, Xn1 -> 0, X2 -> 0, 
  Xn2 -> 0}, {X0 -> -0.046557 + 0.0660528 I, 
  X1 -> -0.00129788 - 0.104325 I, Xn1 -> -0.0370385 - 0.0938482 I, 
  X2 -> -0.00857655 + 0.0700392 I, 
  Xn2 -> 0.0466159 + 0.0600041 I}, {X0 -> 0.046557 - 0.0660528 I, 
  X1 -> -0.00129788 - 0.104325 I, Xn1 -> -0.0370385 - 0.0938482 I, 
  X2 -> 0.00857655 - 0.0700392 I, 
  Xn2 -> -0.0466159 - 0.0600041 I}, {X0 -> -0.094816 + 0.182855 I, 
  X1 -> 0, Xn1 -> 0, X2 -> 0, Xn2 -> 0}, {X0 -> 0.094816 - 0.182855 I,
   X1 -> 0, Xn1 -> 0, X2 -> 0, Xn2 -> 0}, {X0 -> 0, 
  X1 -> 0.109897 - 0.273052 I, Xn1 -> 0.0246269 - 0.3725 I, X2 -> 0, 
  Xn2 -> 0}, {X0 -> 0, X1 -> 0.109897 - 0.273052 I, 
  Xn1 -> 0.0246269 - 0.3725 I, X2 -> 0, Xn2 -> 0}}

My intend is to extract only those solutions from the result where the condition Im(X0)!=0&&Im(X1)!=0&&Im(Xn1)!=0&&Im(X2)!=0&&Im(Xn2)!=0 is met, i.e., the second and third solutions in this case.

$\endgroup$
  • $\begingroup$ I am sorry. It should be != 0. I have corrected it now. $\endgroup$ – Soumyajit Roy Jul 5 at 5:51
  • $\begingroup$ The expression passed as the first argument to Solve can be a system of equations or inequalities for the variables. Include the inequalities in your Solve and the solution should satisfy the conditions. $\endgroup$ – Bob Hanlon Jul 5 at 12:59
3
$\begingroup$
Pick[solution, 
   And @@ Thread[Im[{X0, X1, Xn1, X2, Xn2}] != 0] /. solution]

 {{X0 -> -0.046557 + 0.0660528 I, X1 -> -0.00129788 - 0.104325 I, Xn1 -> -0.0370385 - 0.0938482 I, X2 -> -0.00857655 + 0.0700392 I, Xn2 -> 0.0466159 + 0.0600041 I},
{X0 -> 0.046557 - 0.0660528 I, X1 -> -0.00129788 - 0.104325 I, Xn1 -> -0.0370385 - 0.0938482 I, X2 -> 0.00857655 - 0.0700392 I, Xn2 -> -0.0466159 - 0.0600041 I}}

$\endgroup$
  • $\begingroup$ Initial version of my question had a mistake. The condition should be Im(X0)!=0&&Im(X1)!=0&&Im(Xn1)!=0&&Im(X2)!=0&&Im(Xn2)!=0. I have corrected it now. Thanks for the answer. $\endgroup$ – Soumyajit Roy Jul 5 at 5:58
  • $\begingroup$ Thanks a lot. It has worked. $\endgroup$ – Soumyajit Roy Jul 5 at 6:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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