Function Repository Resource:

ComplexTogether

Source Notebook

Combine the real and imaginary parts of complex numbers into a single fraction

Contributed by: Nikolay Murzin

ResourceFunction["ComplexTogether"][z]

combine together the real and imaginary parts of a complex number z into one fraction.

Examples

Basic Examples (3) 

Combine a complex number into a single fraction:

In[1]:=
ResourceFunction["ComplexTogether"][1 + I/2]
Out[1]=

Use in a computation:

In[2]:=
{ResourceFunction["ComplexTogether"][1 + I/2], x} . {y, ResourceFunction["ComplexTogether"][1 - I/2]}
Out[2]=

Combine together all complex numbers within an expression:

In[3]:=
ResourceFunction["ComplexTogether"][
 1 + I/2 + (1/2 + 3/5 I) x + (2/9 - 10/3 I) y + (3/4 - 7/5 I) z]
Out[3]=

Possible Issues (4) 

ComplexTogether works only for numeric complex numbers (with Complex head), not for symbolic expressions containing an imaginary unit:

In[4]:=
ResourceFunction["ComplexTogether"][\[FormalA] + I/2 \[FormalB] ]
Out[4]=

ComplexTogether is a formatted expression with its own Head:

In[5]:=
ResourceFunction["ComplexTogether"][2 + 2/3 I] // Head
Out[5]=

ComplexTogether unformats itself when used with functions that have the NumericFunction attribute, assuming all other arguments are numeric:

In[6]:=
ResourceFunction["ComplexTogether"][1 + I/2]
Out[6]=
In[7]:=
Exp@%
Out[7]=
In[8]:=
ResourceFunction["ComplexTogether"][1 + I/2]
Out[8]=
In[9]:=
3 % + 2
Out[9]=

Conversely, ComplexTogether stays formatted if it s not a part of a numeric computation:

In[10]:=
ResourceFunction["ComplexTogether"][1 + I/2]
Out[10]=
In[11]:=
\[FormalA] % + b
Out[11]=

Applications (1) 

ComplexTogether can be used with any computation:

In[12]:=
RandomInteger[{-10, 10}, {2, 2}]/RandomInteger[{1, 10}, {2, 2}] + RandomInteger[{-10, 10}, {2, 2}]/
   RandomInteger[{1, 10}, {2, 2}] I // ResourceFunction[
 "ComplexTogether"]
Out[12]=
In[13]:=
Inverse[%] . % // Simplify
Out[13]=
In[14]:=
c = ResourceFunction["ComplexTogether"][1 - 1/2 I]
Out[14]=
In[15]:=
Solve[c - x^2 == 0, x]
Out[15]=

Version History

  • 1.0.0 – 01 November 2021

License Information