Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

Jupyter notebook 2017-01-24-174717/Chapter 1 - Complex Numbers.ipynb

682 views
Kernel: Python 3

Chapter 1 - Complex Numbers


Section 1: Basic Definitions

Complex numbers have their origin in the theory of algebraic equations (or polynomials). It became apparent that in plenty of cases, no solution existed among the usual set of numbers (positive numbers, natural numbers, integers, rational numbers, real numbers). A simple example is below:

x2+1=0x^2 + 1 = 0

Indeed, any possible x2x^2 as we know it would be a positive number or zero. Since here we want x2x^2 to be -1, we are stuck!

One option would be to just give up on finding a solution! But failure is not an option at least for mathematicians. Before discussing the new system that mathematicians came up with, let's remind ourselves of the existing set of numbers,

\bullet Positive numbers: P={1,2,3,...}\mathbb{P} = \{1, 2, 3, ...\}

\bullet Natural numbers: N={0,1,2,3,...}\mathbb{N} = \{0, 1, 2, 3, ...\}

\bullet Integers: Z={...,3,2,2,0,1,2,3,...}\mathbb{Z} = \{..., -3, -2, -2, 0, 1, 2, 3, ...\}

\bullet Rational numbers: Q={mnmZ,nP}\mathbb{Q} = \{\frac{m}{n}|m\in\mathbb{Z},n\in\mathbb{P}\}

\bullet Real numbers: R=Q{...,2,...,e,...,π,...,eπ}\mathbb{R} = \mathbb{Q}\bigcup\{...,\sqrt{2},...,e,...,\pi,...,\frac{e}{\pi}\}

None of these familiar systems have a solution for x2=1x^2=-1. In a desparate attempt to find a solution, we define a new number, denoted by jj (usually ii) such that,

j2=1j^2 = -1 or j=1j=\sqrt{-1}

We know that such a number does not exist amongst real numbers and hence we call it an imaginary number. Aside from the strange behavior that square of jj is -1, it behaves like any regular number. Let's do some exercises:

Example 1.1

What is the value of j3j^3? We could do

j3=j×j×j=(j2)×j=1×j=jj^3 = j\times j\times j = (j^2)\times j = -1\times j = -j

Or we could do it in code as shown below

# Compute j^3 pow((0+1j),3)
(-0-1j)

Exercise 1.1 (30 points)

Simplify these analytically and then verify with code
a. j0j^0, j4j^4, j5j^5, j6j^6, j7j^7 and j8j^8
b. j39j^{39}, j174j^{174}, j252j^{252} and j317j^{317}

j0j^0 = 1
j4j^4 == 1×1×1×1\sqrt{-1} \times \sqrt{-1} \times \sqrt{-1} \times \sqrt{-1} == 1×1-1 \times -1 == 1
j5j^5 == 1×j4\sqrt{-1} \times j^4 == 1×11 \times \sqrt{-1} == 1\sqrt{-1}
j6j^6 == j5×1j^5 \times \sqrt{-1} == 1×1\sqrt{-1} \times \sqrt{-1} == -1
j7j^7 == j6×1j^6 \times \sqrt{-1} == 1×1-1 \times \sqrt{-1} == -1\sqrt{-1}
j8j^8 == j7×1j^7 \times \sqrt{-1} == 1×1-\sqrt{-1} \times \sqrt{-1} == (1)-(-1) == 1
j39j^{39} == (j4)9(j^4)^9 * j3j^3
j174j^{174}
j252j^{252}
j317j^{317}

Points:\textbf{Points:} 2 points per simplification done analytically and additional 1 point for verifying it with code.

# Your code goes here... jp1 = pow((0+1j), 0) jp2 = pow((0+1j), 4) jp3 = pow((0+1j), 5) jp4 = pow((0+1j), 6) jp5 = pow((0+1j), 7) jp6 = pow((0+1j), 8) jp7 = pow((0+1j), 39) jp8 = pow((0+1j), 174) jp9 = pow((0+1j), 252) jp10 = pow((0+1j), 317) j4r = (0+1j)*(0+1j)*(0+1j)*(0+1j) j5r = j4r * (0+1j) j6r = j5r * (0+1j) j7r = j6r * (0+1j) j8r = j7r * (0+1j) print("j0 = "+ str(1)) print("j4 = "+ str(j4r) + "= 1") print("j5 = "+ str(j5r) + "= j") print("j6 = "+ str(j6r) + "= -1") print( "j7 = "+ str(j7r) + "= -j") print("j8 = "+ str(j8r) + "= 1") print("A: j0 = "+ str(jp1) +", j4 = "+ str(jp2) +", j5 = "+ str(jp3)+", j6 = "+ str(jp4)+", j7 = "+str(jp5)+", j8 = "+str(jp6)) print("B: j39 = "+ str(jp7) +", j174"+str(jp8)+", j252 = "+str(jp9)+", j317 = "+str(jp10))
j0 = 1 j4 = (1-0j)= 1 j5 = 1j= j j6 = (-1+0j)= -1 j7 = (-0-1j)= -j j8 = (1-0j)= 1 A: j0 = (1+0j), j4 = (1+0j), j5 = 1j, j6 = (-1+0j), j7 = (-0-1j), j8 = (1+0j) B: j39 = (-0-1j), j174(-1+2.8417995546584478e-14j), j252 = (1+5.885732403546356e-15j), j317 = (3.4234402118832936e-15+1j)

We can also multiply jj with another number, for example 2×j2\times j. These numbers are called imaginary numbers\textbf{imaginary numbers}.

We can, in fact, add a real number and an imaginary number, for instance 3+5×j3+5\times j, and you get a number that is neither real nor imaginary. Such a "hybrid" number is called a complex number\textbf{complex number}.

Definition 1: Complex Number

A complex number is an expression c=a+b×j=a+bjc = a + b\times j = a+bj, where a, b are two real numbers; a is called the real part of c, whereas b is its imaginary part. The set of all complex numbers will be denoted by C\mathbb{C}. When the ×\times is understood, it is omitted from writing.

Example 1.2

Let c1=3jc_1 = 3 - j and c2=1+4jc_2 = 1 + 4j. We want to compute c1+c2c_1 + c_2 and c1×c2c_1 \times c_2

# Let's do the addition in code c1=3-1j c2=1+4j cp=c1+c2 cp #print cp
(4+3j)
# Let's do the multiplication in code cm=c1*c2 cm #print cm
(7+11j)

Exercise 1.2 (20 points)

Now instead of using builtin functions to add and multiply complex numbers, write your own functions. The functions must take as inputs two complex numbers.

import operator c1=3-1j c2=1+4j adding = operator.add(c1,c2) multiply = operator.mul(c1,c2) print("Using Imported tools to add "+ str(adding)) print("Using Imported tools to multipy: "+ str(multiply)) # Without using imported tools def Addingcomplex(a, b): return "Addition calculated without tools: " + str(complex((a.real + b.real),(a.imag + b.imag))) def Multiplycomplex(a, b): return "Multiply calculated without tools: " + str(complex(((a.real * b.real) - (a.imag * b.imag)),((a.real*b.imag)+(b.real*a.imag)))) print(Addingcomplex(c1, c2)) print(Multiplycomplex(c1, c2))
Using Imported tools to add (4+3j) Using Imported tools to multipy: (7+11j) Addition calculated without tools: (4+3j) Multiply calculated without tools: (7+11j)

Exercise 1.3 (16 points)

Calculate c1+c2c_1+c_2 and c1×c2c_1\times c_2 using the functions you just created. Verify your results against the ones you get from builtin functions.
a. c1=3+jc_1 = -3+j and c2=24jc_2 = 2-4j
b. c1=4+7jc_1 = -4+7j and c2=510jc_2 = 5-10j
c. c1=4+12jc_1 = 4+12j and c2=(315j)c_2 = -(3-15j)
d. c1=5jc_1 = 5j and c2=(9+i)c_2 = -(-9+i)
e. c1=7jc_1 = 7j and c2=5+2jc_2 = -5+2j
f. c1=15jc_1 = 1-5j and c2=9+2jc_2 = -9+2j
g. c1=4+jc_1 = 4+j and c2=2+3jc_2 = 2+3j
h. c1=18jc_1 = 1-8j and c2=1+8jc_2 = 1+8j

Points:\textbf{Points:} 2 points each for computation and verification

def addingcomplex(a,b): return complex((a.real + b.real),(a.imag + b.imag)) def multiplycomplex(a,b): return complex(((a.real * b.real) - (a.imag * b.imag)),((a.real*b.imag)+(b.real*a.imag))) import operator #a c1 = -3+1j c2 = 2-4j aAdd = operator.add(c1,c2) aMul = operator.mul(c1,c2) #b c3 = -4+7j c4 = 5-10j bAdd = operator.add(c3,c4) bMul = operator.mul(c3,c4) #c c5 = 4+12j c6 = -(3-15j) cAdd = operator.add(c5,c6) cMul = operator.mul(c5,c6) #d c7 = 5j c8 = -(-9+1j) dAdd = operator.add(c7,c8) dMul = operator.mul(c7,c8) #e c9 = 7j c10 = -5+2j eAdd = operator.add(c9,c10) eMul = operator.mul(c9,c10) #f c11 = 1-5j c12 = -9+2j fAdd = operator.add(c11,c12) fMul = operator.mul(c11,c12) #g c13 = 4+1j c14 = 2+3j gAdd = operator.add(c13,c14) gMul = operator.mul(c13,c14) #h c15 = 1-8j c16 = 1+8j hAdd = operator.add(c15,c16) hMul = operator.mul(c15,c16) print("Using Imported Tools ############################") print("A: Addition" + str(aAdd) +", Multiply" + str(aMul)) print("B: Addition" + str(bAdd) +", Multiply" + str(bMul)) print("C: Addition" + str(cAdd) +", Multiply" + str(cMul)) print("D: Addition" + str(dAdd) +", Multiply" + str(dMul)) print("E: Addition" + str(eAdd) +", Multiply" + str(eMul)) print("F: Addition" + str(fAdd) +", Multiply" + str(fMul)) print("G: Addition" + str(gAdd) +", Multiply" + str(gMul)) print("H: Addition" + str(hAdd) +", Multiply" + str(hMul)) print("Using Personal Functions ########################") print("A: Addition" + str(addingcomplex(c1,c2)) +", Multiply" + str(multiplycomplex(c1,c2))) print("B: Addition" + str(addingcomplex(c3,c4)) +", Multiply" + str(multiplycomplex(c3,c4))) print("C: Addition" + str(addingcomplex(c5,c6)) +", Multiply" + str(multiplycomplex(c5,c6))) print("D: Addition" + str(addingcomplex(c7,c8)) +", Multiply" + str(multiplycomplex(c7,c8))) print("E: Addition" + str(addingcomplex(c9,c10)) +", Multiply" + str(multiplycomplex(c9,c10))) print("F: Addition" + str(addingcomplex(c11,c12)) +", Multiply" + str(multiplycomplex(c11,c12))) print("G: Addition" + str(addingcomplex(c13,c14)) +", Multiply" + str(multiplycomplex(c13,c14))) print("H: Addition" + str(addingcomplex(c15,c16)) +", Multiply" + str(multiplycomplex(c15,c16)))
Using Imported Tools ############################ A: Addition(-1-3j), Multiply(-2+14j) B: Addition(1-3j), Multiply(50+75j) C: Addition(1+27j), Multiply(-192+24j) D: Addition(9+4j), Multiply(5+45j) E: Addition(-5+9j), Multiply(-14-35j) F: Addition(-8-3j), Multiply(1+47j) G: Addition(6+4j), Multiply(5+14j) H: Addition(2+0j), Multiply(65+0j) Using Personal Functions ######################## A: Addition(-1-3j), Multiply(-2+14j) B: Addition(1-3j), Multiply(50+75j) C: Addition(1+27j), Multiply(-192+24j) D: Addition(9+4j), Multiply(5+45j) E: Addition(-5+9j), Multiply(-14-35j) F: Addition(-8-3j), Multiply(1+47j) G: Addition(6+4j), Multiply(5+14j) H: Addition(2+0j), Multiply(65+0j)

Fundamental Theorem of Algebra

Every polynomial equation of one variable with complex coefficients has a complex solution

Exercise 1.4 (9 points)

Verify the following:
a. (1+j)(-1+j) is a solution to the polynomial equation x2+2x+2=0x^2+2x+2=0.
b. (13j)(-1-3j) is a solution to the polynomial equation x2+2x+10=0x^2+2x+10=0.
c. (23j)(2-\sqrt{3}j) is a solution to polynomial equation x24x+7=0x^2-4x+7=0.

import math as m import numpy.polynomial.polynomial as poly a = poly.polyroots([2,2,1]) b = poly.polyroots([10,2,1]) c = poly.polyroots([7,-4,1]) print("A: " + str(a)) print("B: " + str(b)) print("C: " + str(c)) print("A: " + str(pow((-1+1j),2)+2*(-1+1j)+2) + " inserting (-1+1j) into x^2 + 2x + 2") # == complex(0) print("B: " + str(pow((-1-3j),2) + 2*(-1-3j) + 10) + " inserting (-1-3j) into x^2 + 2x + 10") print("C: " + str(pow((2-m.sqrt(3)*1j),2) - 4*(2-m.sqrt(3)*1j)+7) + " inserting (2-sqrt(3)*1j) into x^2 - 4x + 7")
A: [-1.-1.j -1.+1.j] B: [-1.-3.j -1.+3.j] C: [ 2.-1.73205081j 2.+1.73205081j] A: 0j inserting (-1+1j) into x^2 + 2x + 2 B: 0j inserting (-1-3j) into x^2 + 2x + 10 C: 0j inserting (2-sqrt(3)*1j) into x^2 - 4x + 7

Section 2. The Algebra of Complex Numbers

To understand complex numbers better we will soon discuss their geometrical interpretation. However, before we can do that, we'll write complex numbers as a tuple of values made up of two real numbers.

We know that a+bja+bj is made up of a real part aa and an imaginary part bb. We can therefore redefine the complex number as an ordered pair of reals: c(a,b)c \mapsto (a, b)

Therefore, ordinary real numbers can be identified with pairs (a,0)(a, 0). As a result, a(a,0)a \mapsto (a,0)

whereas imaginary numbers will be pairs (0,b)(0, b). In particular, bj(0,b)bj \mapsto (0,b)

Addition\textbf{Addition} is rather obvious: it adds pairs componentwise: (a1+b1)+(a2+b2)=(a1+a2,b1+b2)(a_1 + b_1) + (a_2 + b_2) = (a_1 + a_2, b_1 + b_2)

Multiplication\textbf{Multiplication} is little trickier: (a1,b1)×(a2,b2)=(a1,b1)(a2,b2)=(a1a2b1b2,a1b2+a2b1)(a_1, b_1)\times(a_2, b_2) = (a_1, b_1)(a_2, b_2) = (a_1a_2-b_1b_2, a_1b_2+a_2b_1)

Let's see if the multiplication formula above works: j×j=(0,1)×(0,1)=(01,0+0)=(1,0)=1j\times j = (0, 1)\times(0,1) = (0-1, 0+0) = (-1,0) = -1

Using addition and multiplication, we can write any complex number in the usual form: c=(a,b)=(a,0)+(0,b)=(a,0)+(b,0)×(0,1)=a+bjc = (a,b) = (a,0)+(0,b) = (a,0)+(b,0)\times(0,1)=a+bj

In summary, we have traded one oddity for another: jj was previously quite mysterious, whereas now it is just (0,1)(0,1) and we can essentially forget about jj.

Therefore, a complex number is nothing more than just an ordered pair of ordinary real numbers!

Example 2.1

Let c1=(3,2)c_1=(3,-2) and c2=(1,2)c_2=(1,2). Let us multiply them using the aforementioned rule:
c1×c2=(3×1(2)×2,3×2+(2)×1)=(3+4,6+(2))=(7,4)=7+4jc_1 \times c_2 = (3\times1-(-2)\times2, 3\times2+(-2)\times1) = (3+4, 6+(-2)) = (7,4) = 7+4j

Exercise 2.1 (15 + 4 points)

Write a function to multiply two complex numbers using the tuple format and give the result in a tuple format. Compute the product of,
a. c1=(3,1)c_1=(-3,-1) and c2=(1,2)c_2=(1,-2)
b. c1=(5,3)c_1=(5,3) and c2=(2,7)c_2=(2,-7)
c. c1=(4,3)c_1=(4,-3) and c2=(4,3)c_2=(4,-3)
d. c1=(5,3)c_1=(5,3) and c2=(2,4)c_2=(2,-4)

Points:\textbf{Points:} 15 points for the program and 1 point each for the computation

import operator as op print("Using imported tools #################") #a c1 = (-3,-1) c2 = (1,-2) c3 = complex(c1[0],c1[1]) c4 = complex(c2[0],c2[1]) a = op.mul(c3,c4) print("A: " + str(a)) #b c5 = (5,3) c6 = (2,-7) c7 = complex(c5[0],c5[1]) c8 = complex(c6[0],c6[1]) b = op.mul(c7,c8) print("B: " + str(b)) #c c9 = (4,-3) c10 = (4,-3) c11 = complex(c9[0],c9[1]) c12 = complex(c10[0],c10[1]) c = op.mul(c11,c12) print("C: " + str(c)) #d c13 = (5,3) c14 = (2,-4) c15 = complex(c13[0],c13[1]) c16 = complex(c14[0],c14[1]) d = op.mul(c15,c16) print("D: " + str(d)) print("Using personal function ###############") def multiplycomplex(a,b): return complex(((a[0] * b[0]) - (a[1] * b[1])),((a[0]*b[1])+(b[0]*a[1]))) print("A: "+ str(multiplycomplex(c1,c2))) print("B: "+ str(multiplycomplex(c5,c6))) print("C: "+ str(multiplycomplex(c9,c10))) print("D: "+ str(multiplycomplex(c13,c14)))
Using imported tools ################# A: (-5+5j) B: (31-29j) C: (7-24j) D: (22-14j) Using personal function ############### A: (-5+5j) B: (31-29j) C: (7-24j) D: (22-14j)

So far we have a set of numbers and two operations: addition and multiplication. Both operations are commutative\textbf{commutative}, meaning that for arbitrary complex numbers c1c_1 and c2c_2,
c1+c2=c2+c1c_1 + c_2 = c_2 + c_1
and
c1×c2=c2×c1c_1 \times c_2 = c_2 \times c_1

Both operations are also associative\textbf{associative}:
(c1+c2)+c3=c1+(c2+c3)(c_1 + c_2) + c_3 = c_1 + (c_2 + c_3)
and
(c1×c2)×c3=c1×(c2×c3)(c_1\times c_2)\times c_3 = c_1\times(c_2\times c_3)

Exercise 2.2 (15 + 3 points)

Verify that multiplication of complex numbers is associative for the following:
a. c1=(3,1)c_1=(-3,-1), c2=(1,2)c_2=(1,-2) and c3=(5,3)c_3=(5,3)
b. c1=(2,7)c_1=(2,-7), c2=(4,3)c_2=(4,-3) and c3=(4,3)c_3=(4,-3)
c. c1=(5,3)c_1=(5,3), c2=(2,4)c_2=(2,-4) and c3=(3,1)c_3=(-3,1)

Points:\textbf{Points:} 15 points for the program and 1 point each for the computation

import operator as op def associatecomplex(a,b,c): ac = complex(a[0],a[1]) bc = complex(b[0],b[1]) cc = complex(c[0],c[1]) af = op.mul(op.mul(ac,bc),cc) bf = op.mul(op.mul(bc,cc),ac) print("(c1 * c2) * c3 : " + str(af)) print("c1 * (c2 * c3) : " + str(bf)) if af == bf: print("Looks like these complex numbers are associative.") print(str(af) + " == " + str(bf)) else: print("Looks like these complex numbers are not associative.") print(str(af) + " != " + str(bf)) c1 = (-3,-1) c2 = (1,-2) c3 = (5,3) print("A :") associatecomplex(c1,c2,c3) c1 = (2,-7) c2 = (4,-3) c3 = (4,-3) print("B :") associatecomplex(c1,c2,c3) c1 = (5,3) c2 = (2,-4) c3 = (-3,1) print("C :") associatecomplex(c1,c2,c3)
A : (c1 * c2) * c3 : (-40+10j) c1 * (c2 * c3) : (-40+10j) Looks like these complex numbers are associative. (-40+10j) == (-40+10j) B : (c1 * c2) * c3 : (-154-97j) c1 * (c2 * c3) : (-154-97j) Looks like these complex numbers are associative. (-154-97j) == (-154-97j) C : (c1 * c2) * c3 : (-52+64j) c1 * (c2 * c3) : (-52+64j) Looks like these complex numbers are associative. (-52+64j) == (-52+64j)

Lastly, multiplication distributes\textbf{distributes} over addition: for all c1,c2,c3c_1, c_2, c_3, we have,
c1×(c2+c3)=(c1×c2)+(c1×c3)c_1\times(c_2+c_3) = (c_1\times c_2) + (c_1\times c_3)

Exercise 2.3 (15 + 3 points)

Verify the property that multiplication distributes over addition for the following,
a. c1=(3,1)c_1=(-3,-1), c2=(1,2)c_2=(1,-2) and c1=(5,3)c_1=(5,3)
b. c1=(2,7)c_1=(2,-7), c2=(4,3)c_2=(4,-3) and c3=(4,3)c_3=(4,-3)
c. c1=(5,3)c_1=(5,3), c2=(2,4)c_2=(2,-4) and c3=(3,1)c_3=(-3,1)

Points:\textbf{Points:} 15 points for the program and 1 point each for the computation

import operator as op def distributescomplex(a,b,c): ac = complex(a[0],a[1]) bc = complex(b[0],b[1]) cc = complex(c[0],c[1]) af = op.mul(op.add(bc,cc),ac) bf = op.mul(ac, bc) + op.mul(ac,cc) print("c1 * (c2 + c3) : " + str(af)) print("(c1 * c2) + (c1 * c3) : " + str(bf)) if af == bf: print("Looks like these complex numbers are distributive.") print(str(af) + " == " + str(bf)) else: print("Looks like these complex numbers are not distributive.") print(str(af) + " != " + str(bf)) c1 = (-3,-1) c2 = (1,-2) c3 = (5,3) print("A :") distributescomplex(c1,c2,c3) c1 = (2,-7) c2 = (4,-3) c3 = (4,-3) print("B :") distributescomplex(c1,c2,c3) c1 = (5,3) c2 = (2,-4) c3 = (-3,1) print("C :") distributescomplex(c1,c2,c3)
A : c1 * (c2 + c3) : (-17-9j) (c1 * c2) + (c1 * c3) : (-17-9j) Looks like these complex numbers are distributive. (-17-9j) == (-17-9j) B : c1 * (c2 + c3) : (-26-68j) (c1 * c2) + (c1 * c3) : (-26-68j) Looks like these complex numbers are distributive. (-26-68j) == (-26-68j) C : c1 * (c2 + c3) : (4-18j) (c1 * c2) + (c1 * c3) : (4-18j) Looks like these complex numbers are distributive. (4-18j) == (4-18j)

Having discussed addition and multiplication, we now discuss their complementary operations: subtraction and division

Subtraction\textbf{Subtraction} is straight forward and defined componentwise:
c1c2=(a1,b1)(a2,b2)=(a1a2,b1b2)c_1 - c_2 = (a_1, b_1) - (a_2, b_2) = (a_1 - a_2, b_1 - b_2)

Division\textbf{Division} is somewhat involved. We want to compute,
(x,y)=(a1,b1)(a2,b2)(x,y) = \frac{(a_1, b_1)}{(a_2, b_2)}

After some simple substitutions and computations we get,
x=a1a2+b1b2a22+b22x = \frac{a_1a_2 + b_1b_2}{a_2^2 + b_2^2} and
y=a2b1a1b2a22+b22y = \frac{a_2b_1 - a_1b_2}{a_2^2 + b_2^2}

Note that both xx and yy are calculated using the same denominator, namely, a22+b22a_2^2 + b_2^2. We will discuss this quantity soon.

Example 2.2

Let c1=2+jc_1=-2+j and c2=1+2jc_2=1+2j. We will compute c1c2\frac{c_1}{c_2}. In this case, a1=2a_1=-2, b1=1b_1=1, a2=1a_2=1, and b2=2b_2=2. Therefore,
a22+b22=12+25=5a_2^2 + b_2^2 = 1^2 + 2^5 = 5
a1a2+b1b2=2×1+1×2=0a_1a_2 + b_1b_2 = -2\times1 + 1\times2 = 0
a2b1a1b2=1×1(2)×2=1+4=5a_2b_1 - a_1b_2 = 1\times1 - (-2)\times2 = 1+4 = 5

The answer then is (05,55)=(0,1)=j(\frac{0}{5}, \frac{5}{5}) = (0, 1) = j

Exercise 2.4 (15 + 3 points)

Write a function to calculate c1c2\frac{c_1}{c_2},
a. c1=3jc_1 = 3j and c2=1jc_2 = -1-j
b. c1=27jc_1 = 2-7j and c2=5+3jc_2 = 5+3j
c. c1=5+3jc_1 = 5+3j and c2=24jc_2 = 2-4j

Points:\textbf{Points:} 15 points for the program and 1 point each for the computation

import operator as op c1 = 3j c2 = -1-1j print("A: "+ str(op.truediv(c1,c2))) c1 = 2-7j c2 = 5 + 3j print("B: "+ str(op.truediv(c1,c2))) c1 = 5+3j c2 = 2-4j print("C: "+ str(op.truediv(c1,c2)))
A: (-1.5-1.5j) B: (-0.3235294117647059-1.2058823529411764j) C: (-0.1+1.3j)

Let us go back to discuss the denominator of our division operation above.

Real numbers have a unary operation called the absolute value\textbf{absolute value} given by,
a=+a2|a| = +\sqrt{a^2}

This operation is generalized in the complex domain as follows,
c=a+bj=+a2+b2|c| = |a+bj| = +\sqrt{a^2+b^2}

This quantity is known as the modulus\textbf{modulus} of a complex number.

Example 2.3

What is the modulus of c=1jc = 1-j?
c=1j=+12+(1)2=2|c| = |1-j| = +\sqrt{1^2 + (-1)^2} = \sqrt{2}

Exercise 2.5 (10 + 5 points)

Write a function to compute the modulus of the following,
a. 5+3j5+3j
b. 24j2-4j
c. 6+4j6+4j
d. 75j7-5j
e. 43j4-3j

Points:\textbf{Points:} 10 points for the program and 1 point each for the computation

import operator as op import math as m a = 5+3j b = 2-4j c = 6+4j d = 7-5j e = 4-3j def absmodverify(var): return m.sqrt(pow(var.real,2)+pow(var.imag,2)) print("A: "+ str(abs(a))) print("B: "+ str(abs(b))) print("C: "+ str(abs(c))) print("D: "+ str(abs(d))) print("E: "+ str(abs(e))) print("Using my own method") print("A: "+ str(absmodverify(a))) print("B: "+ str(absmodverify(b))) print("C: "+ str(absmodverify(c))) print("D: "+ str(absmodverify(d))) print("E: "+ str(absmodverify(e)))
A: 5.830951894845301 B: 4.47213595499958 C: 7.211102550927978 D: 8.602325267042627 E: 5.0 Using my own method A: 5.830951894845301 B: 4.47213595499958 C: 7.211102550927978 D: 8.602325267042627 E: 5.0

Exercise 2.6 (15 points)

Write code to verify that given two arbitrary complex numbers c1c_1 and c2c_2, the following equality always holds:
c1c2=c1c2|c_1||c_2| = |c_1c_2|

def complexabs(a,b): aa = abs(a) ba = abs(b) aba = abs(a*b) if aa*ba == aba: print("Looks like these are equal") else: print("Looks like these are not equal")

Additive Identity:\textbf{Additive Identity:} For a complex number cc, c+(0,0)=(0,0)+c=cc+(0,0) = (0,0)+c = c. Therefore, (0,0)(0,0) is called the additive identity.

Multiplicative Identity:\textbf{Multiplicative Identity:} For a complex number cc, c×(1,0)=(1,0)×c=cc\times(1,0)=(1,0)\times c=c. Therefore, (1,0)(1,0) is called the multiplicative identity.

In summary, we have defined a new set of number C\mathbb{C}, with four operations and the following properties,

  1. Additition is commutative and associative.

  2. Multiplication is commutative and associative.

  3. Addition has an identity: (0,0).

  4. Multiplication has an identity: (1,0).

  5. Multiplication distributes with respect to addition.

  6. Subtraction (i.e. the inverse of addition) is defined everywhere.

  7. Divistion (i.e. the inverse of multiplication) is defined everywhere, except when the divisor is zero.

A set of numbers satisfying all the above properties is called a field\textbf{field}. Therefore, C\mathbb{C} is a field, just like R\mathbb{R}, the field of real numbers.

Conjugation

Changing the sign of the imaginary part only is known as conjugation\textbf{conjugation}. If c=a+bjc=a+bj is an arbitrary complex number, then the conjugate of cc is c=abj\overline{c} = a-bj. Two numbers related by conjugation are said to be complex conjugates\textbf{complex conjugates} of each other.

Exercise 2.7 (10 points)

Write a function to compute the complex conjugate of a complex number.

import numpy as py x = 1+1j print "Using imported tools " + str(py.conjugate(x)) print "#########################################" def myConjugate(a): return(complex(a.real,(-1 * a.imag))) print "Using my own method "+ str(myConjugate(x))
Using imported tools (1-1j) ######################################### Using my own method (1-1j)

Exercise 2.8 (20 points)

Write code to verify the following properties of conjugation:

  1. c1+c2=c1+c2\overline{c_1}+\overline{c_2} = \overline{c_1+c_2}

  2. c1×c2=c1×c2\overline{c_1}\times\overline{c_2} = \overline{c_1\times c_2}

import numpy as py import operator as op def conjugationverify(a,b): ac = py.conjugate(a) bc = py.conjugate(b) apbc = py.conjugate(a+b) ambc = py.conjugate(a*b) if op.add(ac,bc) == apbc and op.mul(ac,bc) == ambc: print("1. Conjugation is valid") print("2. Conjugation is valid") elif op.add(ac,bc) != apbc and op.mul(ac,bc) == ambc: print("1. Conjugation is not valid") print("2. Conjugation is valid") elif op.add(ac,bc) == apbc and op.mul(ac,bc) != ambc: print("1. Conjugation is valid") print("2. Conjugation is not valid") else: print("1. Conjugation is not valid") print("2. Conjugation is not valid")

Note that c×c=c2c\times\overline{c} = |c|^2. Therefore, the modulus\textbf{modulus} of a complex number can be obtained by multiplying the number with its conjugate. For example, (3+2j)×(32j)=32+22=13=3+2j2(3+2j)\times(3-2j) = 3^2 + 2^2 = 13 = |3+2j|^2.

Exercise 2.9 (15 points)

Write a function to compute modulus of a complex number using the above property.

#needed to calculate the probability of a qubit state import numpy as py import operator as op import math as m def modulusconjugate(a): if str(m.ceil(abs(op.mul(a, py.conjugate(a))))) == str(m.ceil(abs(complex(pow(abs(a),2))))): print("This property is true for "+ str(a)) print(str(complex(m.ceil(abs(complex(pow(abs(a),2)))))) + " == " + str(complex(m.ceil(abs(op.mul(a, py.conjugate(a))))))) else: print("This property is false for "+str(a)) print(str(complex(m.ceil(abs(pow(abs(a),2))))) + " != " + str(m.ceil(abs(op.mul(a, py.conjugate(a)))))) c = (3+ 2j) modulusconjugate(c)
This property is true for (3+2j) (13+0j) == (13+0j)

Section 3. The Geometry of Complex Numbers