0
$\begingroup$

First: This question is a follow-up question to my question here.

Consider the following code with output:

ClearAll[a1, b1, a2, b2, xC1, yC1, xC2, yC2, c, m]
a1 := 2
b1 := 1
a2 := 1
b2 := 1/2
xC1 := 0
yC1 := 1
xC2 := 0
yC2 := 4

eqn1 = a1 (a1^2 b2^2 m^2 + b1^2 (b2^2 - (c + m xC1 - yC1)^2)) == 
       b2 (a1^2 (a2^2 m^2 + b2^2) - a2^2 (c + m xC2 - yC2)^2);
eqn2 = (a1^2 m (c - yC1) - b1^2 xC1)^2 ==
       (a1^2 m^2 + b1^2) (b1^2 xC1^2 + a1^2 (c - yC1)^2 - a1^2 b2^2);
Solve[eqn1 && eqn2, {c, m}]

\begin{equation} \small \left\{ \left\{c \to -2, m \to -\frac{\sqrt{35}}{2}\right\}, \left\{c \to -2, m \to \frac{\sqrt{35}}{2}\right\}, \left\{c \to 2, m \to -\frac{\sqrt{3}}{2}\right\}, \left\{c \to 2, m \to \frac{\sqrt{3}}{2}\right\} \right\} \end{equation}

I need to calculate the values of the two expressions

(a1^2 m (c - yC1) - b1^2 xC1)/(a1^2 m^2 + b1^2)
(a2^2 m (c - yC2) - b2^2 xC2)/(a2^2 m^2 + b2^2)

for all four combinations of $c$ and $m$. (This gives eight output values.)

Furthermore, I would like the eight output values to be named x1 to x8.

How do I do that?

$\endgroup$
2
$\begingroup$
ClearAll[a1, b1, a2, b2, xC1, yC1, xC2, yC2, c, m]
a1 = 2;
b1 = 1;
a2 = 1;
b2 = 1/2;
xC1 = 0;
yC1 = 1;
xC2 = 0;
yC2 = 4;

eqn1 = a1 (a1^2 b2^2 m^2 + b1^2 (b2^2 - (c + m xC1 - yC1)^2)) == 
   b2 (a1^2 (a2^2 m^2 + b2^2) - a2^2 (c + m xC2 - yC2)^2);
eqn2 = (a1^2 m (c - yC1) - b1^2 xC1)^2 == (a1^2 m^2 + b1^2) (b1^2 xC1^2 + 
      a1^2 (c - yC1)^2 - a1^2 b2^2);

sol = Solve[eqn1 && eqn2, {c, m}];

Clear[x]

Using an indexed variable and depending on the order of the sequencing desired, use either

Evaluate[Array[x, 8]] = {(a1^2 m (c - yC1) - b1^2 xC1)/(a1^2 m^2 + b1^2),
     (a2^2 m (c - yC2) - b2^2 xC2)/(a2^2 m^2 + b2^2)} /. sol // Flatten;

x /@ Range[8]

(*  {Sqrt[35]/6, Sqrt[35]/3, -(Sqrt[35]/6), -(Sqrt[35]/3), -(Sqrt[3]/
  2), Sqrt[3], Sqrt[3]/2, -Sqrt[3]}  *)

or

Clear[x]

Evaluate[Array[x, 8]] = {(a1^2 m (c - yC1) - b1^2 xC1)/(a1^2 m^2 + b1^2),
      (a2^2 m (c - yC2) - b2^2 xC2)/(a2^2 m^2 + b2^2)} /. sol // Transpose // 
   Flatten;

x /@ Range[8]

(*  {Sqrt[35]/6, -(Sqrt[35]/6), -(Sqrt[3]/2), Sqrt[3]/2, Sqrt[35]/3, -(Sqrt[35]/
  3), Sqrt[3], -Sqrt[3]}  *)
$\endgroup$

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.