(* Here are two equations *) 

eqns = { 
 az == ArcTan[Cos[lat]*Sin[dec] - Cos[dec]*Cos[gmst + lon - 
 ra]*Sin[lat], -(Cos[dec]*Sin[gmst + lon - ra])], 
 ha == gmst + lon - ra 

(* should be easy... just replace gmst+lon-ra with ha in the az equation *) 

Solve[eqns, az, {ha}] // InputForm 

(* the answer, however, still contains gmst, lon, and ra *) 

{{az -> ArcTan[Cos[lat]*Sin[dec] - Cos[dec]*Cos[gmst + lon - ra]*Sin[lat],  
    -(Cos[dec]*Sin[gmst + lon - ra])]}} 

(* Eliminate won't work here ... *) 

Eliminate[eqns, {gmst, lon, ra}] // InputForm 

(* yielding this error *) 

   The expression ArcTan[Cos[lat] Sin[dec] -  
      Cos[dec] Cos[gmst + lon - ra] Sin[lat], -(Cos[dec] Sin[gmst + lon - ra])] 
    involves unknowns in more than one argument, so inverse functions cannot be 

(* and this unhelpful output *) 

az == ArcTan[Cos[lat]*Sin[dec] - Cos[dec]*Cos[gmst + lon - ra]*Sin[lat],  
   -(Cos[dec]*Sin[gmst + lon - ra])] && gmst == ha - lon + ra 

My question here isn't necessarily "why can't Mathematica do this?" (because that answer really doesn't help me), but "what can I do to help Mathematica solve this?"

The actual problem has many more variables and equations, but this example represents the general problem.

  • $\begingroup$ What about eqns[[1]] /. Solve[eqns[[2]], gmst][[1]]? $\endgroup$ Nov 11, 2018 at 15:27
  • $\begingroup$ That works in this specific case @UlrichNeumann but won't work in general. I can post a more complete set of equations, but I need a generic solution that doesn't require human cleverness :) $\endgroup$
    – user1722
    Nov 11, 2018 at 15:33
  • $\begingroup$ Simplify[{az == ArcTan[Cos[lat]*Sin[dec] - Cos[dec]*Cos[gmst+lon-ra]*Sin[lat], -(Cos[dec]*Sin[gmst+lon-ra])]}, {ha == gmst+lon-ra}] will rapidly do what you are asking for, even for bigger lists and more complicated expressions, often for things where it would be very difficult for Solve or Reduce to handle. Can you perhaps find a way to automate dividing your list of equations into two lists, the second list containing those var==expression where var appears at least once in the first list and doesn't appear in expression? $\endgroup$
    – Bill
    Nov 11, 2018 at 16:28
  • $\begingroup$ @Bill I'll try this. My ultimate goal is to get everything in terms of everything else to the extent possible. I was hoping I could just do a bunch of Solves and be done with it, but, apparently there's more to it. $\endgroup$
    – user1722
    Nov 11, 2018 at 16:36
  • $\begingroup$ I'm probably just getting paranoid but reference.wolfram.com/language/ref/Solve.html no longer seems to mention the three argument form of Solve, unless the last argument is a domain... ok, it's apparently this: mathematica.stackexchange.com/questions/83902/… $\endgroup$
    – user1722
    Nov 11, 2018 at 16:58

1 Answer 1


Maybe this?:

Solve[eqns, {az}, {ra}, Method -> Reduce]
  {{az -> ArcTan[
      Cos[lat] Sin[dec] - Cos[dec] Cos[ha] Sin[lat], -Cos[dec] Sin[ha]]}}

Or this, if an equation is preferred:

Reduce[eqns, {az}, {ra}]
(* az == ArcTan[Cos[lat] Sin[dec] - Cos[dec] Cos[ha] Sin[lat], -Cos[dec] Sin[ha]] *)
  • $\begingroup$ I'm trying to solve for ha, not ra. When I do that, neither Reduce[eqns, az, {ha}] nor Solve[eqns, az, {ha}, Method -> Reduce] works. $\endgroup$
    – user1722
    Nov 11, 2018 at 16:33
  • $\begingroup$ @barrycarter I didn't solve for ra. The code you first used indicated you wanted to solve for az (and the code asks for ha to be eliminated, but I thought you meant the opposite): "should be easy... just replace gmst+lon-ra with ha in the az equation" and that's exactly what the above does, no? (Apply Equal @@@ ... to the result if you want an equation instead of a rule. Or simply Reduce[eqns, {az}, {gmst, lon, ra}].) $\endgroup$
    – Michael E2
    Nov 11, 2018 at 16:47
  • $\begingroup$ I might be fundamentally misunderstanding, but, despite what the docs appear to say, doesn't Solve[eqns, az, {ha}] mean "give me az in terms of ha"? If not, my whole question is a mistake. $\endgroup$
    – user1722
    Nov 11, 2018 at 16:53
  • 1
    $\begingroup$ @barrycarter When the third argument to Solve or Reduce is a list of variables, they try to eliminate those variables. See this. I believe they took that out of the docs some versions ago, when they added functionality to specify the domain with the third argument. $\endgroup$
    – Michael E2
    Nov 11, 2018 at 17:11

Your Answer

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