0
$\begingroup$

I asked a question a couple days ago and received a solution that worked for me at the time. But now I am seeing that the proposed solution fails for some other cases I need.

For example, if I just have one equation (instead of three as in the question)

eq1 = (a[3] - a[4]) \[Psi] . \[Xi] + (a[1] + 2 a[2]) \[Psi] . \[Phi];
var = Variables[Level[{eq1}, {-1}]]

(* {\[Xi], \[Phi], \[Psi]} *)

sol = Select[Solve[{eq1} == 0], 
  FreeQ[#, Alternatives @@ var] &]

(* {} *)

The solution should be a[3]=a[4] and a[1]=-2a[2], because \[Psi] . \[Xi] and \[Psi] . \[Phi] are different and can be treated as independent variables. How can I make the code work for this case also?

P.s.: One can define var={\[Psi] . \[Xi],\[Psi] . \[Phi]}, because, as I said, I treat them as independent variables.

$\endgroup$
1
  • $\begingroup$ Solve[((List @@ eq1) /. _Dot :> 1) == 0][[1]] $\endgroup$
    – Bob Hanlon
    Commented Jan 21, 2022 at 3:53

2 Answers 2

3
$\begingroup$

What about `SolveAlways?

var = {\[Psi] . \[Xi], \[Psi] . \[Phi]}
SolveAlways[eq1 == 0, var]
(*{{a[1] -> -2 a[2], a[3] -> a[4]}}*)
$\endgroup$
2
$\begingroup$
Clear["Global`*"]

sol[eq_] := Solve[Cases[eq1,
     c_ *_Dot :> c, Infinity] == 0];

eq1 = (a[3] - a[4]) ψ . ξ + (a[1] + 2 a[2]) ψ . ϕ;

sol[eq1]

(* {{a[2] -> -(a[1]/2), a[4] -> a[3]}} *)

For the original problem,

eqns = {
   (a[3] - a[4]) ψ . ξ + (a[1] + 2 a[2]) ψ . ϕ, 
   2 (a[3] - a[4]) ψ . ξ, 
   (a[1] + a[2] + a[3] + a[4]) ψ . ϕ};

Solving separately,

sol /@ eqns

(* {{{a[2] -> -(a[1]/2), a[4] -> a[3]}}, {{a[2] -> -(a[1]/2), 
   a[4] -> a[3]}}, {{a[2] -> -(a[1]/2), a[4] -> a[3]}}} *)

Solving as a system,

sol@eqns

(* {{a[2] -> -(a[1]/2), a[4] -> a[3]}} *)
$\endgroup$

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.