# Solve Equations using Mathematica

Good day. I have a question of how to get the algebraic expressions for $$a$$, real part $$b$$ (denoted $$Re(b)$$), and imaginary part $$b$$ (denoted $$Im(b)$$). Let's say $$a$$ is a real number and $$b$$ is a complex number. I have three equations as below:

$$a ^ 2 = X,\quad(a + b)^2 = Y,\quad(a + bi)^2 = Z,$$

where $$X, Y, Z$$ are symbols, and $$i$$ is imaginary part of $$1i$$. I tried to solve above equations to get $$a$$ and $$Re(b)$$, $$Im(b)$$ in terms of symbols $$X, Y, Z$$.

I tried to solve above equations by hand. Let $$b = u + vi$$. So we have:

$$a = \sqrt X, \quad (a + (u + vi))^2 = Y,\quad (a + (u + vi)i)^2 = Z,$$

Then I stuck at this step. May I ask if we want to use Mathematica to solve above equations. That is, get u and v in terms of X, Y, Z. How should I do? Any suggestions would be appreciated.

The short answer is the value of $$x$$ determines the values of $$a, u, v, y, z$$, within a sign.

eqns = {a^2 == x, (a + b)^2 == y, (a + b*I)^2 == z};
cons = {0 < x, {a, x, y, z} ∈ Reals};
Solve[Join[eqns, cons], {a, b, y, z}] But there is no solution when $$x, y,z$$ are independent, real parameters.

Solve[Join[eqns, cons], {a, b}]         (*   { }   *)


To see why this happens, look at the equations one at a time. The first equation has two real solutions for $$a$$, provided $$0

sola = Solve[a^2 == x, a, Reals];
Simplify[sola, 0 < x]   (*  {{a -> -Sqrt[x]}, {a -> Sqrt[x]}}  *)


The second equation has two solutions for $$b$$. Each solution for $$b$$ is in terms of either of the solutions for $$a$$.

solb = Solve[(a + b)^2 == y, b]   (*  {{b -> -a - Sqrt[y]}, {b -> -a + Sqrt[y]}}  *)


To determine $$u$$ and $$v$$, there are four cases to consider, four combinations of the 2 solutions for $$a$$ and the 2 solutions for $$b$$.

Case 1:

case1 = Join[First[solb], First[sola]];
{u1, v1} = Simplify[ReIm[b] /. case1, 0 < x]

(*  {Sqrt[x] - Re[Sqrt[y]], -Im[Sqrt[y]]}  *)


Note that the value of $$z$$ has not been used. Let's see if we can find a $$z$$ that is compatible with $$0 and $$y\in \text{Reals}$$:

z1 = Simplify[(a + b*I)^2 /. case1, 0 < x];
solz = Reduce[{Im[z1] == 0, 0 < x, Im[y] == 0}, y];
Simplify[{
z1 /. ToRules[First[Last[solz]]],
z1 /. ToRules[Last[Last[solz]]]}, 0 < x]           (*  {-x, x}  *)


So, in case 1 we get two possible solutions for $$z$$ in terms of $$x$$.

Case 2: In the second case there is no solution for $$z$$.

case2 = Join[Last[solb], First[sola]];
{u2, v2} = Simplify[ReIm[b] /. case2, 0 < x];

z2 = Simplify[(a + b*I)^2 //. case2, 0 < x];
solz = Reduce[{Im[z2] == 0, 0 < x, Im[y] == 0}, y]      (*  False  *)


Case 3: In the third case we get the same two solutions for $$z$$ as in Case 1.

case3 = Join[Last[solb], Last[sola]];
{u3, v3} = Simplify[ReIm[b] /. case3, 0 < x];

z3 = Simplify[(a + b*I)^2 //. case3, 0 < x];
solz = Reduce[{Im[z3] == 0, 0 < x, Im[y] == 0}, y];
Simplify[{
z3 /. ToRules[First[Last[solz]]],
z3 /. ToRules[Last[Last[solz]]]}, 0 < x]             (*  {-x, x}  *)


Case 4: In the fourth case there is no solution for $$z$$.

Conclusion

When we specify $$a, x \in \text{Reals}$$, there are only certain values of $$y$$ and $$z$$ that will give solutions. There is no solution when $$x,y,z$$ are all considered independent, real parameters.

Solve[Join[eqns, cons], {a, b}]                  (*   {}   *)

• Thank you very much for your insightful explanation!
– Dan
Dec 12, 2021 at 17:16
• @Akku14 - Yep, I messed up. Dec 13, 2021 at 2:52
eqs0 = Subtract @@@ {a^2 == X, (a + b)^2 == Y, {a + I b}^2 == Z}

ceRe = ComplexExpand[Re[eqs0 /. b -> b1 + I b2],
TargetFunctions -> {Re, Im}]

ceIm = ComplexExpand[Im[eqs0 /. b -> b1 + I b2],
TargetFunctions -> {Re, Im}]

red = Reduce[
1], {a, b1, b2}, Reals];

red //. Or ->
Composition[(Column[#, Right, Background -> {{White, LightGray}},
Frame -> All] &), List]] Or LogicalExpand/Reduce it to have no cross dependence of a,b1,b2

TraditionalForm[
Reduce[LogicalExpand[red]] //.
Or -> Composition[(Column[#, Right,
Background -> {{White, LightGray}}, Frame -> All] &), List]] • Thank you for your comments. Your solution is brilliant. But I can only accept one answer. Thank you all the same. I learned a lot from your solution!
– Dan
Dec 12, 2021 at 17:23
• If you appreciate it, it would be nice to upvote. Dec 12, 2021 at 17:34