A Matlab (R) Companion To Comple - A. David Wunsch
A Matlab (R) Companion To Comple - A. David Wunsch
A MATLAB®
COMPANION
to COMPLEX
VARIABLES
A. David Wunsch
A MATLAB®
COMPANION
to COMPLEX
VARIABLES
TEXTBOOKS in MATHEMATICS
Series Editors: Al Boggess and Ken Rosen
PUBLISHED TITLES
ABSTRACT ALGEBRA: AN INTERACTIVE APPROACH, SECOND EDITION
William Paulsen
ABSTRACT ALGEBRA: AN INQUIRY-BASED APPROACH
Jonathan K. Hodge, Steven Schlicker, and Ted Sundstrom
ADVANCED LINEAR ALGEBRA
Hugo Woerdeman
APPLIED ABSTRACT ALGEBRA WITH MAPLE™ AND MATLAB®, THIRD EDITION
Richard Klima, Neil Sigmon, and Ernest Stitzinger
APPLIED DIFFERENTIAL EQUATIONS: THE PRIMARY COURSE
Vladimir Dobrushkin
COMPUTATIONAL MATHEMATICS: MODELS, METHODS, AND ANALYSIS WITH MATLAB® AND MPI,
SECOND EDITION
Robert E. White
DIFFERENTIAL EQUATIONS: THEORY, TECHNIQUE, AND PRACTICE, SECOND EDITION
Steven G. Krantz
DIFFERENTIAL EQUATIONS: THEORY, TECHNIQUE, AND PRACTICE WITH BOUNDARY VALUE PROBLEMS
Steven G. Krantz
DIFFERENTIAL EQUATIONS WITH MATLAB®: EXPLORATION, APPLICATIONS, AND THEORY
Mark A. McKibben and Micah D. Webster
ELEMENTARY NUMBER THEORY
James S. Kraft and Lawrence C. Washington
EXPLORING LINEAR ALGEBRA: LABS AND PROJECTS WITH MATHEMATICA®
Crista Arangala
GRAPHS & DIGRAPHS, SIXTH EDITION
Gary Chartrand, Linda Lesniak, and Ping Zhang
INTRODUCTION TO ABSTRACT ALGEBRA, SECOND EDITION
Jonathan D. H. Smith
PUBLISHED TITLES CONTINUED
A MATLAB®
COMPANION
to COMPLEX
VARIABLES
A. David Wunsch
University of Massachusetts Lowell
MATLAB® is a trademark of The MathWorks, Inc. and is used with permission. The MathWorks does not
warrant the accuracy of the text or exercises in this book. This book’s use or discussion of MATLAB® soft-
ware or related products does not constitute endorsement or sponsorship by The MathWorks of a particular
pedagogical approach or particular use of the MATLAB® software.
CRC Press
Taylor & Francis Group
6000 Broken Sound Parkway NW, Suite 300
Boca Raton, FL 33487-2742
This book contains information obtained from authentic and highly regarded sources. Reasonable efforts
have been made to publish reliable data and information, but the author and publisher cannot assume
responsibility for the validity of all materials or the consequences of their use. The authors and publishers
have attempted to trace the copyright holders of all material reproduced in this publication and apologize to
copyright holders if permission to publish in this form has not been obtained. If any copyright material has
not been acknowledged please write and let us know so we may rectify in any future reprint.
Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmit-
ted, or utilized in any form by any electronic, mechanical, or other means, now known or hereafter invented,
including photocopying, microfilming, and recording, or in any information storage or retrieval system,
without written permission from the publishers.
For permission to photocopy or use material electronically from this work, please access www.copyright.
com (http://www.copyright.com/) or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood
Drive, Danvers, MA 01923, 978-750-8400. CCC is a not-for-profit organization that provides licenses and
registration for a variety of users. For organizations that have been granted a photocopy license by the CCC,
a separate system of payment has been arranged.
Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used
only for identification and explanation without intent to infringe.
Visit the Taylor & Francis Web site at
http://www.taylorandfrancis.com
Acknowledgments..................................................................................................xi
Introduction.......................................................................................................... xiii
A Note to the Reader.............................................................................................xv
1. Complex Arithmetic........................................................................................1
1.1 The Rectangular Form..........................................................................1
1.1.1 A Caveat on Complex Numbers as Matrix Elements..........3
Exercises.............................................................................................................4
1.2 The Polar Form of Complex Numbers................................................5
Exercises.............................................................................................................8
1.3 Fractional Powers of Complex Numbers............................................9
1.3.1 Using sqrt................................................................................. 11
1.3.2 Reminder: A Warning about Square Roots and
Fractional Powers in MATLAB............................................. 11
1.3.3 Use of roots.............................................................................. 11
1.3.4 A Program to Give You Fractional Roots and
to Do a Check.......................................................................... 14
1.3.5 A Further Caveat with Fractional Powers:
The Plot Function................................................................... 14
Exercises........................................................................................................... 19
1.4 Complex Symbolic Algebra................................................................ 21
1.4.1 Numbers as Symbols..............................................................22
Exercises........................................................................................................... 24
2. Loci and Regions in the Complex Plane and Displaying
Complex Functions........................................................................................ 27
2.1 Meshgrid and Three-Dimensional Plotting.................................... 27
Exercises........................................................................................................... 33
2.2 Two-Dimensional Plots: The Contour Plot.......................................34
Exercises........................................................................................................... 38
2.3 Displaying Regions in the Complex Plane....................................... 39
2.3.1 A Note on pcolor.....................................................................43
Exercises...........................................................................................................44
2.4 Three-Dimensional and Contour Plots for Functions
with Singularities................................................................................. 45
2.4.1 Plots When There Are Isolated Singular Points................. 46
2.4.1.1 Removable Singular Points.................................... 46
2.4.1.2 Pole Singularities..................................................... 48
2.4.1.3 Essential Singularities............................................ 52
2.4.1.4 Branch Cut and Branch Point Singularities:
Three-Dimensional Plots.......................................54
vii
viii Contents
Exercises........................................................................................................... 58
2.5 Contour Plots Affected by Branch Cuts............................................ 60
Exercises........................................................................................................... 66
xi
This page intentionally left blank
Introduction
I hope the reader will enjoy using this book. It is for someone with at least a
beginner’s knowledge of MATLAB® who is learning the branch of advanced
calculus called “functions of a complex variable.” Complex variable theory
is the calculus of functions dependent on variables that can assume complex
numerical values. I want you to discover that MATLAB is your friend when
you are learning this type of mathematics.
One of the daunting aspects of complex numbers (and variables) is that
simple arithmetic operations that are easily done in one’s head, if they
involve real quantities, become tedious when the numbers are complex. You
can ask a class of third graders for the product of the numbers 3, 4, and 5,
and someone with the answer will raise his or her hand in less than 5 sec-
onds. Ask a college student for the product of the numbers (1 + 3i), (1 + 4i),
(1 + 5i) and he or she will, after a little squirming, probably resort to pencil
and paper, although the problem is solvable in one’s head with some serious
concentration. If you were to ask me this question as I’m typing this sentence,
I would open the MATLAB window on my computer and type in the prod-
uct. Here we see a glimpse of the utility of MATLAB in complex arithmetic.
If you glance at the table of contents, you will see how MATLAB can be
your companion in such staples of complex variable theory as conformal
mapping, infinite series, contour integration, and Laplace and Fourier trans-
forms. Fractals, the most recent interesting topic involving complex vari-
ables, cries out to be treated with a language such as MATLAB, and you
might want to begin this book at its end, The Coda, which is devoted entirely
to this visually intriguing subject. However, I must add that as you progress
through the book, the MATLAB skill required increases gradually, and leap-
ing to the end is not for everyone.
Sometimes while working with MATLAB and complex algebra, you may
be puzzled at what you find. For example, if you ask a class of high school
( )
1/3
students to compute 53 , someone will quickly call out “five.” He or she
will know to multiply the exponents together. Now asking the same class
( )
2 1/2
for ( −1 + i ) , a student will follow the same logic and produce a cor-
rect answer: –1 + i. But another student, using MATLAB, will say 1 – i.
Both answers are correct, but why did MATLAB choose this one? This book
answers such questions and many similar ones.
This textbook does not purport to present MATLAB as a substitute for a
knowledge of the functions of a complex variable any more than MATLAB
can be used as a replacement for an actual understanding of elementary cal-
culus or linear algebra. This is also not a text from which one learns the
elements of MATLAB, although if you already know a little of the language,
xiii
xiv Introduction
it will expand your knowledge. Some books that will get the reader started
in the elements of MATLAB programming are listed as references [1,2].
MATLAB is not without constraints, assumptions, limitations, irritations,
and quirks, and there are subtleties involved in performing the calculus
of complex variable theory with this language that will be made evident
here. Without knowledge of these subtleties, the engineer or scientist who
is attempting to use MATLAB for solutions of practical problems in complex
variable theory suffers the real risk of making major mistakes. This book
should serve as an early warning system about these pitfalls.
This book should be read as a companion to standard texts on functions of
a complex variable. Throughout what follows, we refer to two of the author’s
favorites. Not surprisingly, one volume is his own Complex Variables with
Applications (3rd edition) published by Addison-Wesley in 2005. We refer to
this book as “W” in the text. In most cases, the section numbers referred to
apply to the second edition as well. There is a Spanish translation available
for those who prefer that language: Variable Compleja con Aplicaciones. The ref-
erence book in the Schaum’s outline series, Complex Variables, 2nd edition by
M. Spiegel et al. is an old favorite of mine, and although it is more handbook
than textbook, it is remarkably well done, and I will refer to it with the letter
“S.” Notice that the section numbers that I refer to apply to the second edition
only. Complex Variables and Applications by R. V. Churchill and colleagues is
very well written, but the book has had so many editions that it is difficult to
refer the student to any particular section.
References
1. Hunt, B., Lipsman, R., and Rosenberg, J. A Guide to MATLAB for Beginners and
Experienced Users, 3rd edition. New York: Cambridge University Press, 2014.
2. Hahn, B. and Valentine, D. Essential MATLAB for Engineers and Scientists, 5th
edition. New York: Academic Press, 2013.
A. David Wunsch
University of Massachusetts Lowell
Lowell, Massachusetts
A Note to the Reader
To keep the cost of this book reasonable, all figures are rendered in black and
white and shades of gray. Some of the codes provided here will produce only
these colors, while other programs will produce color plots on your screen
even though the plots are in grayscale in your book. In the solutions manual
I have not avoided color.
MATLAB® is upgraded at least once a year with new releases. Its capa-
bilities change and for the most part are improved. This book is based on
R2015a, the release available through most of the year 2015.
Corrections to this book as well as to the solutions manual will be posted
at the author’s web page hosted by the University of Massachusetts Lowell.
Here is the URL: http://faculty.uml.edu/awunsch/wunsch_complex_
variables/faculty.htm.
The author invites corrections and comments for his work. An email
address can be found at the above website where you will also find solu-
tions to the odd numbered problems. To assist readers with data entry in
MATLAB, code text can be found for download at https://www.crcpress.
com/A-MatLab-Companion-to-Complex-Variables/Wunsch/9781498755672.
Instructors using my book in the classroom can also receive a copy of a
complete solutions manual, for all problems, if they write to me on their col-
lege stationary at the ECE Department, University of Massachusetts Lowell,
Lowell, MA 01854, USA.
xv
This page intentionally left blank
1
Complex Arithmetic
z = x + iy (1.1)
where x and y are real numbers, and there is multiplication between the i and
the y. An equally valid representation is
z = x + yi (1.2)
Example 1.1
>> z=3 + 4i
z = 3.0000 + 4.0000i
which is exactly what we hoped for: MATLAB has returned 3.0000 + 4.0000i.
However, entering z = 3 + i4 in the command window will result in an error
message. The value i must appear as the second factor in the multiplication if
i is to be interpreted by MATLAB as a multiplicative factor in z = x + yi. The
practice is only valid if i is preceded by an explicitly stated real (not complex)
number. A symbol cannot be used for that number. This entire convention
can be overlooked provided we employ the MATLAB ✽ for multiplication.
We will adopt that practice throughout this book even though the authors
of MATLAB claim that eliminating ✽ where allowed will speed up calcula-
tions; the advantage is often slight.
1
2 A MATLAB® Companion to Complex Variables
Note that in general, all the arithmetical operations that one does with real
numbers in MATLAB can be carried out for complex numbers, using the
same operators (i.e., the + and − signs for addition and subtraction, the / for
division, the ^ for raising a number to a power, and as noted, the ✽ for mul-
tiplication). The precise meaning of what the ^ will yield when followed by
a fraction will be treated in section 1.3.
To get the magnitude (or absolute value or modulus) of a complex number,
we apply the operation abs to that number. Thus,
Example 1.2
Multiply 3 + i4 by (1 + 2i) and add i2 to that result. Then find the absolute
value of that quantity.
Solution:
>> (3 + i∗4)∗(1 + 2∗i) + 2∗i
ans = −5.0000 + 12.0000i
>> abs(ans)
ans = 13
Electrical engineers often prefer to use j instead of i, and this notation can
be used automatically in MATLAB. We just use j instead of i and follow the
same conventions as above.
You should not use both i and j in the same code, or you will confuse your-
self and whoever reads what you wrote.
Example 1.3
Use j instead of i, and raise (1 + j3) to the –2 power, divide that result by
2 – j3, and subtract 3 + 4j from that result.
Solution:
>> (1 + 3∗j)^(−2)/(2−j∗3)−(3 + 4∗j)
ans = −2.9985 − 4.0277i
Example 1.4
>> z=3 + 4∗i
z = 3.0000 + 4.0000i
>> x=real(z)
x=3
>> y=imag(z)
y=4
>> w=conj(z)
w = 3.0000 − 4.0000i
Comment: Note that in the second instance, the value obtained for a is
which is a row vector with three elements, not the desired two elements. The
first element is 3, and the second is 0 + 1.0000i=i. The error was caused by our
having a space after the 3 and before the adjacent + sign.
4 A MATLAB® Companion to Complex Variables
In the third output for a, we got the correct value even though we typed a
space between the 3 and the plus sign following it.
Note that you can always tell the number of elements in a row or column
vector, let us call it a, with the command length(a). If we apply this operation
to the three values of a described above, we get 2, 3, and 2, respectively.
Exercises
1. Using MATLAB, determine
3 − 4i
a. + i2
1 + i2
2+i
b. − 1 − i/2
3 + 5i
i
(1 + i2/3) −
c.
3
3 − 4i
11
2
1 +
d.
i3
5
2i 1
e.
3 + 4i + 5 − 4i
( )
2. The numerical value of the expression (1 + i)37 can be deter-
mined without recourse to MATLAB by the following technique:
( )
18
(1 + i)37 = (1 + i)36 (1 + i) = (1 + i)2 (1 + i). Now complete the calcula-
tion by evaluating (1 + i)2 and noting that i raised to any even power
is easily computed. Check your answer by using MATLAB to find
(1 + i)37 directly.
3. Consider the finite series (N ≥ 0 is an integer) and its sum.
N
1 − z N +1
∑n= 0
zn =
1− z
z ≠ 1, whose derivation is identical to that given
Sometimes cisθ is used to mean cosθ + i sinθ, but other times, the notation
∠θ is used for the same quantity. Thus,
4.5
4 z
3.5
2.5
r
1.5
1
θ
0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
FIGURE 1.1
The polar coordinates r and θ for the point z.
6 A MATLAB® Companion to Complex Variables
Example 1.5
Find the polar form of the complex number − 3 − i.
Solution:
>> z= −sqrt(3)−i;
r=abs(z)
r = 2.0000
>> theta=angle(z)
theta = −2.6180
>> [th,r]=cart2pol(−sqrt(3),−1)
th = −2.6180
r = 2.0000
Example 1.6
Using MATLAB, compute the angles of the complex numbers −1+eps∗i
and −1−eps∗i and compare them by computing their difference. Recall
that in MATLAB, eps is the smallest possible difference between two
floating point numbers. In the version of MATLAB used in this book,
eps ≈ 2.22 × 10−16. If you type the word eps in the MATLAB command
window, you can find out what eps is for your version of MATLAB. We
chose here to work in the “long” format.
Solution:
>> format long
>> angle1=angle(−1 + i∗eps)
angle1 = 3.141592653589793
>> angle2=angle(−1−i∗eps)
angle2 = −3.14159265358979
>> angle1−angle2
ans = 6.28318530717959
>> 2∗pi
ans = 6.28318530717959
Note that the program does not yield the complex number z = x + iy. It sim-
ply gives the real and imaginary parts of z. To get z, one must take the two
results from above and make that additional computation.
Exercises
1. We know that the polar angle of the product of two complex num-
bers can be expressed as the sum of the angles of each.
( )
a. Multiply (1 + i) by 3 + i using MATLAB. Find the angle of the
product using MATLAB and show that it is the sum of the angles
of each factor.
b. Repeat the above exercise, but use as factors (1 + i) and − 3 + i.
Explain why the angle of each factor, obtained from MATLAB,
when added, does not agree with the angle that MATLAB
yields for the angle of the product. Compute these angles using
MATLAB.
2. When MATLAB is asked for the argument (angle) of a complex num-
ber, it always returns the principal value. Use MATLAB to find the
principal argument of the following numbers where all angles are in
radians except in part (d).
a. 5cis(197)
b. 1/(4∠79)
c. (1 + 2i)17
d. (5cis(53.3°))8 (give answer in degrees)
3. Using the pol2cart function in MATLAB described above, convert
these numbers to rectangular components where the angles below
are in radians:
a. 3cis(−207)
b. 4∠50
4. Write a new function, similar to the pol2cart function in such a
way that if it is given θ in degrees and r, it will convert the polar
form of the number to rectangular form. Call the new function
pold2cart. Use it to convert these numbers to rectangular form.
Give x and y.
a. 5∠60°
b. 2∠(−320°)
Complex Arithmetic 9
where as we recall, cisϕ = cosϕ + i sinϕ. This result is consistent with the defi-
nition zn/m = (z1/m)n. Notice the order of the operations.
In what follows, we will take m as positive and skip the absolute magnitude
signs around the m. We can do this because it is easily shown that the set of
values of z−n/m is identical to the set of values of zn/(−m). Thus, given the prob-
lem of computing (1 + i)2/(−3), we can compute the set of values of (1 + i)−2/3
and use a positive m.
Equation 1.5 is equivalent to
( r) n n
n
z n/m = m
cis θ cis 2 kπ k = 0, 1, 2,... (m − 1) (1.6)
m m
which arises from the identity cis(α + β) = cisαcisβ; it applies to any numbers
α and β. Note that in Equation 1.6, we can generate the same set of values
for zn/m if we let k go through any set of m consecutive integers, for example,
1,2, … m.
The results from Equations 1.5 and 1.6 are m numerically distinct values.
When plotted as points in the complex plane, they all lie on a circle having
( )
m
radius n r (i.e., they have identical magnitudes). The angular spacing of
these values is 2π/m. The separation of these points on the circle is uniform.
10 A MATLAB® Companion to Complex Variables
If you ask MATLAB for the computation of a fractional power, for example,
(81i)3/4, you will receive exactly one value, in this case, 10.3325 + 24.9447i, which
in polar form is 27 ∠1.1781…. The angle here is 3π/8 radians. According to
Equations 1.5 and 1.6, there are three other values for (81i)3/4. After some experi-
mentation with MATLAB, you will see how it decides which value of zn/m to
give you.
MATLAB Rule for Fractional Powers The angle θ in Equations 1.5 and 1.6 is
taken as the principal value, and the value of k is set equal to zero. MATLAB returns
the result in Cartesian form.
You should confirm that this convention yields the MATLAB result just
given for (81i)3/4.
Example 1.7
Use Equation 1.5, taking the MATLAB convention for fractional pow-
ers, to determine one value of (−1 − i)2/3, and verify that MATLAB does
indeed yield this value.
Solution:
We have −1 − i = 2 ∠(−3 π / 4), where the principal value of the argument
of (−1 − i) is used.
Using Equation 1.5, with k = 0 we have
( 2 ) ∠ −3 π4 23 = π
2/3 2
(−1 − i)2/3 = 2 ∠ ( −3π / 4 ) = 3 3
2 ∠ − = −i 3
2
2
Proceeding with MATLAB, we have
>> (−1−i)^(2/3)
ans = 0.0000 − 1.2599i
These two answers are numerically identical because the cube root of
2 is 1.2599….
If we compute a value of zn/m and raise it to the m/n power, do we necessar-
ily get back z? That is, does (zn/m)m/n equal z when the inner and outer opera-
tions are done in MATLAB? Because MATLAB will choose just one value of
the n possible values when raising a number to the m/n power, you cannot
say for certain that in MATLAB (zn/m)m/n = z.
( )
3/4
The reader should confirm that in MATLAB we have (−1)4/3 = −i, so the
original z (namely, −1) is not returned. The result comes about because the
principal angle of −1 is π. When MATLAB evaluates (−1)4/3 using this angle,
−1 3
and the rule stated above, the result is −i whose polar representation,
2 2
π
using the principal angle, is 1∠ −2 . Raising the preceding to the ¾ power
3
using the MATLAB rule for fractional powers, we get 1∠ − π = − i .
2
Complex Arithmetic 11
( )
3/4
For a different problem, MATLAB yields (− i)4/3 = − i. The value of z
is returned. One should be able to predict in advance whether the original
z is obtained if we compute (zn/m)m/n. This matter is explored in problem 2 in
the Exercises.
and yield all m roots. The procedure is to ask MATLAB for roots(p), where p
is a row vector whose entries, from left to right, are the numerical coefficients
c1, c2, … cm + 1. Note that if we take c1 = 1, c2 = 0, c3 = 0, … cm + 1 = −z in the poly-
nomial equation, we obtain wm −z = 0 whose solutions all satisfy w = z1/m.
12 A MATLAB® Companion to Complex Variables
Suppose for example we wanted all six values of (1 + i)1/6. This is the same
problem as finding all six solutions of the polynomial equation w6 − (1 + i) = 0.
The expression on the left is a polynomial of degree 6. We should see that
this polynomial has coefficients of zero for the terms w5, w4, …, w, while the
coefficient of w0 is −(1 + i). Thus, to solve our polynomial sixth-degree equa-
tion in w, we proceed as follows:
The above are the six values of (1 + i)1/6. The following provides a check.
>> ans.^6
ans =
1.0000 + 1.0000i
1.0000 + 1.0000i
1.0000 + 1.0000i
1.0000 + 1.0000i
1.0000 + 1.0000i
1.0000 + 1.0000i
There is some round-off error, which is hidden because we are using short
format, but each of these expressions is, to our degree of approximation,
(1 + i). This is correct, as we expect all six values of (1 + i)1/6 when raised to
the sixth power to yield (1 + i).
Suppose we want all seven values of (3 + 4i)5/7. We would proceed as
before, calculating (3 + 4i)1/7. We would then take all seven of these values
and raise them to the fifth power. Here is the procedure:
The output is
final_answer =
−3.0852 − 0.6691i
0.0342 + 3.1567i
3.0700 − 0.7358i
−1.4005 − 2.8293i
1.3388 − 2.8590i
−2.4467 + 1.9950i
2.4894 + 1.9414i
Note that there are seven answers, as expected. The first line of our code
coeffs=zeros(1,8); establishes a row vector having eight elements. Initially all
eight are zero. Then we set the first element equal to one and the last equal
to –(3 + 4i).
The above technique can be applied to finding all |m| values of zn/m when
m is a negative integer. We compute z−n/|m| and proceed as above, first finding
the |m| values of z1/|m| and then raising them to the –nth power.
Suppose we were to take each of the values of (3 + 4i)5/7 obtained above
and, using MATLAB, raise them all to the 7/5 power. Can we expect in each
case to recover (3 + 4i)? Trying this, we have
Notice that only one of these results is the original 3 + 4i. This is because
there are five possible values of a number raised to the 7/5th power. Just one
( )
7/5
of the above yields ultimately to our having (3 + 4i)5/7 = 3 + 4i.
Keep the following in mind: Suppose using any method at your disposal
you compute all |m| values of zn/m, where n and m are integers, and m ≠ 0.
Now suppose you raise each value to the m/n power using the MATLAB
expression V^(m/n), where V is any one of those m values of zn/m. There is no
guarantee that you will get back z. A simple example will suffice. We know
that (−1)3/2 = (−1)1/2 (−1) = ±i. From MATLAB, we raise both i and −i to the
2/3rds power:
>> i^(2/3)
ans = 0.5000 + 0.8660i
14 A MATLAB® Companion to Complex Variables
>> (−i)^(2/3)
ans = 0.5000 − 0.8660i
In neither case did we recover –1. However, if you computed all values of
i 2/3 and (–i)2/3, you would find in each case that one of the values obtained
is –1.
As an exercise, the reader should modify the above code so that the user
is prompted to enter an integer n and a positive integer m where the fraction
n/m is irreducible. The program then computes all m values of zn/m where
again z must be supplied.
Example 1.8
Using the MATLAB plot function, graph w = x1/3 for the interval −2 ≤ x ≤ 2
and explain your result. Use at least 100 data points.
Solution:
x = linspace (−2,2,101);
w = x.^(1/3);
plot(x,w);grid
1.4
1.2
0.8
0.6
0.4
0.2
0
–2 –1.5 –1 –0.5 0 0.5 1 1.5 2
x
FIGURE 1.2
The plot for Example 1.8.
16 A MATLAB® Companion to Complex Variables
1 2
x 1/3 = 3 x ∠ θ + 2 kπ k = 0, 1, 2
3 3
1
x 1/3 = 3 x ∠ π
3
13
In our preceding graph above, we have the curve x for x < 0 because
2
only the real part of x1/3 is plotted by MATLAB. This is exactly half the
value obtained for the corresponding positive values of x and is con-
firmed if we study the plot.
To properly graph x1/3 over the given interval, we must employ both the
real and imaginary parts of this function as in the following code:
x = linspace (−2,2,101);
w = x.^(1/3);
plot(x,real(w),'−',x,imag(w),'*')
grid
The reader should verify this. Note that axis equal ensures that a cir-
cular plot appears. Without it, MATLAB might use different scales for
the two axes, and the circle would be distorted into an ellipse.
We could have also just plotted 100 stars, like this ∗, for the data points
and not obtained a continuous graph if we used plot(w,’∗’) instead of
plot(w). Here is the result. (See Figure 1.4.)
Complex Arithmetic 17
1.4
Real part
1.2
Imaginary part
0.8
Imaginary part
0.6
0.4
Real part
0.2
0
–2 –1.5 –1 –0.5 0 0.5 1 1.5 2
x
FIGURE 1.3
Plots for x1/3.
–2
–4
–6
–8
–10 –5 0 5 10
FIGURE 1.4
Values of 10eiθ generated by letting θ go through 100 values between 0 and 2π.
18 A MATLAB® Companion to Complex Variables
And while we are on the subject of plot, here is a further peril involv-
ing plot when you are using vectors with complex elements together
with vectors having real elements. Consider the following:
clf
a =[1 + i 5 + 5*i 10 + 10*i];
b =[1 5 10];
plot(a,'k−','linewidth',2);hold on
text(4,4,'the plot of a')
plot(a,'o')
plot(b,'k−','linewidth',2);
plot(b,'o');
text(2.2,5,'the plot of b');grid
We obtain Figure 1.5.
The plot of the vector a shows its imaginary elements plotted against
their corresponding real parts. They all lie on the line y = x, which makes
a 45-degree angle with the real axis.
Now the vector b has only real elements, which are 1 and 5 and 10.
The imaginary part of each element is zero. So, following the logic used
by MATLAB in making the plot for a, we would expect that these points
would occur on the line y = 0 at x = 1 and 5 and 10. We would expect
MATLAB to connect these points with a horizontal line.
10
6
y
The plot of b
5
The plot of a
1
1 2 3 4 5 6 7 8 9 10
x
FIGURE 1.5
Perils of using the plot function.
Complex Arithmetic 19
Exercises
1. Using MATLAB, obtain one numerical value for each of the follow-
ing by simply asking for a^b.
a. (−27i)2/3
b. (1 + i)1/15
c. (−1−i)1/9
2. Without using MATLAB, but knowing its convention for produc-
ing fractional roots, predict whether or not the use of MATLAB will
yield these results, and explain your logic:
a. (i1/2)2 = i
b. (i3/2)2/3 = i
c. ((−1)4/3)3/4 = −1
d. ((−1)3/4)4/3 = −1
e. ((−1 + i)5/3)3/5 = −1 + i
f. Now confirm your predictions for parts (a) through (e) by using
MATLAB.
3. Using roots, as discussed, find all values of the following and in
each case plot the values using a ∗ to mark their location.
a. (1 + i)24/5
b. (3 − 4i)5/7
c. (13 + 7i)100/99 (be sure to use the function zeros in this case to cre-
ate the coefficients for roots)
4. Using Equation 1.6, we can sum all the m possible values of zn/m. The
result is
m− 1
( r) cis θ
n
∑ cis 2kπ n
n
S= m
m m
k=0
m− 1
( r) cis θ
n
∑ (cis(2πn/m))
n k
S= m
m k=0
m− 1
∑ zk =
1 − zm
1− z
z≠1
k=0
m− 1
1 − cis(2 πnm/m)
∑ ( cis(2πn/m))
k
= = 0 since cis(2πn) = 1
k=0
1 − cis(2 πn/m)
Using MATLAB, find all the values of (1 + i)11/7 and sum them
together. Note that you will not get exactly zero. This is due to
round-off errors in MATLAB. However, the sum should be many
orders smaller than the magnitude of any one root.
5. Compare Figures 1 and 2 obtained from this program, explaining
differences and similarities:
clf; clear
x = linspace (−3,3,301);
w =(x−1).^(2/5);
figure(1)
plot(x,w);grid;
figure(2)
plot(x, real(w),'−',x,imag(w),'*')
grid;
6. Modify the program given in the text, which computes z1/m so that
when supplied with integers n and a positive m (these numbers have
no common factors), it will compute all m values of zn/m. Try the prob-
lem out by computing (27i)2/3 and (27i)−2/3.
Complex Arithmetic 21
1 c + id
w= +
a + ib e + if
if w = u + iv, where u and v are real. Our problem is to find u and v in terms
of a, b, c, d, e, f.
Problems such as these are solved in MATLAB by using the statements
syms or sym. These two statements are not identical in what they do. The
reader might wish to investigate them both in the Help window of MATLAB.
In general, syms is slightly more useful, and we will favor it, but we also use
sym. Briefly, if a and b are symbols, we write
syms a; syms b
or more concisely
syms a b
We can put any other symbols we might be using in the above statement
after a and b. Suppose a is a symbol for a real quantity but b can be complex.
Then our code would contain
syms a real; syms b
However, if both a and b must be real, then we have
syms a b real;
We could have included other symbols that are real after the a and b.
The following program shows how to obtain the real part of the symbolic
expression for u, which is the real part of w given above.
syms a b c d e f real
w = 1/(a + i*b)+(c + i*d)/(e + i*f);
u = real(w)
u = expand(u)
'prettier answer for u'
pretty(u)
22 A MATLAB® Companion to Complex Variables
The output is
u = real((c + d∗i)/(e + f∗i)) + a/(a^2 + b^2)
u = a/(a^2 + b^2) + (c∗e)/(e^2 + f^2) + (d∗f)/(e^2 + f^2)
a ce df
ans = prettier answer for u a 2 + b 2 + e 2 + f 2 + e 2 + f 2
± x + x2 + y 2 − x ± x2 + y 2
z1/2 = ( x + iy )1/2 = ±i
2 2
However, we cannot write a program like the one given above that will
give this result.
>> b = sym(sqrt(5))
b = 5^(1/2)
>> b^7
ans = 125∗5^(1/2)
In the first instance, we raised the square root of five to the seventh power
and came up with a decimal answer of around 279.50. In the second instance,
we treated the square root of 5 as a symbol. Raising this to the seventh
power we get 125 times the square root of 5. Sometimes this is more conve-
nient. If we now want this result as a decimal we add the line
>> eval(ans)
which again yields
ans = 279.5085
( )
11
Now, consider the following where we find 5 +i 7 :
We know from the binomial theorem that our final result should be
expressible in terms of the square root of 5 and the square root of 7 and
integers. But how?
>> a = sym(sqrt(5));
>> b = sym(sqrt(7));
>> z = (a + i∗b)^11
z = (5^(1/2) + 7^(1/2)∗1i)^11
>> expand(z)
ans = −381952∗5^(1/2) − 7^(1/2)∗44032i
This gives the desired result that we can now check against our first
answer.
>> eval(ans)
ans = −8.5407e + 05 − 1.1650e + 05i
a ans
b z
24 A MATLAB® Companion to Complex Variables
>> sin(1000∗pi)
ans = −3.2142e−13
>> sin(1000∗sym(pi))
ans = 0
The first answer is wrong—it results from round-off error. The second one
is correct. By using pi as a symbol, we have MATLAB evaluating sinπ and not
the sine of a numerical approximation to the irrational number.
Exercises
1. Use MATLAB to extract the real and imaginary parts of the expression
1 1 i
w= + +
x iy (( x − 1) + iy )2
where x and y are real. Use the pretty command to make your
answers as easy to read as possible. Use MATLAB to evaluate your
expressions, when x = 1 and y = 1. Note that for these values the
numerical results are easily checked by inspection.
2. Consider the expression
1
z = R + iX =
1 1
+
r1 + ix1 r2 + ix2
where R, X, r1, r2, x1, x2 are all real quantities. This notation is com-
mon in electrical engineering. Write a MATLAB program that will
give explicit expressions for R and X expressed entirely in terms of
real quantities. In addition, have your program determine the values
of R and X if r1 = r2 = 2 and x1 = x2 = 4. Also, consider the case where
x1 = −x2 = 4 and again r1 = r2 = 2.
3. Using MATLAB, find the real and imaginary parts of
1
( x + iy )3
4. Let
6
z
w = u + iv =
z
13
1
2 − i 3
This page intentionally left blank
2
Loci and Regions in the Complex Plane
and Displaying Complex Functions
27
28 A MATLAB® Companion to Complex Variables
0 1 2
0 1 2
x=
0 1 2
0 1 2
3 3 3
5 5 5
y=
6 6 6
7 7 7
Note that x is no longer a row vector but a matrix, all of whose rows are
identical to one another; these rows are the old row vector x = [0 1 2]. The
number of rows is taken to be the number of elements in the old row vector
y = [3 5 6 7]. One could also say that the number of rows in the new matrix x
is equal to the number of rows in the transpose of the old row vector y.
Observe that y is now a matrix, all of whose columns are identical to one
another; these columns are the vector that is the transpose of the old row
vector y. The number of columns in the new matrix y is taken to be equal
to the number of elements in the row vector x; thus, the dimensions of the
matrices x and y are identical.
Now consider z = x + iy which in MATLAB is
>> format short
>> z=x+i∗y
>> w=z.^2
Note the necessity for the period (the dot) after the z in the first line. This
causes MATLAB to square each element in z. Without the period, the matrix z
would be squared if that were possible.
We can now make three-dimensional plots of the real and imaginary parts
of w as functions of x and y. Calling these u(x,y) and v(x,y), respectively, we
can extract their values from the above matrix as follows:
>> u=real(w)
−9 −8 −5
−25 −24 −21
u=
−36 −35 −32
−49 −48 −45
>> v=imag(w)
0 6 12
0 10 20
v=
0 12 24
0 14 28
the plot in the x−y plane. Z is a real variable that depends on x and y. Do not
confuse it with the complex variable z. For example, Z might be the variable
v just described. We then have, plotting v,
>> mesh(x,y,v);
colormap(gray)
colorbar
xlabel('x');ylabel('y');
title('Imag(z^2)')
25
30
25 20
20
15 15
10
5 10
0
7
6 2 5
5 1.5
y 1
4 x
0.5 0
3 0
FIGURE 2.1
The imaginary part of z2.
Loci and Regions in the Complex Plane and Displaying Complex Functions 31
be in color and would instruct you how to interpret the colors resulting in
the “fishnet.” You should now try obtaining a color plot on your computer.
The subject of color mapping in MATLAB is rather detailed, and the reader
is referred to the topic colormap in the help menu.
The plot given in Figure 2.1 is the view of the surface seen by an observer
whose azimuth position is at −37.5° and whose elevation is 30°. The mean-
ing of these angles is shown in Figure 2.2, which was downloaded from the
MathWorks, Inc., website. These are the default angles that MATLAB uses
in providing three-dimensional plots. Sometimes this is not the best angle
from which to view a three-dimensional surface. If you attempt a plot of
u = Re(z2) = x2 − y2, using the default angles, you will most likely be confused
by the picture thus obtained (try this). Instead, after some experimentation,
we find that azimuth and elevation of 45 and 60 degrees, respectively, give
a better picture. To avoid the default view, enter the line of code view(az,el)
right after the line of code that generates the plot. You must, of course, assign
numerical values to az and el, the desired azimuth and elevation (in degrees)
to use this code.
This better plot is shown in Figure 2.3, where we also show the code
employed. Note that the grid lines used are more numerous than those we
employed in generating Figure 2.1. For x we use 10 values uniformly spaced
on the interval 0 ≤ x ≤ 2, and for y there are 20 values uniformly spaced on
the interval 0 ≤ y ≤ 7. The result is a surface with finer increments in x and y
than would have been obtained from the grid formed for Figure 2.1. Note the
line of code view(45,60) as mentioned.
Viewpoint
y
Center of
plot box x
Elevation
Azimuth
–y
FIGURE 2.2
The default MATLAB viewing angles.
32 A MATLAB® Companion to Complex Variables
–5
–10
50 –15
–20
0
–25
–50 –30
0 8
–35
0.5 6
1 4 –40
x y
1.5 2 –45
2 0
FIGURE 2.3
Real part of z2.
x=linspace(0,2,10);
y=linspace(0,7,20);
[x y]=meshgrid(x,y);
z=x+i*y;
w=z.^2;
u=real(w);
mesh(x,y,u);view(45,60);colormap(gray);colorbar
xlabel('x');ylabel('y')
title ('real part of z^2')
–5
–10
50 –15
–20
0
–25
–50 –30
0 8
–35
0.5 6
1 4 –40
x y
1.5 2 –45
2 0
FIGURE 2.4
The real part of z2.
Exercises
1. Consider the function f(z) = z + 1/z. Plot the real and imaginary parts
of this function over the region described by .5 ≤ x ≤ 2 and .5 ≤ y ≤ 2.
Use 50 uniformly spaced increments in x and y. Use the default val-
ues for view. Note that you can generate multiple plots from the
same program by using such commands as figure(1), figure(2), and
so on, placed as code before you call plotting functions such as mesh,
meshz, surf, and so on. Try plots in both color and shades of gray.
a. Plot each surface using the function mesh. Use the default values
for the view.
b. Plot each surface using the MATLAB function meshz.
c. Plot each surface using the MATLAB function surf.
d. Find new values for azimuth and elevation such that you can
improve or make more interesting at least one of the above surfaces.
2. The exponential function f(z) = ez = ex cos y + iex sin y is entire (every-
where analytic) and is the most basic transcendental function in
complex variable theory. Write a single program that will produce
four different plots as described below. The plot should be over the
rectangular region −2 ≤ x ≤ 2, −8 ≤ y ≤ 8. Use 40 uniformly spaced data
points for x and 80 for y and employ one of the plotting functions
34 A MATLAB® Companion to Complex Variables
* More correctly, this is a first-order saddle point. For more information on saddle points, see
any standard text on advanced calculus.
Loci and Regions in the Complex Plane and Displaying Complex Functions 35
x=linspace(-2.5,2.5,100);
y=linspace(-2.5,2.5,100);
n=linspace(-2,2,5);
[x,y]=meshgrid(x,y);
z=x+i*y;
w=z.^2;
wi=imag(w);
[c,h]=contour(x,y,wi,n);colormap(gray)
xlabel('x');ylabel('y');title('Contour Lines for Im(z^2)')
grid
clabel(c,h)
2.5
–2
2
1.5
–1
1
1
0.5 –2 2
–1 1
0
0 0 0
y
1 –1
0
–0.5 2 –2
–1
–1
–1.5
1
2
–2
–2
–2.5
–2.5 –2 –1.5 –1 –0.5 0 0.5 1 1.5 2 2.5
x
FIGURE 2.5
Contour lines for Im(z2).
hold on
wr=real(w);
[d,h]= contour(x,y,wr,n);colormap(gray)
clabel(d,h)
2.5 –
1 01 –2
2 –1 1
–2
2
2
1.5 –2
–1
0
1
1 –1
2
0.5 –2 0 2
–1 1
0
0 0 0
1
y
1 –1
0
2 0 –2
–0.5
2
–1 –1
0
1
–1
–1.5 –2
2
–2
–2
2
–1 –2 0
–1 1
1
–2.5
–2.5 –2 –1.5 –1 –0.5 0 0.5 1 1.5 2 2.5
x
FIGURE 2.6
Contour lines for real and imag (z2).
on which u(x,y) assumes m different values of its own choosing. The value
assumed on each contour by u(x,y) chosen by MATLAB can be read off each
plot provided you are using the command clabel(d,h), as described above.
Note that it is possible that you might apparently see more than m plots: for
example, Im(z2) = 2xy = 2 is satisfied by a curve in the third quadrant and one
in the first. Both are branches of the same hyperbola.
Suppose you want the contour on which a function assumes just one
numerical value, let us call it v1. Then in the expression contour (x,y,Z,V),
enter for V the vector [v1 v1]. The matter is explored in problem 2.
Exercises
1. For the region −3 ≤ x ≤ 3, −3 ≤ y ≤ 3, use MATLAB to plot the contours
on which
a. Re(ez) has the values 0 and ±1.
b. Repeat part (a) but use the imaginary part.
c. Plot the results of parts (a) and (b) on the same set of coordinates,
and verify that the intersections of the curves appear orthogonal.
d. Repeat part (a) but have MATLAB automatically choose five
values on which Re(ez) is constant. Compare the plot to the one
obtained in part (a). Do you see any disadvantages to having
MATLAB choose the values?
2. a. For the region −3 ≤ x ≤ 3, −3 ≤ y ≤ 3 use MATLAB to plot the con-
2
tours on which e z has the integer values 2 through 5.
b. Explain why each of these contours is hyperbolic in shape, and
find the equations of these hyperbolas.
2
c. Use MATLAB to plot just the contour on which e z is 1, and
explain why this has degenerated into something that does not
look like a hyperbola.
3. a. For the region −2.5 ≤ x ≤ 2.5, −2.5 ≤ y ≤ 2.5, use MATLAB to plot
the contours on which |cos z − cosh z| assumes the integer val-
ues 0 through 4.
b. You should observe that there is no contour on which |cos z −
cosh z| = 0, although this equation is satisfied at z = 0. Explain
how one could predict in advance the absence of such a contour.
Hint: Recall that the zeros of a nonconstant analytic function
are isolated (i.e., each zero has a deleted neighborhood through-
out which the function is nowhere zero). See, for example,
W section 5.7.
Loci and Regions in the Complex Plane and Displaying Complex Functions 39
4. a. For the region −2.5 ≤ x ≤ 2.5, −2.5 ≤ y ≤ 2.5, use MATLAB to plot
the contours on which Re(cos z − cosh z) assumes the integer
values 0 through 4. On the same set of axes, plot the contours on
which Im(cos z − cosh z) assumes these values.
b. Observe that the two sets of contours obtained in part (a) inter-
sect at right angles except at one point. What point is this?
Explain this in terms of the vanishing of the first derivative of
cos z − cosh z at the point in question. See W section 2.5 and S
section 3.12 for some help.
x=linspace(-4,4,1000);
y=linspace(-4,4,1000);
[x,y]=meshgrid(x,y);
z=x+i*y;
40 A MATLAB® Companion to Complex Variables
w=abs(z-i);
v=abs(z+i);
ww=(w<=2);
vv=(v<=2);
tt=ww&vv;
meshz(x,y,-tt);colormap(gray)
view(2);
hold on
x=linspace(-4,4,9);
y=x;
[x y]=meshgrid(x,y);
plot(x,y,'r');plot(y,x,'r');axis equal
tle('The Intersection of the Sets |z-i|{\leq}2 and |z+i|
ti
{\leq}2')
xlabel('x');ylabel('y')
In the first through third lines, we form a very tightly spaced mesh in the
region −4 ≤ x ≤ 4 and −4 ≤ y ≤ 4, where z = x + iy is evaluated at the 10002 =
one million intersections of the mesh. The variable w = |z − i| is found at
each of these values of z. Similarly, we find v = |z + i| at these same values.
The line of code ww=(w<=2) supplies us with a matrix ww whose elements
are equal to 1, where the inequality |z − i| ≤ 2 is satisfied in the complex
plane. Where the inequality is not satisfied, the matrix has the matrix ele-
ment 0. Similarly, vv=(v<=2) gives us a matrix vv having elements equal to 1
where the inequality |z + i| ≤ 2 is satisfied, and if the inequality is not satis-
fied, we get elements of 0. The logical statement tt=ww&vv yields a matrix
having ones only where both ww and vv have ones. Otherwise, the matrix
element is 0. Thus, tt has ones where the inequalities |z − i| ≤ 2 and |z + i| ≤
2 are both satisfied—that is, at the intersection of the sets specified by these
two inequalities. The code meshz(x,y,-tt);colormap(gray) gives a three-
dimensional plot of this matrix over the complex z plane. The plot is best
viewed from directly above the plane, with a downward view. The MATLAB
statement view(2) accomplishes this. The surface generated by these closely
spaced points through the use of meshz(x,y,-tt) is either 1 unit below the
x−y plane (where the two inequalities are satisfied) or directly on this plane.
The use of the minus sign in –tt in the meshz argument together with the
grayscale colormap place a black mark in the complex plane where both |z
− i| ≤ 2 and |z + i| ≤ 2 are satisfied. Thus, as shown in Figure 2.7, we have a
plot of the intersection of the two given sets.
Had we used the code line meshz(x,y,tt); (without the minus sign), we
would have generated an image in which the region, which is the union of
|z − i| ≤ 2 and |z + i| ≤ 2, would have been displayed in white while the
remainder of the complex plane would be black; this is contrary to common
usage for displaying regions in complex variable texts.
We have not generated the grid of lines that you see in the figure by
using the usual command of grid following the plot. This command would
create a grid based on the data points—one with lines too closely spaced
Loci and Regions in the Complex Plane and Displaying Complex Functions 41
0
y
–1
–2
–3
–4
–5 –4 –3 –2 –1 0 1 2 3 4
x
FIGURE 2.7
The intersection of the sets |z−i| ≤ 2 and |z+i| ≤ 2.
The resulting program now yields a plot showing the union of the sets|z − i|
≤ 2 and |z + i| ≤ 2. The result is shown in Figure 2.8.
The method presented here has its limitations. If the region being described
is unbounded, then we cannot display the entire region as some uniformly
colored area of the complex plane; we can only hope to show some por-
tion of that region. For example, the union of the sets |z| ≤ 2 and Re(z) > 0 is
unbounded, a fact we should realize before attempting plots like those in the
preceding two figures. We would thus see only a portion of the sought-after
set on the screen. Its unboundedness is something we would have to see in
advance, or we could convince ourselves of this fact by trying grids covering
increasing areas in the complex plane. Another difficulty with the method
presented relates to the boundary points of sets. The set described by |z| ≤ 3
is a closed set and contains all its boundary points, but the set |z| < 3 is an
open set and contains none of its boundary points. However, were we to
apply the MATLAB method described above to displaying both of these sets,
we would generate identical figures. So, one must be careful about boundary
points, and one should find them by studying the inequalities that one has
been given.
We are not limited to codes that find the union or intersection of two sets. In
fact, the number of sets involved is practically unlimited. Suppose we want
to find the intersection of these three sets: |z − 1| ≤ 1, |z − i| ≤ 1, and |z + i| ≤ 1.
0
y
–1
–2
–3
–4
–5 –4 –3 –2 –1 0 1 2 3 4
x
FIGURE 2.8
The union of the sets |z−i| ≤ 2 and |z+i| ≤ 2.
Loci and Regions in the Complex Plane and Displaying Complex Functions 43
w=abs(z-1);
v=abs(z-i);
s=abs(z+i);
ww=(w<=1);
vv=(v<=1);
ss=(s<=1);
tt=ww&vv&ss;
The remainder of the code would be that used to generate Figure 2.7,
beginning with the line meshz(X,Y,-tt);colormap(gray);. Of course, the
title of the plot would be different. A similar technique can be used to find
the union of these sets.
x=linspace(-4,4,1000);
y=linspace(-4,4,1000);
[x,y]=meshgrid(x,y);
z=x+i*y;
w=abs(z-i);
v=abs(z+i);
ww=(w<=2);
44 A MATLAB® Companion to Complex Variables
vv=(v<=2);
tt=ww&vv;
h=pcolor(x,y,-tt);
set(h,'EdgeColor','none');colormap(gray);grid;axis equal
set(gca,'layer','top'); %required if you hope to see the grid
%sets the grid over the plot
ti
tle('The Intersection of the Sets |z-i|{\leq}2 and |z+i|
{\leq}2')
xlabel('x');ylabel('y')
Exercises
1. Write MATLAB code that will display the union of the sets |z − 1| ≤ 1
and |z − i| ≤ 1/2.
2. Write MATLAB code that will display the union of the sets |z − 1|
≤ 1, |z − i| ≤ 1, |z + i| ≤ 1.
3. Write MATLAB code that will display the intersection of these sets:
|z − 2| ≤ 3, |z−1−i| ≤ 2, Re(z) ≤ Im(z).
4. Write MATLAB code that will display the intersection of these sets:
|sin z2|≤ 1, |z| ≤ 1.
5. Using the complex plane and the random number generator in
MATLAB, you can find π, approximately. The method to be described
here is an example of a Monte-Carlo method, and the reader is
encouraged to read the history of this subject in the Wikipedia.
Suppose you draw a square and a circle on a piece of paper. The
circle is of a unit radius and the square has sides of length 2, and
the circle is inscribed inside the square, which means that it will
be tangent to the sides. Suppose you drop some tiny seeds on the
square, at random, in such a way that there is uniform probability of
a seed landing at any point on the square. Thus, the chance of a seed
landing inside the circle is π/4. This is just the ratio of the area of the
circle to the area of the square. We can use this fact to approximately
compute π with MATLAB. Place the center of the circle at z = 1 + i in
the complex plane. The sides of the square are given by the four lines
x = 0, x = 2, y = 0, y = 2.
a. Write a MATLAB code that randomly generates the x coordi-
nates of 1000 points and the y coordinates of 1000 points. Each of
these coordinates must be positive and be less than 2.
Loci and Regions in the Complex Plane and Displaying Complex Functions 45
* There is also such a thing as a function with a nonisolated essential singular point, for exam-
ple, 1/sin(π/z). Observe that every neighborhood of z = 0 will contain another singular point
besides z = 0 at the origin. You cannot find a neighborhood of z = 0 containing just one singu-
lar point. We will not treat such functions here.
46 A MATLAB® Companion to Complex Variables
These singularities most often occur on branch cuts; the branch cut is a means
of creating a single-valued branch of what would otherwise be a multival-
ued function.* An example is f(z) = z1/2, a branch of which we might define by
means of a branch cut lying along the line x = 0, y ≤ 0 together with the fact that
we choose f (1) = −1. Every point on the line x = 0, y < 0 is a singular point of f(z),
because f(z) changes discontinuously as we cross such a point. Moreover, f(z)
fails to be analytic at z = 0, which makes z = 0 a singular point as well.†
Finally, there are isolated singular points that can be removed through
a proper definition of the function at such a point. These singularities are
sin z
known as removable. The most common example is the function f ( z) = .
z
This function is not defined at the origin as you are here dividing 0 by 0. If
one asks MATLAB to evaluate such a function at the origin, an error message
is generated. However, an application of L’Hôpital’s rule shows that the limit
sin z
of this function as z → 0 is 1. If we define f ( z) = z ≠ 0 and f(0) = 1, we
z
have a new function that agrees with the old except at z = 0. Moreover, the
z2 z 4
new function is the sum of the convergent power series 1 − + + ... and
3! 5!
is therefore analytic wherever this series converges—in this case, the whole
complex plane including the origin. We see that by properly defining a func-
tion at an isolated singular point, we can remove its singularity at that point.
The original function is said to have a removable singularity at this isolated
singular point.
branch of z1/2.
Loci and Regions in the Complex Plane and Displaying Complex Functions 47
x=linspace(-5,5,101);
y=linspace(-1,1,51);
[x,y]=meshgrid(x,y);
z=x+i*y;
w=sin(z+eps)./(z+eps);
wi=imag(w);
meshz(x,y,wi);colormap gray
grid on
title('The Imaginary Part of sin(z)/z')
xlabel('x');ylabel('y')
0.5
–0.5
1
0.5 5
0
0
y –0.5
–1 –5 x
FIGURE 2.9
sin( z)
The imaginary part of .
z
48 A MATLAB® Companion to Complex Variables
x=linspace(-1,1,200);
y=linspace(-1,1,200);
[x,y]=meshgrid(x,y);
z=x+i*y;
w=cos(z)./(z);
wm=abs(w);
meshz(x,y,wm);colormap gray
grid on
* Recall that in the statement x=linspace(a,b,n) one element in the row vector for x is exactly
halfway between a and b if n is odd.
Loci and Regions in the Complex Plane and Displaying Complex Functions 49
x=linspace(-1,4,150);
y=linspace(-1,1,150);
[x,y]=meshgrid(x,y);
z=x+i*y;
f=z.*(z-2).^2;
150
100
50
0
1
0.5 1
0 0.5
–0.5 0
y –0.5
–1 –1 x
FIGURE 2.10
cos( z)
The magnitude of .
z
50 A MATLAB® Companion to Complex Variables
40
30
20
10
0
1
0.5 1
0 0.5
0
y –0.5 –0.5
–1 –1 x
FIGURE 2.11
cos( z)
A better plot of the magnitude of .
z
f=1./f;
f=abs(f);meshz(x,y,f);
axis([-.5 2.5 -1 1 0 30]);colormap gray
title('The Magnitude of 1/(z(z-2).^2)')
xlabel('x');ylabel('y')
view(10,15)
30
25
20
15
10
5 1
0
0 y
–0.5 0 0.5 1 –1
1.5 2 2.5
x
FIGURE 2.12
1
The magnitude of .
z( z − 2)2
The proper choice of the arguments in view may be critical when we study
functions with pole singularities. If a function has more than one pole sin-
gularity, it is possible that we might not see all of the poles when we make
a three-dimensional plot of the magnitude of this function if our perspec-
tive in viewing the plot is poorly chosen. For example, if the line of code
in the preceding program is changed from view(10,15) to view(90,15),
the resulting plot will show only the second-order pole at z = 2 because the
simple pole at the origin will be obscured. To avoid these situations, we can
make contour plots of the magnitude of the function under study.
If a function f(z) has a pole of order N at z0, we have in a neighborhood of
φ( z) c− N
z0 that f ( z) = ≈ . The approximation becomes increasingly
( z − z0 ) N ( z − z0 ) N
valid as z approaches z0. Here ϕ(z) is a function that is analytic in a neighbor-
hood of z0, while C−N = ϕ(z0) ≠ 0.
Thus, near a pole, approximately, the magnitude of f(z) is constant on
contours on which |z − z0| is constant (i.e., on circles centered at z0). The
magnitude grows larger as we consider circles of diminishing radius.
Contour plots of the magnitude of a function near a pole are thus circles
concentric with the pole. At some point, sufficiently far from the pole, these
plots may cease to be circular, because we are beyond the neighborhood
c− N
in which f ( z) ≈ is a fair approximation. The preceding discussion
( z − z0 ) N
should be illuminated by the following example where we plot the contour
52 A MATLAB® Companion to Complex Variables
1
lines on which the magnitude of f ( z) = assumes certain prescribed
z( z − 2)2
values. Note this was the function just studied with a three-dimensional
plot of its magnitude.
clf;clear
x=linspace(-1,3,100);
y=linspace(-1,1,100);
n=[.5 1 2];
[x,y]=meshgrid(x,y);
z=x+i*y;
w=1./(z.*(z-2).^2);
wm=abs(w);
[c,h]=contour(x,y,wm,n);
axis equal
grid
hold on
clabel(c,h);
title('Contour Lines Showing |1/(z(z-2)^2)|')
1
We have plotted the contour lines on which f ( z) = assumes the
z( z − 2)2
values 0.5, 1, and 2. There are lines that are nearly circular around the poles at
z = 0 and z = 2. On these, |f(z)| is 1 and 2, with, as you would expect, the higher
value resulting in contours that are closer to the poles. The value |f(z)|=.5
does not occur in close proximity to the poles and in fact results in a con-
tour enclosing both poles. Figure 2.13 should be compared with Figure 2.12,
which should make clear why the contours in Figure 2.13 for values 1 and 2
lie closer to the pole at z = 0 than they do for the pole at z = 2.
Note the line of code axis equal. This ensures that equal units of measure-
ment along the x and y axes are represented by equal intervals on the figure
generated by MATLAB.
In this way, a contour will appear as a circle on your computer screen
where appropriate.
−1
known as the principal part and has an infinite number of terms; in other
words, we cannot identify any exponent as being the most negative one in
the Laurent series.
Loci and Regions in the Complex Plane and Displaying Complex Functions 53
1.5
1
0.5
0.5 1
0.5
2
2
1
0
0.5
1
–0.5 1
0.5
5
0.
–1
–1.5
–1 –0.5 0 0.5 1 1.5 2 2.5 3
FIGURE 2.13
Contour lines showing 1 .
( z( z − 2)2 )
* See, for example, Conway, John, Functions of One Complex Variable I (2nd ed.). Springer, 1978.
54 A MATLAB® Companion to Complex Variables
x=linspace(-1,1,50);
y=linspace(-1,1,50);
[X,Y]=meshgrid(x,y);
z=X+i*Y;
w=sqrt(z);
wi=imag(w);
meshz(X,Y,wi);colormap gray
grid on;view(45,30)
Loci and Regions in the Complex Plane and Displaying Complex Functions 55
( )
1/2 Logz
obtained are consistent with the choice z1/2 = e Logz = e 2 , where Log z is
the principal branch of the logarithm, which is defined by a branch cut along
the negative real axis and includes z = 0 as shown in Figure 2.15.
For the principal branch of the log, we have Log z = Log|z| + i arg z, where
−π < arg z < π. Actually, MATLAB uses not the principal branch of the log but
the principal value defined by Log z = Log|z| + i arg z, where −π < arg z ≤ π.
There is a subtle distinction between the principal branch and the principal
value. Notice that < π (in the principal branch) has been replaced by ≤π (in
the principal value). In this way, we can ask MATLAB to compute, for exam-
ple, square roots of negative real numbers; such numbers of course have
1 1 i
( )
1/2 Log z Log z + arg z
arguments (angles) of π in the expression z1/2 = e Log z = e2 = e2 2 .
We cannot seek the square root of negative real numbers if we are using the
1.5
1
0.5
0
–0.5
–1
–1.5
–1 1
–0.5 0.5
0 0
0.5 –0.5
x y
1 –1
FIGURE 2.14
The imaginary part of the square root of z.
56 A MATLAB® Companion to Complex Variables
0
y
–2
–4
–6
–10 –8 –6 –4 –2 0 2 4 6 8 10
x
FIGURE 2.15
Branch cut for Log(z) is y = 0, −∞ ≤ x = 0.
principal branch, because these numbers have been removed (by a branch
cut) from the plane in which the principal branch of z1/2 is defined. The func-
tion z1/2 is analytic in that cut plane.
Using the principal value from MATLAB, we have
>> format short
>> sqrt(−1)
ans = 0 + 1.0000i
1 1 i π
Log ( −1) Log ( −1) + arg( −1) i
since Log(−1) = i π and e 2 = e2 2 = e 2 = i.
MATLAB will also tell you that the square root of 0 is zero by using the
limit of the real part of Log z as z → 0+. The function produced by MATLAB
for z1/2 is actually not analytic anywhere on the line y = 0, x ≤ 0, even though
MATLAB yields numerical values for the function for points on this line.
The difficulty is that if you move from a point on the line downward to a
point below the line, the value of z1/2 changes discontinuously. Consider the
following two results:
>> sqrt(−3)
ans = 0 + 1.73205080756888i
>> sqrt(−3−i*eps)
ans = 0.00000000000000 − 1.73205080756888i
Moving from −3 to its very near neighbor −3−i*eps produces results for the
square root that are so different that you feel that you are falling off a cliff.
Indeed, such a cliff is shown in Figure 2.14.
Loci and Regions in the Complex Plane and Displaying Complex Functions 57
* The reader may wish to consult section 3.8 of W for a discussion of branch cuts of some simi-
lar functions.
58 A MATLAB® Companion to Complex Variables
–1
–2
–2
–1 1
0 0
1 –1 y
x 2 –2
FIGURE 2.16
The imaginary part of arcsin z.
Exercises
ez − 1
1. a. Show that the function f ( z) = has a removable singularity
z
at z = 0 through the use of either L’Hôpital’s rule or a Maclaurin
series expansion of the numerator. Be sure to state how f(0)
should be defined in order to remove the singularity.
b. Make a plot of the surface describing |f(z)| over the region
−2 ≤ x ≤ 2, −2 ≤ y ≤ 2; use at least 1000 data points. Your code
should be written in such a way that you never divide by zero
(i.e., MATLAB should not give you a warning message).
c. Repeat part (b) but use the real part of the function f(z).
d. Repeat part (b) but use the imaginary part of f(z).
sin( z − e)
2. a. Show that the function f ( z) = has a removable singu-
Log( z) − 1
larity at z = e through the use of L’Hôpital’s rule. Be sure to state
how f(e) should be defined in order to remove the singularity.
b. Make a plot of the surface describing |f(z)| over the region .5 ≤ x
≤ 4, −2 ≤ y ≤ 2; use at least 1000 data points. Your code should be
written in such a way that you never divide by zero (i.e., MATLAB
should not give you a warning message). You should provide a
view statement in your code such that you can view the height of
your surface at the removable singular point.
Loci and Regions in the Complex Plane and Displaying Complex Functions 59
c. Repeat part (b) but use the real part of the function f(z).
d. Repeat part (b) but use the imaginary part of f(z).
1
3. Make a plot of the magnitude of f ( z) = . Choose the limits on
z( z − i)2
your axes and the arguments in your view statement such that you
can clearly see the behavior near both poles. Your plot should dem-
onstrate that the surface rises more steeply near the pole of order 2
than near the pole of order 1.
z
4. a. Where are the two poles of f ( z) = that are nearest the ori-
sin πz
gin, and what is their order? Where is the removable singularity?
Prove that it is removable.
b. Make a plot of the magnitude of this function that clearly shows
the behavior near these poles, but do not include any other poles
in your plot. Make certain that your program does not seek to
divide by zero.
In the following three problems, be sure to use axes of equal scales (the axis equal
command in MATLAB does this) so that contour plots near the poles will appear
nearly as circles if you are sufficiently close to the poles.
1
5. Make a plot of the contours on which the magnitude of f ( z) =
z( z 2 + 1)
assumes the values 0.5, 1, and 5.
Suggestion: Use the region described by |x| ≤ 2, |y| ≤ 2. Do the con-
tours encircle the individual poles? Explain.
1
6. Make a plot of the contours on which the magnitude of f ( z) =
sin( πz)
assumes the values 0.5, 1, and 3. Use a region that includes only the
poles at 0 and ± 1. Which contours encircle the poles?
7. a. Identify the location of the pole of 1 , and state its order.
( Log z − 1)2
b. Make contour plots on which the magnitude of this function
assumes the values 1, 2, and 10. A suggested region to use satis-
fies 0 ≤ x ≤ 10, −5 ≤ y ≤ 5. Place an asterisk * at the location of the
pole, on your plot. Comment on how well these contours appear
to be circles surrounding and concentric with the pole.
8. Make three-dimensional plots of both the real and imaginary parts
of f(z) = Log z for the region −2 ≤ x ≤ 2, −2 ≤ y ≤ 2. The plot of the real
part should clearly show the discontinuous behavior of Log |z| at
z = 0. The plot of the imaginary part should show the discontinuous
nature of Log z at the branch cut for this function.
9. Consider the function f(z) = (iz − 1)1/3. Where do you expect the
branch cut for this function, as created by MATLAB, to lie? Verify
60 A MATLAB® Companion to Complex Variables
the branch cut that MATLAB uses in this case by making three-
dimensional plots of the real and imaginary plots of this function
over the region −2 ≤ x ≤ 2, −2 ≤ y ≤ 2.
10. a. Consider the function f(z) = (1 − z2)1/2. Establish the branch cut
that MATLAB uses in evaluating this function by making three-
dimensional plots of the real and imaginary plots of this function
over the region −2 ≤ x ≤ 2, −.25 ≤ y ≤ .25. For view a good choice is
view(−30,70). What value does MATLAB produce at z = 0?
b. Repeat part (a) but choose f(z) = (z2 − 1)1/2. Notice that the branch
cuts are now different from those in part (a). Where are they?
What value does MATLAB choose for f(0)?
11. Consider the function f(z) = sinh−1(z) = log(z + (z2 + 1)1/2), the inverse
hyperbolic sine of z. Establish the branch cut that MATLAB uses
in evaluating this function by making three-dimensional plots of
the real and imaginary plots of the function sinh−1z over the region
−2 ≤ x ≤ 2, −2 ≤ y ≤ 2. Explain why no branch cut arises from the
logarithm, and explain what branch of the log is used by MATLAB.
12. Consider the function f(z) = zi. Establish the branch cut that MATLAB
uses in evaluating this function by making three-dimensional plots
of the real and imaginary plots of this function over the region
−2 ≤ x ≤ 2, −2 ≤ y ≤ 2. What relationship does this have to the branch
cut for Log z?
Suggestion: Try view(−125,30) to view your plot. What numerical val-
ues does MATLAB assign to 1i and ii?
1
4
1
3
1
0 2 –3 –2 3 2 –0 0
1
–3
–1
–2
–3
–2
–4
–1
–5
–5 –4 –3 –2 –1 0 1 2 3 4 5
FIGURE 2.17
Contour lines for the imaginary part of Log z.
Notice the jumble of contour lines and numbers near the negative real axis.
The imaginary part of Log z is the principal value of the angle of z (i.e., the
principal value of arg(z)). The curves on which this angle assumes constant
values are simply rays extending out from the origin. The command contour
should produce rays spaced at equal angles. This is not the case in the above.
The difficulty arises from the branch cut for Log z, which extends out from the
origin along the negative real axis. Just above the cut we have arg z = π, and just
below the cut arg z = −π. In constructing the contour lines, MATLAB errone-
ously assumes that Im(Log z) assumes all possible real values lying between
−π and π in any domain containing the negative real axis. It does not allow for
this function having a step-type discontinuity. It is possible that later versions
of MATLAB will sense the discontinuity and that what we will describe here
is not necessary. As noted, we are using here MATLAB release 2015a.
To prevent what just happened, before we invoke the contour command,
we must insert a line of code asserting that if z lies in a narrow band contain-
ing the negative real axis, then z “is not a number.” This is done below and
on the next page:
x=linspace(-5,5,1000);
y=x;
[x y]=meshgrid(x,y);
z=x+i*y;
62 A MATLAB® Companion to Complex Variables
1
4
2
3
1
0 3 0
–3
–1
–2
–3
–2
–4
–1
–5
–5 –4 –3 –2 –1 0 1 2 3 4 5
FIGURE 2.18
An improved version of the preceding plot.
w=log(z);
wm=imag(w);
del=.01;
wm(abs(y)<del&x<=0)=nan;
[g h]=contour(x,y,wm);
clabel(g,h);grid
Example 2.1
Using the ideas presented above, obtain a satisfactory plot of the contour
( z − 1)
lines of the imaginary part of w = Log . Let MATLAB choose the
( z + 1)
lines, and then change the program so that it plots exactly six lines.
Loci and Regions in the Complex Plane and Displaying Complex Functions 63
Solution:
This function has a branch cut where (z + 1)/(z − 1) is zero or negative
real. Some study (which you should do now) reveals that this is only
where y = 0, −1 ≤ x ≤ 1. We remove from consideration a strip containing
points along abs(y)<del, −1 ≤ x ≤ 1. We try del =.01. The following code
is used:
clf
x=linspace(-5,5,1000);
y=x;
[x y]=meshgrid(x,y);
figure(1)
z=x+i*y;
w=log((z-1)./(z+1));
wm=imag(w);
del=.01;
wm(abs(y)<del&-1<=x<=1)=nan;
[g h]=contour (x,y,wm,6);
clabel(g,h);grid
title('contour lines for Im log((z-1)/(z+1))')
xlabel('x');ylabel('y');
4 0.44451
2
1
445
1 335
1.3
0.4
2.2225
0
y
–1.
–1 333
1
5
–0.4445
–2
–3
–4 1
445
–0.4
–5
–5 –4 –3 –2 –1 0 1 2 3 4 5
x
FIGURE 2.19
( z − 1)
Contour lines for Im log .
z + 1
64 A MATLAB® Companion to Complex Variables
One should not think that the branch cut can create problems only in
the imaginary part of an analytic function. Here is an instance where the
branch cut appears in both real and imaginary parts.
Example 2.2
Obtain the contour lines for both the real and imaginary parts of the
function f(z) = u(x,y) + iv(x,y) = zi, where the principal branch of the func-
tion is used.
Solution:
Both the real and imaginary parts of the above are discontinuous as
we cross the negative real axis because of the discontinuity in the prin-
cipal value of arg(z). Both real and imaginary parts are discontinuous as
|z|→ 0 because of the singularity in Log|z|. Thus, in computing the con-
tour lines for both the real and imaginary parts of this function, we must
again exclude points from a strip that extends outward from the origin
along the negative real axis. We use the same strip as we used in creat-
ing Figure 2.18. We seek the contours on which the levels of 0 through 5
(integer values) are achieved. The following code will do the job. If you
run this program, the plot will be in color.
5 0
4 0
2
0
0
y
1 1
2 54
3
2
–1 5
0
4
–2 1
3
–3
2
0 1
–4
0
–5
–5 –4 –3 –2 –1 0 1 2 3 4 5
x
FIGURE 2.20
Contour lines for Re zi.
1
0
0
y
1
3
12 4
0
–1
5
–2
2
–3
–4 3
–5
–5 –4 –3 –2 –1 0 1 2 3 4 5
x
FIGURE 2.21
Contour lines for Im zi.
66 A MATLAB® Companion to Complex Variables
If you were to make both sets of plots on the same set of axes, you would
find that the sets of curves intersect at right angles. This is a well-known
property of analytic functions (see W section 2.5 and S section 3.12). If
you were to delete the lines of code wr(abs(y)<del&-1<=x<=1)=nan;
wm(abs(y)<del&-1<=x<=1)=nan, you would find that the curves form
a jumble along the negative real axis due to the discontinuity caused by
the branch cut described above.
The near absence of contour lines in the upper half plane in the two
figures can be remedied if we seek some contours having numerical val-
ues between 0 and 1.
Exercises
1. a. Consider f(z) = Log(z2 + 1). Obtain contour line plots for the real
and imaginary parts of this function. Before doing so, determine
the location of the branch cut that makes a domain of analyticity
for this function, and in your code eliminate points on this cut
through the use of NaN. Do this for both plots. Use a grid like
that in Example 2.1.
b. Try out your program but do not include the use of NaN, and see
what happens to your plots. Are both affected?
2. a. Consider f(z) = sin(Log z). This function is obviously discontinu-
ous as we cross the branch cut y = 0, x ≤ 0. Explain why the real
part is not discontinuous.
Hint: Recall sin(a + ib) = sin a cosh b + i cos a sinh b. Obtain contour
plots of the real part of this function, noting that you need not
use NaN. Consider a grid filling |x| ≤ 2, |y| ≤ 2 and let MATLAB
choose the values on the contours. Explain why the unit circle is
a contour on which this function is equal to 0.
b. Using the same domain and procedure as above, plot contours
for the imaginary part of the function but insert NaN where
needed. Try leaving out NaN and see what happens.
3. a. Consider f(z) = Log(sin(z)). Explain why to define this function in
the complex plane you need an infinite number of branch cuts.
Prove that these cuts are along the lines where any one of the fol-
lowing is true:
y = 0, sin x ≤ 0, or the set of lines where cos x = 0, sin x < 0,
−∞ < y < ∞.
b. Write a MATLAB plot to generate two separate contour program
of the real and imaginary parts of f(z).
Loci and Regions in the Complex Plane and Displaying Complex Functions 67
Suggestion: Consider the space −6 < x < 6, and −2 < y < 2, and
let the contour function choose the values on the contours. You
might also wish to make both plots on the same set of axes to
verify that they intersect at right angles. Be sure to use NaNs
to avoid evaluating the imaginary part of f(z) at or near the
branch cuts. Explain why this is not necessary for the contour
lines for the real part.
4. a. Consider f(z) = zz, where we use the principal branch. Explain
why both the real and imaginary parts of this function are dis-
continuous in any domain containing any portion of y = 0, x ≤ 0.
b. Obtain a set of contour plots for both the real and imaginary
parts of this function. A suggested range for both x and y is that
their absolute value be less than or equal to 2. Use NaNs where
required. Let the contour function choose the values assumed by
the function.
c. Obtain a contour plot showing only where the imaginary part
of this function assumes the value 1. A suggested range for both
x and y is that their absolute value be less than or equal to 5.
Notice that one of the contours appears coincident with a portion
of the positive real axis. This would seem to be wrong, because
if z = x is positive real, then zz = xx must be real and cannot have
an imaginary part equal to one. Can you explain this? Think in
terms of asymptotic behavior.
This page intentionally left blank
3
Sequences, Series, Limits, and Integrals
3.1 Sequences
In complex variable theory, we deal with both infinite and finite sequences,
the former being more common. A finite sequence of complex numbers is
simply a list z1, z2, z3, ..., zn of n numbers, where n is any positive integer.
Sometimes we begin the list with z0 instead of z1 so that the list has n + 1
elements instead of the n just shown. If n is allowed to grow without bound,
we have an infinite sequence. An example of a finite sequence might be i, i2,
i3, i4, i5. Thus, the nth member or element in the sequence is in. If we were to
let n here run beyond the number 5 and increase all the way to infinity, we
would have an infinite sequence.
Sometimes we have sequences of functions. Each element in the sequence
is defined by a function whose value typically depends on the index that
locates that function in the list defining the sequence. Here is an infinite
sequence of functions: sin z, sin 2z, sin 3z, ..., whose nth element is sin nz.
Here n is allowed to grow without bound. Restricting the size of n would
result in a finite sequence.
69
70 A MATLAB® Companion to Complex Variables
The most useful infinite sequences have a limit. This has a precise
mathematical meaning. Suppose the sequence is of the form
where the terms in the sequence might be functions of z, like sin nz, n = 1,
2, …, or simply constants like in.
The sequence has a limit (or “converges to the limit”) P(z) if the following
is true.
Given any positive number ε, there exists a positive integer N such that
The preceding says simply that if we go to the Nth term in the sequence,
then the magnitude of the difference between all terms beyond the Nth
(to the right of the Nth) and P(z) will be less than any preassigned positive
number ε that you choose, no matter how small. N almost always depends
on the value chosen for ε, and the smaller you make ε the larger must be N.
If the terms pn(z) are not constants but are functions of z, then almost invari-
ably N will depend on z as well as ε. Loosely speaking, if a sequence has a
limit P(z), then its terms must cluster closer and closer to P(z), in the complex
plane, as you move to the right in Equation 3.1. A sequence might have a
limit for some values of z but not others. For the latter, it would be futile to
try to find P(z). The reader might wish to see W section 5.2 and S sections
2.15 through 2.17 for more information on sequences.
Example 3.1
Let us consider the simple sequence
1
whose nth term is pn ( z) = 1 + . We use MATLAB to plot the elements
(1 + i)n
of this sequence.
Solution:
It should be obvious that the limit of this sequence is P = 1, since
1 1
lim 1 + n
= 1 + lim =1
n→∞ (1 + i) n →∞ (1 + i)n
1
This follows from the well-known fact that lim n = 0 if |w|>1. We can
n→∞ w
take w = 1 + i.
Sequences, Series, Limits, and Integrals 71
The reader should verify that we can take N in Equation 3.2 as any
1
Log
integer N satisfying N > ε . Thus, if we use MATLAB to plot the
Log(1 + i)
elements pn(z) of this sequence in the complex plane, they should cluster
more and more closely around the point 1 + i0. We prove this with the
following code and Figure 3.1:
N=15;
p=ones(1,N);rp=real(p);ip=imag(p);
for n=1:N
p(n)=1+1/(1+i)^n;
rp(n)=real(p(n));
ip(n)=imag(p(n));
b=num2str(n)
plot(rp(n),ip(n));
text(rp(n),ip(n),b,'FontSize',6);hold on
pause(.25)
n
p(n)
end
grid
plot(p,'−')
title('The First 15 Terms in the Sequence 1+1/(1+i)^n')
hold off
0.2
5 6
0.1
7
4 13
0 12 14 8
11 15
10 9
–0.1
–0.2
3
–0.3
–0.4
2 1
–0.5
0.7 0.8 0.9 1 1.1 1.2 1.3 1.4 1.5
FIGURE 3.1
1+ 1
The first 15 terms in the sequence .
(1 + i)n
72 A MATLAB® Companion to Complex Variables
Here the number 6 is the font size. Using a larger integer than 6 here
will allow the values of n to be printed larger, but there will be increased
crowding of these numbers near the limit of the sequence at 1.
Example 3.2
()
ii
i
( ii )
Investigate the sequence i, i , i , i i
, …. Thus, the nth element pn
is obtained by taking the previous element pn–1 and using it for the
exponent of i so that pn = i pn−1, where n ≥ 2. We will agree to take p1 = i.
We use the p rincipal value in each of these calculations, so that, for
example,
( )
i i = e iLog ( i ) = e iiπ/2 = e − π/2
while,
Solution:
Using MATLAB we can make a plot of the elements of this sequence in
the complex plane. Here is the code and the resulting Figure 3.2 when
we use the first 50 terms:
clear
clf
Sequences, Series, Limits, and Integrals 73
N=50;
p=ones(1,N);rp=real(p); ip=imag(p);
p(1)=i;
for n=2:N
p(n)=i^p(n−1);
rp(n)=real(p(n));
ip(n)=imag(p(n));
b=num2str(n)
plot(rp(n),ip(n),'*');
pause(.3);% gives a .3 sec delay in plotting
hold on
% text ( rp(n) , ip(n) , b , 'FontSize' , 6 );hold on
n
p(n)
end
plot(p(1),'*');
grid
title('Sequence from p_n=i^{p_{n−1}}')
hold off
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
FIGURE 3.2
Sequence from pn = i np− 1.
74 A MATLAB® Companion to Complex Variables
you will place at each point on the plot the index n corresponding to
each point in the plot. If you do this, you should eliminate the line
plot(rp(n),ip(n),'*');. The numbers for n will be hard to read on the
plot near the limit of the sequence, where they become crowded.
Why are there three spiral arms? Does the sequence in q uestion
have a limit, and what it is it? This problem has been studied in
two papers by Greg Packer, Steve Abbott, and Steve Roberts.* The
limit is close to 0.4383 + i0.3606. We can obtain the limit by means of
MATLAB.
Notice that lim pn − 1 = lim pn = p, assuming the limit p exists. Now
n→∞ n→∞
observe that lim pn = lim i pn−1. The left side of the preceding is this p. Let
n→∞ n→∞
us assume that we can swap the limit and exponentiation process of the
right side.† We thus have the equation
p = ip (3.3)
which must be satisfied by the limit p. We can solve this equation in the
complex plane using MATLAB. Let p = x + iy. Using this in Equation 3.3,
we have
Dividing the second of these by the first and making a little rearrange-
ment, we have
y = x tan(πx/2) (3.6)
* Greg Packer and Steve Abbott, “Complex Power Iteration,” The Mathematical Gazette 81 (492,
Nov. 1997): 431–434.
† The justification for this swap lies with the “Continuous Function Theorem for Sequences.”
See, for example, George B. Thomas, Ross L. Finney, Maurice D. Weir, and Frank R. Giordano,
Thomas’ Calculus, 10th ed. (Reading, MA: Addison-Wesley, 2000), 614.
Sequences, Series, Limits, and Integrals 75
Exercises
n
x
1. All textbooks on calculus have the formula e x = lim 1 + , where
n→∞ n
x is any real number. By studying the derivation of this formula, we
find that it applies equally well to the case where z is any number,
not just reals.* Thus, we can say that ez is the limit of the sequence
(1 + z), (1 + z/2)2, (1 + z/3)3, ..., (1 + z/n)n, …. Take z = (1 + i) and make
a plot similar to that in Figure 3.2 in which you display the first 100
terms of this sequence. Also display in this plot the value of e1+i.
2. a. Consider the sequence in which each term is obtained by cub-
ing the preceding term and squaring this same term, summing
these and adding them to i/2. Thus, p(n) = [p(n – 1)]3 + [p(n – 1)]2 +
i/2. Taking p(1) = 0, obtain a plot like Figure 3.1, which generates
a line connecting the first 1,000 terms in the sequence.
Suggestion: Use the xlim and/or ylim functions of MATLAB to
show the portion of the x–y plane near what is the apparent limit
of this sequence. From your plot or from the value of p(1000),
estimate the limit of this sequence.
b. Repeat part (a) but take p(1) = .9∗i. Compare p(1000) arising from
each case. Do you suspect that both sequences are heading for
the same limit?
c. Investigate what happens if you take p(1) = i. Leave off the xlim
and ylim. Does the sequence appear to have a limit?
d. No matter what you take for p(1), if this sequence has a limit, let us
call it p, show that it must satisfy the equation p3 + p 2 – p + i/2 = 0.
Find the roots of this equation by using the MATLAB function
roots. Which of the three roots is close to the limit you estimated
in parts (a) and (b)? How good is the agreement between the result
obtained here for the limit and the result for parts (a), (b), and (c)?
3. Consider the sequence p(n) = sin(nπ/10)zn, where n = 1, 2, ....
a. Let z = 1 + i/10. Obtain a plot comparable to Figure 3.2 showing
the first 100 terms of this sequence.
Suggestion: Put a pause statement in your code giving a pause
of around 0.5 second as each point is plotted so that you can
see how the points are generated. What terms in your sequence
have the smallest absolute magnitude? Prove mathematically
that this sequence cannot diverge to infinity.
* See, for example, K. Knopp, Infinite Sequences and Series, English edition (Mineola, NY:
Dover, 1956): 153–154.
Sequences, Series, Limits, and Integrals 77
∑ u (z), or with different indexing, ∑ u (z). Here the u (z), are usually,
n= 0
n
n=1
n n
∑
e inz
the second indexing, examples of such series are
∞ n= 0
n + 1
and ∑
n2 ( z + i ) ,
n
∑
n=1
1
while a series with no z such as also qualifies as infinite. The most
n=1
n2
useful series converge. Loosely speaking, it means that if you look at the first
N
∑
n=1
un ( z) converges to the function S(z), which is written ∑ u (z) = S(z), if
n=1
n
the sequence formed by taking the Nth partial sums (where N = 1, 2, …),
namely, u1(z), u1(z) + u2(z), u1(z) + u2(z) + ... + uN(z) converges to S(z).
∞
f ( z) = ∑ c (z − z )
n= 0
n 0
n
(3.9)
where
f n ( z0 )
cn = (3.10)
n!
The above two statements give us Taylor’s theorem.
Taylor’s theorem with Remainder is as follows:
N −1
f ( z) = ∑ c (z − z )
n= 0
n 0
n
+ RN (3.11)
where the same values for cn are used as in Equation (3.9). R N is known as the
remainder in the series and is given by this integral:
( z − z0 ) N f ( z′ )
RN =
2 πi ∫ ( z′ − z )
C
0
N
( z ′ − z)
dz′
where the integration is done in the complex plane, using the variable z′, around
the circle |z′ – z0|= b, where b is a positive real number less than r given above.
Thus, the circle excludes any singular points of f(z′). It is not hard to show that
as n → ∞, the remainder vanishes. If we delete the remainder in Equation 3.11,
we may approximate f(z) with a series containing N terms as follows:
N −1
f ( z) ≈ ∑ c (z − z )
n= 0
n 0
n
= c0 ( z − z0 )0 + c1 ( z − z0 )1 + ... + c N − 1 ( z − z0 )N − 1 (3.12)
Example 3.3
∞
z2 z3 zN −1
ez ≈ 1 + z + + + ... + (3.13)
2! 3! ( N − 1)!
Nmax=11;
a=0:Nmax−1;
q=1./factorial(a);
b=(2+2*i).^a;
SN=q.*b;
format long
S=(cumsum(SN)).';% this sums all the elements in the row
%vector SN
N=[1:Nmax]';
disp('number of terms series approximation')
[N S]
disp('MATLAB computes exp(2+2i)')
exp(2+2*i)
The output is
number of terms series approximation
ans =
1.
000000000000000 + 0.000000000000000i 1.000000000000000 +
0.000000000000000i
2.
000000000000000 + 0.000000000000000i 3.000000000000000 +
2.000000000000000i
3.
000000000000000 + 0.000000000000000i 3.000000000000000 +
6.000000000000000i
4.
000000000000000 + 0.000000000000000i 0.333333333333333 +
8.666666666666666i
5.
000000000000000 + 0.000000000000000i −2.333333333333333 +
8.666666666666666i
6.
000000000000000 + 0.000000000000000i −3.400000000000000 +
7.600000000000000i
7.
000000000000000 + 0.000000000000000i −3.400000000000000 +
6.888888888888888i
8.
000000000000000 + 0.000000000000000i −3.196825396825396 +
6.685714285714285i
9.
000000000000000 + 0.000000000000000i −3.095238095238095 +
6.685714285714285i
80 A MATLAB® Companion to Complex Variables
10.
000000000000000 + 0.000000000000000i −3.072663139329805 +
6.708289241622574i
000000000000000 + 0.000000000000000i −3.072663139329805 +
11.
6.717319223985890i
The left-hand column shows the number of terms we have elected to use
in our series approximation (Equation 3.11), while the adjacent c olumns give
the real and imaginary parts of the resulting sum. At the bottom of the out-
put, we see what value MATLAB gives for e2+2i. By the time we use a series
with 11 terms, the disparity between the approximate and “exact” value
is tiny.
The command S=(cumsum(SN)).'; in the above code may be unfamiliar.
If the argument of cumsum is a vector, either row or column, the result-
ing vector is a vector that has elements that are the cumulative sum of the
elements in the argument. For example, from MATLAB:
cumsum([2 7 9])
ans = 2 9 18
Thus, S=(cumsum(SN)).'; will sum the elements in the row vector SN;,
next the ′ (prime) converts this to a column vector, and the . (dot) before the
prime prevents this operation from taking the conjugate of these complex
elements.
The representation of ez by a polynomial with N terms as in Equation 3.13
may seem puzzling. According to the fundamental theorem of algebra, such
a polynomial has N – 1 roots (i.e., vanishes at N – 1 locations in the complex
plane). Thus, the more terms used in the series, the greater is the number of
these points. However, ez is known to be nonzero throughout the complex
plane. (See W section 5.7 and S problem 2.59.) Thus, the series might appear
to become increasingly not valid as N increases. This paradox is studied in
problem 3.
Example 3.4
Here we look at a series that is valid only within a domain having a finite
radius. ∞
Consider
1
∑
=
cosh z n = 0
cn z n, where we are using a Maclaurin expan-
1 1 z 2 5z 4
= 2 4 ≈ 1− + (3.14)
cosh z z z 2 24
+1+ + ...
2! 4!
The reader should fill in the details of this calculation. Note that on
the above right,
1 1 d2 1 −1 1 d 4 1 5
=1, 2 = , =
cosh z z = 0 2! dz cosh z z= 0 2 4! dz 4 cosh z z = 0 24
10
1/cosh(z), y = 0
–5
–2 –1.5 –1 –0.5 0 0.5 1 1.5 2
x
FIGURE 3.3
1
and its series approximation.
cosh( z)
82 A MATLAB® Companion to Complex Variables
Had we wanted say the 20th derivative, we would have put a 20 instead
of a 4 in the diff expression. Note that the line of code syms z is required to
establish z as a symbolic variable.
Suppose we wished to evaluate the preceding answer at z = 0 and
divide that result by 4! in order to obtain the coefficient of z 4 in the Taylor
expansion of 1/cosh(z) about z = 0. To do this, we create a function handle
and an anonymous function in MATLAB, topics the reader might wish to
review.
syms z b
b(z)=@(z)diff(1/cosh(z),4)
the_coeff=b(0)/factorial(4)
1 d4 1
The output is identical to the 5/24 = 4
we used in our series
above. 4! dz cosh z z= 0
There is an even easier way to obtain the Taylor series of an analytic func-
tion by means of MATLAB. Suppose we want the first three terms in the
1
Taylor expansion of about z = i. We use the MATLAB function taylor,
cosh z
in the Symbolic Math Toolbox, from the Command window as follows:
>> syms z T
>> T=taylor(1/cosh(z),z,i,’order’,3)
The output is
T = 1
/cosh(i) − (sin(1)*(z − i)*i)/cosh(i)^2 − ((sin(1)^2/
cosh(i)^2 + 1/2)*(z − i)^2)
/cosh(i)
syms z b
b(z)=@(z)taylor(1/cosh(z),z,i,'order',3)
b(.1+.1*i)
eval(b(.1+.1*i))
84 A MATLAB® Companion to Complex Variables
The output is
b(z) = 1
/cosh(i) − (sin(1)*(z − i)*i)/cosh(i)^2 − ((sin(1)^2/
cosh(i)^2 + 1/2)* (z − i)^2)/cosh(i)
ans =
((sin(1)^2/cosh(i)^2 + 1/2)*(4/5 + (9*i)/50))/cosh(i) +
(sin(1)*(−9/10 − i/10))/cosh(i)^2 + 1/cosh(i)
ans = 3.5883 + 0.6864i
said to be the Laurent series expansion of the function on the left. If a func-
tion is analytic in a deleted neighborhood of z0 described by 0 < |z–z0| < r2,
then a Laurent expansion of this function is also possible, and it is valid
in this “punctured disc.” The coefficients of the series in either case can be
expressed as contour integrations around closed contours in either the ring
or the punctured disc (deleted neighborhood) centered at z0. The reader
might wish to consult a book on complex variables to recall what these inte-
grals are (e.g., W section 5.6 and S section 6.9).
Ordinarily we do not obtain the coefficients by means of these integrals
but instead use the method of partial fractions or changes of variable within
2
a known Taylor series. For example, e 1/z is analytic in a deleted neighbor-
w2 w3
hood of z = 0. Recall that ew has the Taylor expansion 1 + w + + + ...
2! 3!
valid for all finite w. We can replace w with 1/z in the preceding (as long
2
2 1 1 1
as z ≠ 0) and obtain the Laurent expansion e 1/z = 1 + 2 + + + ...,
z 2! z 4 3! z6
which is valid for all z ≠ 0.
Can we use MATLAB to obtain the coefficients in a Laurent series expan-
sion much as we used it to obtain the coefficients in a Taylor series? The
answer is no… and yes—there is no function laurent like taylor in the release
2015a. However, there is a quirk in the taylor function that allows it to yield
Laurent expansions of functions.
Example 3.5
Use MATLAB to obtain the first few terms in the Laurent expansion of
1
f ( z) = valid in a deleted neighborhood of z = 0.
sin z
Solution:
We notice that sin z = 0 at z = 0, z = ±π, …. An expansion of the function
is thus possible in the deleted neighborhood of the origin. This domain
Sequences, Series, Limits, and Integrals 85
z z
g( z) = zf ( z) = =
sin z z3 z5
z − + − ...
3! 5!
z 1
=
sin z z2 z4
1− + − ...
3! 5!
1
z2 z4
1− + − ...
3! 5!
syms z b
b(z)=@(z)taylor(z/sin(z),z,0,'order',6)
The answer is
In the preceding expansion, we asked for six terms, but we seem to have
gotten only three. Note that z/sin(z) is an even function of z. In our series, the
first term is simply 1, the second is 0, the third contains the second power
of z, the fourth vanishes, the fifth is the fourth power, while the sixth is
absent. The terms with odd exponents of z vanish.
86 A MATLAB® Companion to Complex Variables
The infinite series of which we have obtained only the first three nonzero
terms converges for |z|< π to the function z when z ≠ 0 and to 1 when
sin z
z = 0. Dividing this series by z, we obtain the desired Laurent expansion:
1 1 z z3
= + +7 + ... 0< z <π
sin z z 6 360
where we have placed the terms in their usual order of ascending powers.
The function 1 is analytic in the ring-shaped domain π < |z| < 2π, and
sin z
a Laurent expansion of the function should be possible there. We can use the
previously obtained Laurent series, valid for 0 < |z| < π, to get us partway to
the solution. The details can be found in W section 6.3 problem 41.
There are other ways to use the Taylor series function in MATLAB to obtain
Laurent series. This is especially true when a function is analytic at infinity.
Recall that a function f(z) is analytic at infinity if the function F(w) = f(1/w) is
1
analytic in the w plane at w = 0. For example, f (z) = is analytic at
( z − 1)( z − 3)
1
z = ∞ since F(w) = is analytic at w = 0 (verify this), while f(z) = z
(w −1 − 1)(w −1 − 3)
is not analytic at z = ∞ since 1/w is not analytic at w = 0.
Example 3.6
z
Expand f ( z) = in a Laurent series in powers of z, valid
( z − 1)( z + 3)
for |z|>3.
Solution:
We verify that this function is analytic in the finite plane except at z = 1
and z = −3. Thus, if we are working with series having powers of z, a
Taylor series is available for 0 ≤ |z| < 1. A Laurent series can be found
for 1 < |z| < 3, and another for |z| > 3. The MATLAB function taylor
will produce the Taylor series. Now
w −1 w
F(w) = f (1/z) = f ( z) = =
(w − 1)(w −1 + 3) (1 − w)(1 + 3w)
−1
>> c(z) = @(z)taylor(exp(1./z),’ExpansionPoint’,inf,’Order’,5)
c(z) = 1/z + 1/(2∗z^2) + 1/(6∗z^3) + 1/(24∗z^4) + 1
The above is the Laurent expansion (the first five terms) of e1/z. Notice the
rather strange ordering of the terms: 1/z∞ is the first term, and 1/z0 is the last
term. The actual Laurent expansion is ∑ n! z
1 1 . MATLAB does not yield the
n
n= 0
Laurent expansion of, for example, ze1/z, because this function has a simple
pole at infinity, as the reader should verify with the substitution w = 1/z.
z
In Example 3.6, we mentioned that the function f ( z) = has
( z − 1)( z + 3)
a Laurent expansion in the domain 1 < |z| < 3. The methods we have been
using with MATLAB will not produce this series.
However, MATLAB can still help us to obtain the series. We express f(z) in
the form
α β
f ( z) = +
z+3 z−1
.75 .25 z
+ =
z + 3 z − 1 ( z − 1)( z + 3)
Now we expand the first fraction in a Taylor series and the second
in a Laurent series, each in powers of z, and we add the two series, as
follows:
syms z a b
a(z)=@(z)taylor(.75/((z+3)),'ExpansionPoint',0,'Order',4);
b(z)=@(z)taylor(.25/(z−1),'expansionpoint',inf,'order',4);
a(z)+b(z)
z3 + 2 z2 + i
f ( z) =
( z − 1)( z + 3)
in a Laurent series valid for |z| > 3. We again seek a partial fraction decom-
position, but note that we are dealing here with an improper rational
Sequences, Series, Limits, and Integrals 89
2.2500 − 0.2500i
L=
0.7500 + 0.2500i
−3.0000
M=
1.0000
N = [1 0]
Note that N is not empty.
The preceding means that the partial fraction decomposition of f(z) is
syms z a b
a
(z)=@(z)taylor((2.25−.25*i)/(z+3),'ExpansionPoint',inf,
'Order',4)
b(z)=@(z)taylor((.75+.25*i)/(z−1),'expansionpoint',inf,'order',4)
a(z)+b(z)
Our final answer, the desired Laurent series for |z| > 3, requires our add-
ing the term z to the above. Thus, we have
z3 + 2 z2 + i
f ( z) = = z + 3/z + (−6 + i)/z ^ 2 + (21 − 2∗i)/z ^ 3 +
( z − 1)( z + 3)
for |z| > 3.
90 A MATLAB® Companion to Complex Variables
Exercises
1. Perform a calculation similar to Example 3.3 but compute sin(3 + 4i)
using the Maclaurin series expansion of sin z. Compare the sum of
series having 1, 2, ... 10 nonzero terms to the MATLAB determination
z3 z5
of sin(3 + 4i). Recall that sin z = z − + − ...
3! 5!
How many terms would you need in your series to get agreement
between the MATLAB value of sin(3 + 4i), and the series approxima-
tion, that is within 1%?
1
2. Consider the series = 1 + z + z 2 + z 3 + ... . This series is u
niformly
1− z
convergent in the disc |z| ≤ r if r < 1. If necessary, review the concept
of uniform convergence in either W section 5.3 or S section 6.4. Because
the series is uniformly convergent, we may integrate it term by term
along a contour connecting z = 0 with z = w in the complex plane. We
require that |w| < 1 and that the contour lies in the above disc. Thus,
w w w w
dz w2 w3
∫
0
1− z
=
∫
0
∫
0
∫
dz + z dz + z 2 dz + ... = w +
0
2
+
3
+ ... w < 1
w
dz 1
∫ 1 − z = − Log(1 − z)
w
But notice also that = Log . Thus,
0
(1 − w)
0
1 w2 w3
Log =w+ + + ... |w| < 1
1– w 2 3
i
a. Take w = in the preceding equation. By taking the real and
3
imaginary parts of this equation, show that
3 −1 1 1
Log = + − + ...
2 2 × 3 4 × 9 6 × 27
and
π 1 1 1 1 1 1 1
= − + − ... = 1− + − − ...
6 3 3× 3 ×3 5× 3 ×9 3 3 × 3 5 × 9 7 × 27
z2 zn
ez ≈ 1 + z + + ... +
2! n!
1 1 1 1 1 1 1 1 (−1)n− 1 1 1
π = 4 + − 3 + 3 + 5 + 5 + ... + 2 n− 1 + 2 n− 1 ...
3 2
3 3 2
5 3 2 2n − 1 3 2
1
f ( z) =
(1 − z)1/2
∑c z
n= 0
n
n
=
1
(1 − z)1/2
valid? Give the center of the domain and its radius. Through the
use of Equation 3.10, find a formula for cn in terms of n.
b. Using the MATLAB function diff, show that the first six terms
in the Maclaurin series as given by the formula you derived in
Sequences, Series, Limits, and Integrals 93
(a) agree with those obtained with having MATLAB generate the
derivatives.
c. Confirm the results in (b) by using the MATLAB function
taylor. Convert the expression found to an anonymous function
of z using the @(z) notation.
d. Show that you can use your series to find 2 by suitable choice
of z. Using this value of z in the above derived function handle,
find what values you get for 2 by using the series having six
terms found in (c) and compare this result with the MATLAB-
generated sqrt(2). Use double precision. Now repeat this but use
50 terms. Are the results better with 50 terms?
∫ f ( z) dz = lim
n→∞ ∑ f (z )∆z
k =1
k k (3.15)
A
where all Δzk → 0 as n → ∞. Note that the complex number A = X1 + iY1 and
B = XN+1 + iYN+1. We must think of the summation on the above right as arising
from summing the following n products: the function f(z) evaluated at a point
on C multiplied by the complex number for the neighboring vector chord.
94 A MATLAB® Companion to Complex Variables
y
Xn+1, Yn+1
B
Δyn Zn
Xn , Yn
etc.
Δz
2 z2
X1 , Y1 Δz1
A X2 , Y2
z1
Δx1 x
FIGURE 3.4
Defining a contour integral.
If we do not pass to the limit on the right, but instead use some finite value
of n, we obtain only an approximation of the integral
B n
∫ f (z) dz ≈∑ f (z )∆z
A k =1
k k (3.16)
Example 3.7
1
Consider
∫ cos z dz, where the integral is along the arc C in the first
i
quadrant y = 1 – x2.
Sequences, Series, Limits, and Integrals 95
Solution:
We create the subarcs, arbitrarily, by making each x-axis projection of
Δzk, namely, Δxk, to be of identical length. Figure 3.5 shows what h appens
with three such subdivisions.
Since x advances from 0 to 1 as we integrate, we have when n = 3 that
X1 = 0, X2 = 1/3, X3 = 2/3, X4 = 1. The corresponding values of the Y
coordinates are obtained from the equation of C—that is, y = 1–x2. Thus,
Y1 = 1, Y2 = 8/9, Y3 = 5/9, Y4 = 0.
Having found the endpoints of each subarc, we have that Δz1 = 1/3 – i/9,
Δz2 = 1/3 – i/3, Δz3 = 1/3 – i5/9 as some study of the figure should confirm.
Notice that the sum of these three quantities is simply 1 – i which is a
vector connecting the start of integration at (1,0) with the fi nish (0,1). This
will always be the case with the Δzk quantities—their sum will equal a
vector going from the start to the finish of integration.
The quantities zk must now be chosen. Recall that they must each reside
somewhere on the corresponding subarc. We choose arbitrarily to place
them in such a way that each xk lies exactly between the two values of Xk
defining the ends of the arc. The corresponding value of yk is found from
the equation of the contour C. Thus, yk = 1 – xk2. We now have x1 = 1/6,
y1 = 35/36, x2 = 1/2, y2 = 3/4, x3 = 5/6, y3 = 11/36. Our corresponding three-
term sum on the right in Equation 3.16 is
1.2
X1, Y1
1 z1
X2, Y2
Δz1
0.8
z2
Δz2
0.6
y
X3, Y3
0.4
Δz3 z3
0.2
X4, Y4
0
0 0.5 1 1.5
x
FIGURE 3.5
The arc C and vector chords.
96 A MATLAB® Companion to Complex Variables
∑ f (z )∆z
k =1
k k = cos(1/ 6 + i35 / 36)(1/ 3 − i / 9) + cos(1/ 2 + i3 / 4)(1/ 3 − i / 3)
∫ cos z dz
i
∫ cos z dz = sin 1 − sin i
i
Example 3.8
Repeat Example 3.7 but use series that range from 1 to 10 terms.
Solution:
nmax=input('max number of terms in series')
for(n=1:nmax)
Sequences, Series, Limits, and Integrals 97
nmax = 10
sin(1)−sin(i)
0.841470984807897 − 1.175201193643801i
Notice that the agreement between the above “exact” value and the value
obtained by the series approximating the integral is surprisingly good.
With only a five-term series, the disparity in both real and imaginary parts is
less than 1%, and agreement continues to improve with the use of more terms.
98 A MATLAB® Companion to Complex Variables
As a check, we should observe that the results obtained from the three-term
series agree with that obtained in the previous example.
The reader might wonder what the point of the preceding exercise is if we
can evaluate the integral so easily by using the antiderivative, which quickly
yields the exact result sin(1) − sin(i). Of course, there is no point in deter-
mining the integral numerically in the way we just have. However, had the
integrand been a function that is not analytic, for example, f(z) = cos|z| or
f ( z) = cos z, we cannot find an antiderivative, and a numerical determination
is required.
The function f ( z) = cos z is analytic except at z = 0 and is therefore
z
analytic throughout a simply connected domain containing the path of inte-
gration like the one just employed. However, an antiderivative F(z) cannot be
found for this function in terms of the elementary functions of calculus, and
a numerical integration is necessary unless one might have access to numeri-
cal tables (in this case, they do exist) yielding this integral.
MATLAB provides several functions that will perform n umerical
integrations, among them are quad, quadl, and quadgk. The last is among
the most recent in MATLAB and of the most use to us here, because under
certain circumstances, it permits integration between complex limits, as well
as limits that can be infinite. It is so valuable that the next section is devoted
to quadgk.
Exercises
1+ i
infinity which we designate inf. The number inf is the real number, say x, as
it increases without bound through positive values, inf = lim
x→∞
x, while –inf is a
real number x as it decreases without bound through negative values –inf =
lim x. One should note that like quadgk, int will do an integration in the
x →−∞
complex plane, but the contour must be a single straight line and cannot be
composed of a sequence of straight lines. For example, quadgk can integrate
all the way around or part of the way around a triangle, while int would
integrate only along one side.
At this point the reader should study both methods of integration, int
and quadgk, by going to the help feature of MATLAB. In the remainder
of this section, we see how int and quadgk can be used to verify results
obtained with residue calculus or in some cases perform integrations that
are possible with complex variable theory but require tedious mathematical
manipulations.
Example 3.9
∞
x 2 dx
Find I =
∫
0
x4 + 9
by using residue calculus and by using both int and
quadgk.
Solution:
a. With residues:
Let us recall a theorem from complex variable theory (see W
section 6.5 and
∞
S problems 7.15–7.17). Suppose we must evaluate
P( x) , where P and Q are polynomials in the
the integral
−∞
∫
Q( x)
dx
variable x.
Assume that the highest power of x in Q exceeds that in P
by two or more, in other words, the degree of Q is at least two
bigger than P, and we also agree that Q(x) ≠ 0 for all real x. Then,
∞
P( z)
∫ Q(x)dx = 2πi∑ Res Q(z) @ all the poles in the upper half plane (3.17)
P( x)
−∞
∞ 1
x 2 dx
have that I =
∫x
−∞
2
+94
. Thus, in Equation 3.17, we take P(z) = z2/2
g ( z) g ( z0 )
Res @ z0 = (3.18)
h( z) h′( z0 )
2 πi π
I=
8 3
[ cos(π/4) − i sin(π/4) + cos(−3π/4) + i sin(−3π/4)] = 2 6
We note that the answer must be real, and it is.
b. To integrate with int, we use this MATLAB code:
syms x;
I=int((x.^2)./(x.^4+9),0,inf)
The output is
I = (pi*6^(1/2))/12
π
Observe that this is the same as π 6 / 12 = , the result
obtained by residues. 2 6
Notice the importance of the line of code:
syms x;
f=@(x) (x.^2)./(x.^4+9)
format long
I=quadgk(f,0,inf)
The output is
I = 0.641274915080932
Sequences, Series, Limits, and Integrals 103
Some comments:
Obviously, quadgk and int each have their uses. If you want to obtain
an immediate numerical expression for use in other calculations,
then quadgk would be your best bet. If you want an expression with
numerical symbols to place inside an engineering or physics formula,
you might prefer int. Of course, you can do the integration in the pre-
ceding example with residue calculus. However, if you were given the
1
x 2 dx , you could not quickly find the
problem to find, for example,
0
∫
x4 + 9
answer with r esidues. You might resort to an integral table or perhaps
just use quadgk or int depending on your needs. The code would be
like that used in Example 3.9 except that the upper limit of integra-
tion would no longer be inf but would be 1. There are symbolic prob-
lems in integration that cannot be done with int (i.e., it cannot do a
closed-form expression for the result). See problem 2 that follows for
example.
∞
x 2 dx
A problem such as I =
∫
0
x4 + x2 + 3 + i
can in principle be done with
residue calculus, but you would be faced with the messy job of locating
the roots of z4 + z2 + (3 + i) in the complex plane. Here you are much
better off with either int or quadgk, depending on your goal. A similar
integral is considered in exercise problem 5.
3
∫
1/2
A problem like e i(sinh z ) dz will pose a difficulty for int as the following
0
code shows:
syms z
I=int(exp(i∗sqrt(sinh(z))),0,3)
vpa(I,10)
yields this answer, in numerical form, correct to 10 decimal places.
ans = 2.15702077∗i + 0.1021467801
104 A MATLAB® Companion to Complex Variables
Example 3.10
(1+ i )
Find I1 =
∫e
(1− i )
iz
dz by using quadgk, and verify the answer with complex
variable theory.
Solution:
The required code is simply as follows:
syms z
f=@(z) exp(i*z)
format long
I=quadgk(f,1−i,1+i)
check_answer=(exp(i*(1+i))−exp(i*(1−i)))/i
Whose output is
I = −1.977795411525730 + 1.269927829569473i
check_answer = −1.977795411525731 + 1.269927829569473i
Notice the “check answer” portion of the output. We recall that since
eiz is an analytic function, we may simply evaluate the integral using the
e iz e i(1+ i) − e i(1− i)
antiderivative of this function. Thus, I = |11+− ii = . Observe that
i i
the agreement between the two methods is nearly perfect. Had the given
integrand been e iz, which is not analytic, we could not have checked the
results of our numerical integration so easily, as this function does not have
an antiderivative.
A note is appropriate here about the use of infinity (inf) in the limits of
quadgk if we are integrating in the complex plane. One can use this as one of
the limits provided that the other limit is real. One can also use - inf if the other
limit is real. You can use –inf and inf together. We cannot really use infinity
as a limit unless we stick to the real axis, although complex integrands are
permissible when integrated on the real axis.
Sequences, Series, Limits, and Integrals 105
3.4.2 Waypoints
Using quadgk, we can integrate along a contour composed of straight
lines. The waypoints vector, placed in quadgk, tells quadgk where the end-
points of these straight lines lie. For example, suppose we wish to inte-
grate cos z/z from 1 + i to −3i using this path of successive straight lines:
from 1 + i to 2i and then along the line from 2i to −1 + 2i, and from there
to −1 − i, and finally from −1 − i to −3i. (See the solid lines with arrows in
Figure 3.6.) We write code in which waypoints is a row vector whose ele-
ments are the points where the contour abandons its old straight line path
and starts on a new one. We do not include in waypoints the starting points
and endpoints in the numerical integration. These points still appear as
the limits of integration. The numerical entries in waypoints are the points
on the path where the tangent of the overall contour of integration is dis-
continuous; we enter these points as complex numbers in waypoints from
left to right in the order in which they are encountered on the path. If you
elect to use waypoints, you may not use infinity (i.e., inf or −inf) in the
waypoints vector or in either the starting point or endpoint of the integra-
tion if any of the elements in waypoints is not real, or if any of the limits
of integration are not real.
Here is the required code to solve the problem described above:
format long
syms z
f=@(z)cos(z)./z;
IA=quadgk(f,1+i,−3i,'waypoints',[2i,−1+2i,−1−i])
y
2
x
0
0
–1
–2
–3
–3 –2 –1 0 1 2 3
FIGURE 3.6
An illustration of “Waypoints.”
106 A MATLAB® Companion to Complex Variables
The output is
IA = 4.078219914209672 + 4.425139846864735i
Notice (refer to the figure and the solid lines) that the integration begins
at 1 + i and ends at –3i and that the waypoints are 2i, –1 + 2i, and –1 – i.
We can check this result. If we integrated along a straight-line path
connecting 1 + i with –3i by using I=quadgk(f,1+i,−3i,), we would not
obtain the above value for IA. This is because the operation we are doing
depends on the path of integration. The function cos z/z has a singular-
ity (a simple pole) at z = 0 but is otherwise analytic. We cannot deform
the integration along the original path (the solid line in Figure 3.6) into
the dotted-line path without forcing the contour to pass through the
singularity.
Suppose, however, we were to take the result IA from the above and add it
to the integral of cos z/z taken along the straight line going from –3i to 1 + i.
cos z
The sum of these two integrals would be the value of the integral
∫ z
dz
taken in the positive (counterclockwise) direction around the closed contour
that is the polygon shown in Figure 3.6.
We can do this integration with residues, because cos z/z has a simple pole
cos z
at z = 0, which is enclosed. The result should be 2 πi Res[ @ z = 0], where
z
Res is an abbreviation for residue. Using Equation 3.18, we have that the resi-
due is cos 0 = 1. So the result of our integration around the closed contour in
Figure 3.6 is 2πi.
Let us add our integral IA obtained above from quadgk to the integral of
cos z/z taken along the dotted line in Figure 3.6. We call the latter integral IB.
The sum of these should equal 2πi and would provide a check on the value
of IA. Here is our code:
format long
syms z
f=@(z)cos(z)./z;
IA=quadgk(f,1+i,−3i,'waypoints',[2i,−1+2i,−1−i])
IB=quadgk(f,−3i,1+i)
total_is= IA +IB
two_pi_i=2*pi*i
Whose output is
IA = 4.078219914209672 + 4.425139846864735i
IB = −4.078219914209674 + 1.858045460314853i
two_pi_i = 0 + 6.283185307179586i
Sequences, Series, Limits, and Integrals 107
Observe that the agreement between the sum of these two integrals and
the desired 2πi is excellent, and any disparity is due to round-off errors.
Rather than integrate around the quadrilateral by combining two inte-
grals, we can perform the integration with a single quadgk statement. We
take the beginning and final limits of integration as 1 + i and use the remain-
ing corners as waypoints. The code is
format long
syms z
f=@(z)cos(z)./z;
IC=quadgk(f,1+i,1+i,'waypoints',[2i,−1−i,−3i])
which yields
IC = −0.000000000000020 + 6.283185307179271i
This agrees with the total sum of the two prior integrals, IA plus IB, up to
13 decimal places. We would have been happier if the real part above had
turned out to be zero, but rounding errors prevented this.
Exercises
1
∫
1. Evaluate e i sin x cos x dx by the following three methods and compare
0
the results
a. By using the antiderivative of the integrand
b. By using int
c. By using quadgk
1
2. Evaluate
∫e 0
i sin x
dx. Note that, unlike the previous problem, an
bn z n + bn− 1 z n− 1 + ... + b0
f ( z) =
am z m + am− 1 z m− 1 + ... + a0
Sequences, Series, Limits, and Integrals 109
Then MATLAB can find the location of the poles of this expression
as well as the residue at each pole. At this point, you should read the
documentation for residue in the help folder. Briefly, you employ the
statement
[r,p,k]=residue(b,a)
use only the residues in the uhp or, if you prefer, only the lhp.
c. Check your answer to (b) by using int, being sure to convert
your answer to a decimal form to facilitate comparison with the
answer from (b).
7. Recall from complex variable theory that if we are given the integral
∞
P( x)
∫ Q(x) e
−∞
iνx
dx
where v > 0 and the degree of Q(x) exceeds that of P(x) by 1 or more,
∞
then
P( x)
∫ Q(x) e iνx
dx = 2 πi ∑ Res QP((zz)) e iνz
@ all poles in the uhp .
−∞
If v < 0, we would use the poles in the lower half plane and replace
2 with –2.
110 A MATLAB® Companion to Complex Variables
∞
cos 2 x
∫ x (x − 1)
−∞
2
+1
dx
and
∞
sin 2 x
∫ x (x − 1)
−∞
2
+1
dx
10. a. Consider
cos( πz)
∫ sin(πz) dz
where the integral is done on the contour |z|=3/2. Explain why we
can get the same result if we integrate instead in the positive direc-
3 3
tion around the square having corners at z = ± and z = ± i.
2 2
b. Perform the given integration by using residues.
c. Check your answer by using quadgk and the square contour.
Employ waypoints. Are the results the same?
d. By using quadgk, do the integration
cos( π z )
∫
sin( πz)
dz
∫
11. Compute Log z dz using quadgk and waypoints. Use the following
−i
two different paths:
a. Straight lines connecting –i, 1, and i.
b. Straight lines connecting –i, –1, and i.
c. Discuss the fact that the answers to (a) and (b) are not the same.
Note that you are using the principal value of the Log.
d. Derive both of the answers analytically by using the antideriva-
tive of the log.
Hint: For part (b), notice that the imaginary part of log changes
discontinuously as you cross the branch cut at z = –1. Thus, you
should break your integration into two integrals: one from –i
to –1-i∗eps (at the bottom of the cut) and the other from –1 to i.
Notice that using principal values in MATLAB log(–1–i∗eps) ≈ –iπ
and it takes log(–1)=iπ.
12. a. Using quadgk and waypoints, find
sin z
I=
∫ sinh z (z 2
+ 1)( z + 10i)
dz
Harmonic functions and conformal mapping are two of the richest and
most interesting topics in complex variable theory. It is our good fortune
that harmonic functions, which are always the real and imaginary parts
of analytic functions, can be used to describe two-dimensional configura-
tions of fluid flow, heat transfer, and electrical fields. Historically, confor-
mal mapping achieved importance as a means of solving two-dimensional
problems in these branches of engineering and physics. Although numeri-
cal methods on modern computers have rendered this application of less
importance, conformal mapping still provides us with solutions to certain
canonical problems that can be used to verify the correctness of computer-
generated solutions. This is analogous to the practice of learning to perform
integrations in e lementary calculus courses even though, for example, the
MATLAB® Symbolic Mathematics Toolbox will perform them for you. One
must know what kinds of answers to expect from a computer and to have a
means of checking them.
In Chapter 2, we learned some graphical techniques for studying
functions of a complex variable. These included three-dimensional
plots as well as the use of contour lines. Conformal mapping provides
another means of visualizing the properties of a function of a complex
variable. In this case, we work in just two dimensions and use two sepa-
rate planes.
4.1 Introduction
Let z = x + iy and w = u + iv be complex variables. If w = f(z) describes a func-
tion of the complex variable z and is defined at the point z0, we can say that
this function maps the point z0 into the point w0 where w0 = f(z0).
We can display this fact using two planes—the z and w planes. The
points z 0 = x0 + iy 0 and w 0 = u 0 + iv 0 might be plotted as * or some other
symbol. We say that w 0 is the image of z 0 under the given transformation
w = f(z).
113
114 A MATLAB® Companion to Complex Variables
clf
z=(1+i);
w=log(z);
figure(1);
plot(z,'*');grid on;xlabel('x');ylabel('y');
%the above plots the point 1+i in z plane,
% and labels the axes.
text(1.02,1.02,'z_0')
% above labels the above point, we use 1.02, 1.02
%and not 1,1, so as to keep the letter zo off the star *
text(1,1.6,'\fontsize {12} The z Plane')
figure(2);
plot(w,'*');grid on;xlabel('u');ylabel('v')
%above plots log(1+i) in w plane.
text(real(w)+.05,imag(w)+.05,'w_0');
%note the use of .05 in the above to keep
%the wo off the *
%labels the above point
text(0,1.7,'\fontsize{12} The w Plane')
1.8
1.6
1.4
1.2
z0
1
y
0.8
0.6
0.4
0.2
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
x
(a)
1.5
1
w0
v
0.5
–0.5
–1 –0.5 0 0.5 1 1.5
u
(b)
FIGURE 4.1
(a) The point for 1 + i and (b) the principal value of log(1 + i).
3 to the ASCII number for A (which is 65) and then converting the result
(which is 68) back to a character which will be D. We convert from the ASCII
number to the actual letter of the alphabet by use of the operation char.
Here is how we might convert a letter A to letter D. Recall the use of single
quotes to make a character, ‘…’.
116 A MATLAB® Companion to Complex Variables
>> uu=‘A’
uu = A
>> vv=uu+3
vv = 68
>> char(vv)
ans = D
Here is how we might go from the lowercase letter z to the lower case u.
Recall that there are four letters between u and z and that the ASCII number
for u is smaller than that for z.
>> tt=‘z’
tt = z
>> LL=tt−5
LL = 117
>> char(LL)
ans = u
Now consider the 11 points on the line x = 1 given by z = 1, 1 ± 1i, 1 ± 2i, …
1 ± 5i. We will identify them with the letters A … K (starting with 1 – 5i and
proceed upward along x = 1 to 1 + 5i). Using the mapping w = log z, we will
plot not only the given values of z but their images in the w plane and label
them as A … K.
This is accomplished with the following code:
clf
y=linspace(−5,5,11);
x=1;
z=1+i*y;
w=log(z);
figure(1)
plot(real(z),imag(z),'.');grid on;
%plots a dot for each value used in
%z plane
xlabel('x');ylabel('y');title('z plane');grid on
figure (2)
plot(real(w),imag(w), '.');axis equal;
%plots a dot at each value of logz
xlabel('u');ylabel('v');title('w plane')
for n=1:length(y)
letter=char(n+64);
%the above creates the letters A, B,...
figure(1);
text(1.02,imag(z(n)),letter,'FontSize',10);
% the above plots the letters A,B,
%note that using 1.02 instead of 1 in the above
%keeps the text off the dot in the plot.
%a similar thing is done for figure(2)
figure(2)
Harmonic Functions, Conformal Mapping, and Some Applications 117
te
xt(real(w(n))+.02,imag(w(n)),letter,'FontSize',10, ...
'FontAngle',...
'italic','FontWeight','bold');
% the above plots in the w plane the
% italicized bold A, B, C...
% which are the images of the points in the z plane
hold on
end;grid on
5 K
4 J
3 I
2 H
1 G
0 F
y
–1 E
–2 D
–3 C
–4 B
–5 A
0 0.2 0.4 0.5 0.8 1 1.2 1.4 1.6 1.8 2
x
FIGURE 4.2
Some points for values of 1 + iy.
118 A MATLAB® Companion to Complex Variables
J K
I
H
1
0.5
0 F
v
–0.5
–1
D
C
B A
–0.5 0 0.5 1 1.5 2 2.5
u
FIGURE 4.3
Principal value of the logarithm for numbers in preceding figure.
we cannot map them all. The usual procedure is to map a sufficient num-
ber of points from the curve in the z plane into the w plane—the number
of points is large enough so that if MATLAB connects them together the
resulting curves in either plane resemble the usually smooth ones that we
are considering. If in doubt, overestimate the number of points you think
you might need. The only drawback will be increased required time for the
computation, and this is often not a consideration.
Let us consider two intersecting curves and again map them with the
transformation w = log z. These will be the circle |z| = 2 and the line seg-
ment x = Re(z) = 1, −1 ≤ y ≤ 1.
As a first attempt, we proceed as follows with this code:
clf
y=linspace(−3,3,101);
x=1;
z1=1+i*y;
w1=log(z1);
th=linspace(−pi,pi,100);
z2=2*exp(i*th); % yields 100 points on circle of radius 2
w2=log(z2);
Harmonic Functions, Conformal Mapping, and Some Applications 119
figure(1)
plot(real(z1),imag(z1),'linewidth',2);hold on
plot(real(z2),imag(z2),'linewidth',1);grid on;axis equal
xlabel('x');ylabel('y');title('z plane');grid on
figure (2)
plot(real(w1),imag(w1),'linewidth',2);hold on
plot(real(w2),imag(w2),'linewidth',1);
grid on;axis equal
xlabel('u');ylabel('v');title('w plane')
y=linspace(−3,3,6);th=linspace(−.9*pi,pi,6);
0
y
–1
–2
–3
–3 –2 –1 0 1 2 3
x
FIGURE 4.4
Circle |z| = 2 and Line Re(z) = 1.
120 A MATLAB® Companion to Complex Variables
0
v
–1
–2
–3
–3 –2 –1 0 1 2 3 4
u
FIGURE 4.5
Images of the preceding curves when mapped by Log z.
and a, b, c, … while indicating their image points with bold italic versions of
these letters. We add on this code to the above code. The additional lines
provide an idea of how each curve is deformed by the mapping process:
y=linspace(−3,3,6);th=linspace(−.98*pi,.98*pi,6);
z1=1+i*y; z2=2*exp(i*th);
%we will use fewer data points for the letters
%on the curves than were needed to make the curves
for n=1:length(y)
letter1=char(n+64);
% above creates the letters A, B,...
letter2=char(n+96);
%above creates letters a,b, ...
figure(1);
text(1,imag(z1(n)),letter1,'FontSize',10);
%plots the letters A,B,
% in the z plane on x=1;
text(real(z2(n)),imag(z2(n)), letter2,'FontSize',10)
%
above plots the letters a,b, on the circle in
% the z plane
w1(n)=log(z1(n));
w2(n)=log(z2(n));
figure(2);
Harmonic Functions, Conformal Mapping, and Some Applications 121
tex
t(real(w1(n)),imag(w1(n)),letter1,'FontSize',10, 'FontAngle',
...'italic','FontWeight','bold');
% the above puts in the w plane the italicized bold A,B,..
% which are the images of the points A,B,.. in the z plane
t(real(w2(n)),imag(w2(n)),letter2,'FontSize',10,'FontAngle',
tex
...'italic','FontWeight','bold');
%the above puts in the w plane the italicized bold
%a,b..which are the
%images of a,b,c in the z plane
hold on
end;
With these new lines appended to the preceding program, the output is as
shown in Figures 4.6 and 4.7.
Notice the line of code: th=linspace(−.98∗pi,.98∗pi,6);. We do not set limits
on th (the angle used to locate points of the circle in Figure 4.6) from –pi to pi.
Otherwise in Figure 4.6, the points marked a and f would lie on top of one
another because of the line of code z2=2*exp(i*th), which would produce
two identical values for z2;.
We see how the vertical line x = 1 in Figure 4.6 is bent into the bow shape in
Figure 4.7 that is symmetrical about the real axis. We also see how the circle
of radius 2 is deformed into a line segment. It is not hard to show (try this)
3
F
2
e E
d
1
D
f
0
y
C
–1
c
B
–2
b
A
–3
–3 –2 –1 0 1 2 3
x
FIGURE 4.6
Circle |z| = 2 and Line Re(z) = 1.
122 A MATLAB® Companion to Complex Variables
3
f
2
e
E F
1
D d
0
v
C c
–1
B A
b
–2
a
–3
–3 –2 –1 0 1 2 3 4
u
FIGURE 4.7
Images of the preceding curves when mapped by Log z.
that the segment lies along the line u = Log 2, −π < v ≤ π, because MATLAB
uses the principal value of the log.
Consider the intersection between the circle and the straight line in
Figure 4.6 near the point marked E. The reader should show that the
intersection is at x = 1, y = 3. With a little high school geometry, he or she
should see that the acute angle between the tangent to the circle and the ver-
tical line is 60°. See Figure 4.8 (detail).
If you study Figure 4.9, you will find that the intersection between the
images of the curves shown in the detail appears to also be about 60°.
It is in fact exactly 60°; notice that in each case the curve with the lowercase
letters is displaced 60° counterclockwise from the one with uppercase let-
ters. What we have here is an illustration of the conformal property in complex
variable theory (see W section 8.2, S section 8.4): if w = f(z) is analytic in a
domain D, and if C1 and C2 are two curves intersecting at a point z0 in D, then
the images of these two curves in the w plane will intersect in such a way
that their angle of intersection (at w0 = f(z0)) will be the same as that between
C1 and C2, provided that f′(z0) ≠ 0. Not only is the magnitude of the angle
preserved, but so is its sense. For example, if we must rotate C1 clockwise to
stretch it onto C2 (using the smallest possible angle), then this must be true of
their respective images. We now see where the word conformal comes from
Harmonic Functions, Conformal Mapping, and Some Applications 123
60°
e E
FIGURE 4.8
Detail of an intersection.
60 F
E
FIGURE 4.9
Detail of the images of the intersection for curves in preceding figure.
F
3
60°
2 E
e
d
1
0
y
–1 c
–2 B
b
–3 A
–4
–5
–6 –4 –2 0 2 4 6
x
FIGURE 4.10
A domain in the z plane.
3
f
2 e
60°
1 E F
d
0
v
–1 B
A
b
–2
a
–3
–3 –2 –1 0 1 2 3 4
u
FIGURE 4.11
The image of the domain in the preceding figure under the transformation w = Log z.
Harmonic Functions, Conformal Mapping, and Some Applications 125
For confirmation, note that the point z = 3/2, which lies in the domain
shown in Figure 4.10, has an image lying at w = Log(z) ≈ .4055, which is seen
to lie in the domain depicted in Figure 4.11.
Exercises
1. a. Consider the unit circle |z| = 1. Construct this circle in the z plane
by choosing 100 points uniformly spaced around the circle, plac-
ing them in the z plane, and having MATLAB connect them with
a smooth curve. Be sure to use axes of equal scales to see the cir-
cle. Suppose you had used only the nine points at arg(z) = 0, 45,
90, 135, … 315, 360 degrees, what kind of curve would MATLAB
give you, and how well would it approximate a circle?
b. Using the 100 points employed above, map the circle into the
w plane using the transformation w = ez.
c. Place the nine points described in part (a) on the circle generated
with 100 points in part (a). Label these points with the letters
A, B, C, … .
d. Using MATLAB, plot the images of these points with the letters
(italic) A, B, C, … on the figure in part (b).
2. Consider the rectangular-shaped domain in the z plane whose
boundary points are on the four straight-line segments: y = 0,
−1 ≤ x ≤ 1; y = π, −1 ≤ x ≤ 1; x = ±1, 0 ≤ y ≤ π.
a. Using w = ez, map these four line segments into the w plane by
means of MATLAB. Do this by mapping 100 points from each
segment. Use a heavy line width (e.g., 3) for the boundary in each
plane.
Using MATLAB, place a different capital letter of the alpha-
bet at each of the four corners of the domain in the z plane, and
place one at the midpoint of each line segment. Put correspond-
ing bold italic letters at the images of these points in the w plane.
b. The interior points of the above rectangle form a domain. How is
it mapped into the w plane by the given transformation?
c. Explain why the mapping from the z plane to the w plane is one-
to-one—that is, if we choose any point in the domain found in
part (b), for example, f(z1), it has exactly one image in the domain
given in the z plane (i.e., there is only one possible value for z1).
d. Suppose we change the rectangle in the z plane to y = 0, −1 ≤ x ≤ 1;
y = 2π, −1 ≤ x ≤ 1; x = ±1, 0 ≤ y ≤ 2π, and use the same mapping.
126 A MATLAB® Companion to Complex Variables
az + b
w( z) = (4.1)
cz + d
z= solve('w=(a*z+b)/(c*z+d)','z')
'a pretty answer for z='
pretty (z)
The output is
b − dw
− (4.2)
a − cw
which is obviously also a bilinear transformation. Note that if you run the
above program, you will receive a warning message (not shown here) that
the result is valid only if ad ≠ bc.
You may avoid this warning by using, if you wish,
solve('w=(a*z+b)/(c*z+d)','z','IgnoreAnalyticConstraints',true)
to the right of the equals sign in the first line of code in lieu of
solve('w=(a*z+b)/(c*z+d)','z').
128 A MATLAB® Companion to Complex Variables
Example 4.1
z−1
Let us verify some mappings using the transformation w = and
z+i
MATLAB. We will map, by means of this transformation, these two
circles: |z| = 1 and |z − 1 − i| = 2.
Solution:
Before beginning, notice that as we approach the point z = −i, the func-
tion w(z) → ∞. Now z = −i is on the circle |z| = 1. Thus, at least one
point of the circle has an image at infinity, which means that the image
of the entire circle must be an infinite straight line. Using MATLAB to
plot points from the z to the w plane, we must be careful to avoid z = −i.
Otherwise, we will be dividing by zero and will receive an error mes-
sage. Observe, too, that the given circle passes through z = 1, where w = 0.
Thus, the given line must pass through the origin in the w plane.
The circle |z − 1 − i| = 2 does not pass through z = −i. Thus, w is never
infinite on this locus, and the image of the circle must be another circle.
The code is
th=2*pi*linspace (0,1,1000);
z=exp(i*th);
figure (1);
Harmonic Functions, Conformal Mapping, and Some Applications 129
plot(real(z),imag(z));axis equal;grid on
xlabel('x');ylabel('y');title 'Unit Circle z plane'
w=(z−1)./(z+i);
figure (2)
plot(real(w),imag(w));grid on;axis equal;
xlabel('u');ylabel('v');
z=1+i+2*z;
figure(3)
plot(real(z),imag(z));axis equal;grid on
xlabel('x');ylabel('y');title 'Circle |z−1−i|=2'
w=(z−1)./(z+i);
figure(4);
plot(real(w),imag(w));grid on;axis equal;
xlabel('u');ylabel('v');
There are some things to note here. We have used 1,000 data points on
the two circles in the z plane in order to map these circles into the w plane.
This may seem excessive, but in the case of the transformation applied to the
z−1
circle |z − 1 − i| = 2, it is not. This is because the mapping function w =
z+i
changes rapidly as we approach z = –i. If we expect to obtain a smooth curve
from the mapping, we must obtain enough image points in the w plane to
yield a circle.
0.8
0.6
0.4
0.2
0
y
–0.2
–0.4
–0.6
–0.8
–1 –0.5 0 0.5 1
x
FIGURE 4.12
Unit circle, z plane.
130 A MATLAB® Companion to Complex Variables
600
500
400
300
200
v
100
–100
–200
–300 –200 –100 0 100 200 300 400 500 600 700
u
FIGURE 4.13
( z − 1)
Image in the w plane of the unit circle for w = .
( z + i)
2.5
1.5
1
y
0.5
–0.5
FIGURE 4.14
Circle |z – 1 – i| = 2.
Harmonic Functions, Conformal Mapping, and Some Applications 131
3.5
2.5
1.5
1
v
0.5
–0.5
–1
–1.5
–5 –4 –3 –2 –1 0 1
u
FIGURE 4.15
( z − 1)
Image in the w plane of the circle |z – 1 – i| = 2 for w = .
( z + i)
z−1
We noted that w = goes to infinity at –i and that the unit circle passes
z+i
through this point. On the unit circle, we have z = exp(iθ) 0 ≤ θ ≤ 2π. By not
using θ = 3π/2, we can avoid evaluating w at this point. This is satisfied by
the line of code th=2*pi*linspace(0,1,1000);. In fact, we can replace 1,000
with any even integer and avoid the troublesome point, as the reader should
verify.
( z1 − z2 ) ( z3 − z4 ) ( w1 − w2 ) ( w3 − w4 )
=
( z1 − z4 ) ( z3 − z2 ) ( w1 − w4 ) ( w3 − w2 )
Let us take one of these points, say z4, to be the arbitrary variable z having
image w. Substituting these values in the preceding, we have
132 A MATLAB® Companion to Complex Variables
( z1 − z2 ) ( z3 − z ) ( w1 − w2 ) ( w3 − w )
= (4.3)
( z1 − z ) ( z3 − z2 ) ( w1 − w ) ( w3 − w2 )
The preceding can be solved for either z(w) or w(z) as we wish.
Notice that the values z1, z2, z3 must differ from each other, and the same
goes for their corresponding images w1, w2, w3. (Recall that the bilinear
transformation is one-to-one.) If one of the quantities on the left, say z3, is
infinite, we replace the quotient of the two terms (in this case (z3 − z)/(z3 − z2))
involving this quantity by the number 1. The same technique is used on the
right if there is an infinite quantity there. We can write a MATLAB pro-
gram in which one supplies z1, z2, z3 as well as the desired images w1, w2, w3.
The output from the program can be either w(z) or z(w), or both. The matter
of what to do when a quantity is infinite is taken up in problem 2 in the
exercises.
Example 4.2
Write a MATLAB program in which you enter the finite values z1, z2, z3
and w1, w2, w3 and receive back the bilinear transformation w(z).
Solution:
The following code will work:
w=solve('(w1−w2)*(w3−w)/((w1−w)*(w3−w2))=(z1−z2)*(z3−z)/
((z1−z)*(z3−z2))','w');
zvalues= input(' z1 z2 z3 as row vector elements')
z1=zvalues(1);
z2=zvalues(2);
z3=zvalues(3);
wvalues= input(' w1 w2 w3 as row vector elements')
w1=wvalues(1);
w2=wvalues(2);
w3=wvalues(3);
% the following line substitutes the numerical values into
the formula %for w, in place of the symbols
w=s
ubs(w,{'w1','w2','w3','z1','z2','z3'},{w1,w2,w3,z1,
z2,z3});
simplify(w)
factor(w)
Some things to note include that the line of code using solve will
yield the symbolic solution for w. This employs the symbols for the six
values z1, z2…w1, w2…. The line containing the function subs places the
numerical values in these symbols. The function factor will help us rec-
ognize that we have a bilinear transformation. Notice, however, that
simplify does not always live up to its name. If you attempt simplify
((z − i)/(z2 + 1)), MATLAB will not factor the denominator, divide the com-
mon factor, and give you back 1/(z + i). Thus, the fact that such a func-
tion is a bilinear transformation is not evident. You must be prepared
for such outcomes. Sometimes factor can be helpful in these situations.
Notice also that the function solve results in the output of the program
Harmonic Functions, Conformal Mapping, and Some Applications 133
warning you that we cannot find w(z) if the points to be mapped in either
plane are not numerically distinct. The warning can be eliminated by
adding 'IgnoreAnalyticConstraints', true in the solve expression
as discussed above.
ans = (z − 1)/(z + 1)
ans = [z − 1, 1/(z + 1)]
These two answers are consistent; the second simply factors the first.
You can check this formula by installing the previous values of zn and veri-
fying that the desired values of wn are obtained.
Because this bilinear transformation contains only real coefficients, we
know that it will map a circle, in the z plane, with center on the x axis into
either a circle with center on the u axis or into an infinite line perpendicular
to that axis. The circle with center at z = 1 having radius 1 passes through the
given points 0, 2, 1 + i. The image of this circle in the w plane passes through
1 2i
the three points w1 = −1, w2 = 1/3, w3 = + and has center at the average of
5 5
–1 and 1/3 (i.e., at w = –1/3). Suppose we want to see how the transformation
thus obtained maps the circle |z − 2i| = 1. We add on these lines of code to
the preceding:
th=linspace (0,2*pi,100);
z=
2*i+exp(i*th);% creates the points on the circle, center at 2i
w=subs(w,{'z'},{z});% puts the values we need into w
figure (1)
plot(real(w),imag(w));axis equal
For the values of z1, z2 … w1, w2 … specified above, the output of this would
be a circle.
Because a nonconstant analytic function maps a domain into a domain, it
should be possible to find a bilinear transformation that maps the real axis
in the z plane into the unit circle in the w plane in such a way that the image
of the upper half of the z plane is the interior of that circle. Notice that we can
rewrite Equation 4.1 as
a z + b/a
w ( z) = (4.4)
c z + d/c
where we must assume that a and c ≠ 0. If c were zero in Equation 4.1, we could
not argue that z = ∞ has an image at a finite point in the w plane. The limit
of the right side in the above expression as z → ∞ is a/c. As we want this to
134 A MATLAB® Companion to Complex Variables
a
lie on the unit circle in the w plane, we can take = e it, where t is any real
c
number. Suppose z = x is real. We want the image for such a point to have
magnitude 1.
Then we obtain from Equation 4.4
x + b/a x + b/a
w( z) = e it = =1
x + d/c x + d/c
How do we know that the space above the axis is mapped into the interior of
the circle? If we take p as any point in the z plane satisfying Im(p) > 0, we see
from the above that it is mapped into the origin of the w plane—the center of
the circle. Because domains are mapped into domains by the above, we con-
clude that the transformation in Equation 4.5, with Im(p) > 0, maps the upper
half plane into the domain bounded by the unit circle and the boundary
y = 0 into the unit circle.
Example 4.3
Write a MATLAB program that will accomplish the following. It is to
produce a bilinear transformation that will transform the real axis in
the z plane into the unit circle of the w plane. The program will request
a particular point in the upper half plane that will be mapped into the
origin in the w plane. Finally, the program will request a particular point
on the real axis z that is to have a specified image on the unit circle in
the w plane.
Solution:
The following program will work:
Here we try the program out. We will ask that z = i be mapped into
π
i
w = 0 and that z = 1 be mapped into w = e 4 , which, as required, is on the
unit circle.
Here are the inputs, outputs, and the result:
Exercises
1. a. In Example 4.1, using MATLAB, we mapped the unit circle
|z| = 1 into the w plane by means of the transformation
z−1
w= . We obtained what appears to be the infinite line v = u.
z+i
Prove mathematically that this line is indeed obtained.
Hint: In the given expression for w(z), multiply numerator and
denominator by the conjugate of the denominator. We can gener-
ate the given circle in the x–y plane with z = eiθ, where 0 ≤ θ ≤ 2π.
Substitute this expression for z in the equation just obtained, and
show that if w = u + iv, then u and v are such that v = u which is
the equation of a straight line through the origin in the w plane.
It should be obvious that the line passes through infinity when
z goes through –i.
b. Using MATLAB, plot in the w plane the image of the circle
|z − 1 − i| = 1 under the transformation w = 1/z. The original cir-
cle has center at z = 1 + i. Does its image have center at 1/(1 + i)?
Where is its center? Figure this out analytically and confirm it
from your plot.
136 A MATLAB® Companion to Complex Variables
( z1 − z2 ) ( w1 − w2 ) ( w3 − w )
=
( z1 − z ) ( w1 − w ) ( w3 − w2 )
az + b ez + f
f ( z) = and f1 ( z ) =
cz + d gz + h
which are each bilinear. Then
Harmonic Functions, Conformal Mapping, and Some Applications 137
az + b
a
f ( f1 ( z ) ) = cz + d
+b
=
( )
a 2 + bc z + bd + ab
+ d ( ac + dc ) z + bc + d
az + b 2
c
cz + d
z+1 z+i
f ( z) = and also f ( z) =
z−1 z − 2i
∂2 Ω ∂2 Ω
+ = 0 (4.6)
∂x2 ∂y 2
− ∂φ − ∂φ
Ex ( x , y ) = Ey ( x , y ) = (4.7)
∂x ∂y
140 A MATLAB® Companion to Complex Variables
∂φ ∂φ
Vx ( x , y ) = Vy ( x , y ) = (4.8)
∂x ∂y
For heat conduction,
− k ∂φ − k ∂φ
Qx ( x , y ) = Qy ( x , y ) = (4.9)
∂x ∂y
Here k is a constant peculiar to the heat-conducting medium and is called
its thermal conductivity. If you are familiar with the concept of the gradient or
the del operator, ∇, you see that
V = ∇ϕ = grad ϕ (4.11)
The vector E, for example, which has components Ex(x, y) and Ey(x, y),
is “minus the gradient of ϕ”; it is the vector whose components are
− ∂φ − ∂φ
and . Note that some authors would put minus signs after the
∂x ∂y
equals signs in Equations 4.8 and 4.11. There is no unanimity here.
MATLAB is useful to us here in several ways. First, given a function ϕ(x, y),
how can we tell if it is harmonic? For a simple function, say ϕ(x, y) = x2 − y2,
it should be evident that Equation 4.6 is satisfied with ϕ = Ω, and by contrast,
ϕ(x, y) = x2 + y2 does not satisfy the equation and is not harmonic. Verify
this. Thus, the first of these can serve as a voltage, velocity potential, or tem-
perature function while the second cannot. Suppose we are given a more
( )
complicated function φ ( x , y ) = e e cos y cos e x sin y . It is not obvious if this is
x
harmonic, although the question is readily resolved with the following code:
syms x y
g=exp(exp(x)*cos(y))*cos(exp(x)*sin(y));
A=diff(g,x,2)+diff(g,y,2)
A=diff(g,x,2)+diff(g,y,2)
this function is harmonic in any domain of the complex plane. This function z
was constructed by a choice of ϕ(x, y) as the real part of the function e( e ),
which must of course be harmonic. The reader should compute the real and
imaginary parts of this function.
Suppose we proceed as above and try to determine whether the function
−2 xy
φ ( x, y ) =
(x )
2 2
+ y2
is harmonic. The code
syms x y
gg=(-2*x*y)/(x^2+y^2)^2;
B=diff(gg,x,2)+diff(gg,y,2)
Since, unlike in the previous example, we do not simply get zero, we might
conclude that this is not a harmonic function. Wrong. The additional line of
code, which simplifies the above, B=simplify(B) has as its output B = 0
which confirms that we have a harmonic function, one that the reader should
1
verify is the imaginary part of f ( z) = . We had to simplify our result
( x + iy )2
to see this. We should, to be safe, try to simplify our result in such calcula-
tions, to determine if we have a harmonic function. However, before con-
−2 xy
cluding that the function φ ( x , y ) = 2 is harmonic everywhere, take
(
x + y2
2
)
note of the fact that it is undefined at z = 0 and therefore is not differentiable
at the origin. MATLAB ignores this. Thus, the correct conclusion is that this
function is harmonic in any domain not containing the origin.
In the preceding, we began with a real function ϕ(x, y) and used MATLAB
to determine whether the function is harmonic. Alternatively, we might begin
with an analytic function f(z) and extract its real or imaginary part. Each
must be harmonic in any domain where f(z) is analytic. Often the problem of
extracting u(x, y) + iv(x, y) from f(z) is simple. For example,
x y
f ( z) = 1/ z = 1/ ( x + iy ) = 2 2
−i 2
x +y x + y2
whose real and imaginary parts
x −y
and
x + y2
2
x + y2
2
are harmonic in any domain not containing the origin.
142 A MATLAB® Companion to Complex Variables
This is an entire function whose real and imaginary parts are harmonic
everywhere. The following code shows how to extract the real and imagi-
nary parts u(x, y) and v(x, y) and confirms in addition that these parts are
harmonic:
The output is
w = exp(cos((x + y∗i)^2))
u = exp(cosh(2∗x∗y)∗cos(x^2 − y^2))∗cos(sinh(2∗x∗y)∗sin(x^2 − y^2))
v = −exp(cosh(2∗x∗y)∗cos(x^2 − y^2))∗sin(sinh(2∗x∗y)∗sin(x^2 − y^2))
u_check = 0
v_check = 0
syms x y real
This tells MATLAB that x and y are real. Without this line, we could not use
the real(w) and imag(w) operations to extract the real and imaginary parts of
w because MATLAB would assume that x and y are complex.
We have chosen to check that the real part of w, which we call
wr(x, y), is harmonic through the inclusion of the line of code
u_check =diff(u,x,2)+diff(u,y,2).
The output of zero, which is the sum of the second x and y derivatives
of wr(x, y), confirms that we have a function that is harmonic everywhere.
A similar check is made on the imaginary part of w.
Incidentally, the functions u(x, y) and v(x, y) obtained from the preceding
code might be more comfortably written as
and
clear
syms x y real
syms z
z=x+i*y
A0=sin(z)
A0r=real(A0)
A1=sin(1/z)
A1r=real(A1)
A2=sin(z*sin(1/z))
A2r=real(A2)
A3=sin(z^2)
A3r=real(A3)
Whose output is
z = x + y∗i
A0 = sin(x + y∗i)
A0r = cosh(y)∗sin(x)
A1 = sin(1/(x + y∗i))
A1r = cosh(y/(x^2 + y^2))∗sin(x/(x^2 + y^2))
A2 = sin(sin(1/(x + y∗i))∗(x + y∗i))
A2r = real(sin(sin(1/(x + y∗i))∗(x + y∗i)))
A3 = sin((x + y∗i)^2)
A3r = cosh(2∗x∗y)∗sin(x^2 − y^2)
Refer to A2r above. Note that MATLAB was unable to present the real part
of sin(z sin(1/z)) as an explicit real function of x and y. In the case of the other
functions sin(z), sin(1/z), sin(z2), we were successful.
To deal with the case of sin(z sin(1/z)), we can break the operation into
steps for MATLAB, first obtaining the real and imaginary parts of sin(1/z)
and entering that result into the argument of sin(z sin(1/z)). It will be found
that the following will produce an explicit function for the real part of
sin(z sin(1/z)):
clear
syms x y real
144 A MATLAB® Companion to Complex Variables
syms z
z=x+i*y
A1=sin(1/z)
A1r=real(A1);
A1i=imag(A1);
A2=sin(z*(A1r+i*A1i))
A2r=real(A2)
The output is
Using MATLAB, you can readily show that the preceding is a harmonic
function in any domain not containing the origin.
In Section 2.2 we saw how the properties of a real function of the two real
variables, like ϕ(x, y), can be studied through a set of contour plots. In electric-
ity, if the harmonic function ϕ(x, y) describes the potential in space, then such
contour plots are the loci on which the voltage is constant. These are the traces
in the x−y plane of the surfaces of constant voltage, often referred to as equipo-
tential surfaces. Similarly, if a temperature is given by ϕ(x, y), then the contour
plots of ϕ(x, y) are isotherms, or surfaces of constant temperature. Finally, in
fluid mechanics, we can also plot and speak of equipotential surfaces.
To review this subject, consider for example an infinitely long, uniformly
charged, filament passing perpendicularly through the complex plane at the
point (x0, y0). The electric potential (voltage) created in the surrounding mate-
rial is given by
1
φ( x , y ) = C Log (4.13)
( x − x0 ) + ( y − y 0 )
2 2
One should use MATLAB (as was done earlier) to quickly verify that ϕ(x, y)
is a harmonic function in any domain not containing (x0, y0).
* In this case, C = ρL/(2πε0), where ρL is the charge per unit length on the filament and ε0 is
a constant found in handbooks called “the permittivity of free space.”
Harmonic Functions, Conformal Mapping, and Some Applications 145
Example 4.4
An electrical transmission line is being approximated as two oppo-
sitely charged filaments. The positive filament passes through z = 1
while the negative one passes through z = –1. Each filament is perpen-
dicular to the complex plane. The potentials created by the filaments
can be obtained from Equations 4.13 and 4.14. We take z 0 = 1 or z 0 = −1
as needed. Thus,
and
x=linspace(−4,4,100);
y=linspace(−4,4,100);
n=linspace(−2,2,5);
[x,y]=meshgrid(x,y);
z=x+i*y;
w=−log(z−1)+log(z+1);
wr=real(w);
[c,h]= contour(x,y,wr,n);colorbar;
xlabel('x');ylabel('y');
title('Contour Lines for Log|z+1|−Log|z−1|')
grid
clabel(c,h);axis([−2.5 2.5 −2.5 2.5])
2.5
0
2
1.5
1
–1 1
0.5
–2
2
0
y
–0.5
–1 0 1 1
–1
–1.5
–2
–2.5
–2.5 –2 –1.5 –1 –0.5 0 0.5 1 1.5 2 2.5
x
FIGURE 4.16
Contour lines for log|z + 1| – log|z – 1|.
the heat flux density in other situations. The electric field is the vector
having components given in Equations 4.7 and 4.10.
MATLAB provides a convenient graphical means for visualizing the
gradient vector. This involves using the MATLAB functions gradient
and quiver, and the reader should read the documentation for these in
the help folder. Let the function ϕ(x, y) be approximated by numerical
values at the intersections of a rectangular grid, perhaps one gener-
ated by meshgrid. The MATLAB function gradient uses the differences
between values of ϕ(x, y) at adjacent points to compute numerical values
of the components of the gradient at the same grid points. For example,
at some point with coordinates xj, yk,
( ) (
∂φ φ x j+1 , y k − φ x j , y k
≈
)
∂x ∆x
Example 4.5
Let ϕ(x, y) = x2 − y2 = Re(z2), a harmonic function. The following code
illustrates the use of gradient and quiver to show us a picture of the gra-
dient of the function. You might wish to study quiver in the help folder.
clf
v=linspace(−3, 3, 100);
[x,y]=meshgrid(v);
f=(x.^2−y.^2);
figure (1)
n=linspace(−2,2,5);
[c,h]=contour(x,y,f,n);axis equal
clabel(c,h);colorbar
hold on
%following uses coarse spacing for gradient
%which is desirable
v=linspace(−3, 3, 10);
[x,y]=meshgrid(v);
f=x.^2−y.^2;
[gx,gy]=gradient(f);
quiver(x,y,gx,gy);
title('contour lines and gradient for x^2−y^2')
–2 1
–
1
2
0
2
–2
–1
1
2
1
0
0
0
1
–1
2
–1
–2
–2
2
0
1
–1 –2
0
–3
–3 –2 –1 0 1 2 3
FIGURE 4.17
Contour lines and gradient for x2 – y2.
Notice that we are using a coarser grid to plot the gradient (compare 100
versus 10). Had we used as fine a grid to plot the gradient as was done
with the surfaces of constant ϕ, we would have obtained a plot from
quiver so densely filled with arrows as to be unintelligible. The reader
should verify this for him- or herself. The plot shown above is in black
and white, but the code will generate a more attractive color picture.
To find the numerical values of the gradient of ϕ, we are best served by using
the formula for grad ϕ rather than the line of code [gx,gy]=gradient(f),
which would yield a result based on an approximate evaluation of the deriva-
tives with respect to x and y. In the present problem, the gradient is a vector
having components
(
∂ x2 − y 2 ) = 2 x and ∂( x 2
− y2 )
= −2 y. These are readily
∂x ∂y
evaluated on any grid of points by means of MATLAB. Observe that both
components of the vector vanish at the origin, which explains the absence of a
vector in the above figure at this point.
Example 4.6
Using quiver, plot the negative of the gradient, for the equipotentials
shown in Figure 4.16. We are using the negative of the gradient because
the electric field is generally the vector with components −∇ϕ, where
ϕ(x, y) is the electrostatic voltage.
Harmonic Functions, Conformal Mapping, and Some Applications 149
The following code will work. We simply add these lines to those used
in Example 4.4:
hold
v=linspace(−2.5, 2.5, 10);
[x,y]=meshgrid(v);
z=x+i*y;
w=−log(z−1)+log(z+1);
wr=real(w);
[gx,gy]=gradient(−wr);
quiver(x,y,gx,gy,.75);
The .75 scales down the length of the arrows to three quarters of their
normal length. Without this number, the arrows are longer and crowd
each other in the figure. Observe that the vectors representing the elec-
tric field emanate out from the positive charge on the right and head
toward the negative one on the left, as is to be expected. The arrows
strike the equipotentials at right angles.
Your plot will be in color and will have a color bar. We give here only
a gray-scale version.
2.5
0
1.5
1
–1
0.5
–2
0
y
–0.5
–1
–1
–1.5
–2
–2.5
–2 –1 0 1 2
x
FIGURE 4.18
Electric field for –log|z – 1| + log|z + 1|.
150 A MATLAB® Companion to Complex Variables
Exercises
1. Using MATLAB, determine whether the following functions are har-
monic. If a function is harmonic in general except at certain points,
state where these points are located.
a. cos(x2 + y2) cos(2xy)
b. cos(x2 − y2) cos(2xy)
c. Log(sinh2 x + sin2 y)
d. Log(cosh2 x + sin2 y)
1
e. e
− tan −1( y/x )
( )
sin Log x 2 + y 2 , where the principal value of the
2
arctan is used. In MATLAB you will have to use atan(y/x) and
not atan2(y,x), as MATLAB will not do symbolic differentiations
involving the latter function. As the two functions differ only by
a constant, their derivatives are identical.
2. With z = x + iy, express the following functions in the form
f(z) = u(x, y) + iv(x, y), finding u(x, y) and v(x, y) by means of MATLAB,
and use MATLAB to show that both u(x, y) and v(x, y) satisfy Laplace’s
equation in a domain. State where the equation is not satisfied.
a. cos(1/z)
b. cos(cos z)
c. 1/(z − i)5
Harmonic Functions, Conformal Mapping, and Some Applications 151
d. (z + z−1)5
e. sinh(sin z2)
3. An electrostatic potential in space is being created by two identi-
cal positively charged filaments. One filament passes through z = 1,
while the other passes through z = –1. Each filament is perpendicu-
lar to the complex plane. The potentials created by the filaments are
from Equations 4.13 and 4.14.
and
φ2 ( x , y ) = − Log ( x + 1)2 + ( y )
2
= − Log|z + 1|
where the constant C has been set equal to 1. The combined potential
is given by
Here ψ(x, y) is a real function that is known as the stream function because
of its connections to fluid mechanics, although the term is used in electricity
and heat transfer as well. Thus, ψ and ϕ are conjugate functions. The former
can be as useful as the latter, as we see later. The function Φ(x, y) is called the
complex electric potential (in electrostatics) or complex temperature (in the case of
heat flow) and the complex velocity potential (for fluid flow). Suppose we know
either ϕ or ψ. Can we use one to find the other?
2x + 1 = ∂v/∂y (4.18)
We integrate Equation 4.18 with respect to the variable y and Equation 4.19
with respect to the variable x. We also swap the locations of the minus sign
in Equation 19 and get Equations 4.20 and 21:
Here c1(x) is a function that can depend on x but not on y, while c2(y) is a func-
tion that can depend on y but not on x. C2 and C4 are true constants. One should
verify the above results by substituting back into Equations 4.18 and 4.19.
Now Equations 4.20 and 4.21 should both be valid expressions for v. The
difference between them must be identically zero. Subtracting the second
from the first gives us the expression we call difference:
Setting difference equal to zero, we see that we must take c1(x) = −x, c2(y) = y
as well as C2 = C4.
The number C2 = C 4 is simply a true constant, independent of x and y,
and its value can only be found if the numerical value of v(x, y) is known at
some value of (x, y). Thus, using our derived values in either Equation 4.20
or Equation 4.21 gives
v = 2xy + y − x + C2
clear all
syms y x v ux uy v1(y) v2(x) c1(x) c2(y) difference;
u=y+x^2−y^2+x;
ux=diff(u,x);
uy=diff(u,y);
%below solves du/dx=dv/dy
v1=dsolve(ux==diff(v1),y)+c1(x);
%below solves du/dy=−dv/dx
v2=dsolve(uy==−diff(v2),x)+c2(y);
v1=simplify(v1)
v2=simplify(v2)
difference=v1−v2;
difference=simplify(difference)
The reader might wish to study the MATLAB help for diff and dsolve.
Notice that the lines of code ux=diff(u,x) and uy=diff(u,y) compute
∂u ∂u
and . The next two lines of code, which employ dsolve, solve
∂x ∂y
∂u ∂ v ∂u − ∂ v
= and = . We add on “constants” c1 and c2, which can depend
∂x ∂y ∂y ∂x
on x and y, respectively. We derive two expressions for v(x, y), which we call
v1 and v2, respectively. We form the difference of these expressions. The
output of the program is
v1 = C2 + y + c1(x) + 2*x*y
v2 = C4 − x + c2(y) + 2*x*y
difference = C2 − C4 + x + y + c1(x) − c2(y)
154 A MATLAB® Companion to Complex Variables
Studying the above line, we see that if the difference in our two expressions
for v is to be zero throughout a region of the x–y plane, then c1(x)=-x
and c2(y)=y. We may install these in the expression for either v1 or v2.
The constant C2=C4 remains undetermined. We have just found the value
of v = 2xy + y − x + C2 to within a constant. In this particular problem, C2
and C4 are the numerical values of v(0, 0). In the exercises, you will do some
MATLAB problems similar to the above where the computer program can
save us some labor.
A program similar to the above can be written if we are supplied with the
imaginary part of an analytic function and are seeking the real part. This is
left to the exercises.
Recall that in textbooks in complex variable theory, the Cauchy–Riemann
equations are derived by equating two equally valid expressions for the
derivative of a function of a complex variable. Thus, with f(z) = u(x, y) + iv(x, y),
∂u ∂ v ∂v ∂u ∂v
we have both f ′ ( z ) = +i and f ′( z) = − i . We can eliminate in
∂x ∂x ∂y ∂y ∂x
the first of these by means of a Cauchy–Riemann equation (Equation 4.17)
∂u ∂u
and obtain f ′ ( z ) = − i . If we take Φ(z) = ϕ(x, y) + iψ(x, y) as our analytic
∂x ∂y
∂φ ∂φ
function, we have Φ′ ( z ) = − i , and finally
∂x ∂y
∂φ ∂φ
Φ′ ( z ) = +i (4.22)
∂x ∂y
Ex ( x , y ) + iEy ( x , y ) = − Φ′ ( z ) (4.23)
For this complex potential Φ(z), the real part ϕ(x, y) is the velocity potential
describing fluid flow.
Harmonic Functions, Conformal Mapping, and Some Applications 155
Qx ( x , y ) + iQy ( x , y ) = − k Φ′ ( z ) (4.25)
The real and imaginary parts on the left are the components of the heat
flux density vector, and k is the thermal conductivity of the material in use.
Of what use is the stream function ψ(x, y)—the imaginary part of the
potential—in each of these three cases? Recall that for the analytic function
Φ(z) = ϕ(x, y) + iψ(x, y), if we generate a set of curves ϕ(x, y) = α1, α2, …, and
another set of curves ψ(x, y) = β1, β2, … (where the α and β values are real con-
stants), the two sets of curves will meet at right angles—they are orthogonal.
The orthogonality property can break down at a point where Φ′(z) = 0. Recall
also that in electrostatics the electric field at each point in space is at right
angles to the curve of constant potential (the curve of constant ϕ) passing
through that point. Thus, at each point in space, the electric field vector must
be tangent to the curve of constant ψ passing through that point. The state-
ment breaks down only at those places where the electric field vanishes—
here we cannot assign it a direction.
In a similar fashion, in fluid mechanics, the curves along which the
stream function maintains constant values, the “streamlines,” are the
curves that are tangent to the direction of fluid flow. The curves do not
by themselves show the actual sense of flow (i.e., the direction of motion
along the s treamline)—this must be computed from either Equation 4.24 or
Equation 4.8. However, we can frequently tell the direction along the curve
by a simple physical argument. Finally, in heat conduction problems, the
streamlines—the curves of constant ψ—are the curves that are tangent to
the direction of heat flow.
In fluid mechanics, we require that any impermeable boundary be coinci-
dent with a streamline. Let us look at the following case.
The analytic function Φ(z) = z, z = x + iy is not a very interesting complex
velocity potential. We have from Equation 4.24 that Φ ′ ( z ) = 1 = Vx + iVy so
that Vx = 1 and Vy = 0. Thus, fluid is moving uniformly in the positive x
direction with uniform velocity. The stream function ψ(x, y) = y and so the
streamlines are simply the lines on which y assumes fixed real values, for
example, y = 0, ±1, ±2, …. Suppose we add to this analytic function the ana-
lytic function 1/z. Thus, Φ(z) = z + 1/z, where we exclude the origin. Notice
that as z → ∞, Φ(z) → z, which means that the flow is uniform at infinity.
Let us ask MATLAB to generate the streamlines for this potential. This code
will do that:
clf;clear
x=linspace(−6,6,200);
y=linspace (−6,6,200);
n=linspace (−2,2,9);
[x,y]=meshgrid(x,y);
156 A MATLAB® Companion to Complex Variables
z=x+i*y;
w=z+1./z;
wi=imag(w);
[c,h]= contour(x,y,wi,n);colorbar;
axis equal
xlabel('x');ylabel('y'); grid
clabel(c,h);
Φ( z) = z + 1/z = x + iy + 1/( x + iy ) = x + iy +
( x − iy )
x2 + y 2
6 2
1.5
4
1
2 2
2 2 2 2
1.5 1.5
1.5 1 1.5 1.5 0.5
1
1 0.5 1 1
0.5 –1
0.5 0.5 0.5
–0 1.5
–
–2
0
.5
0 0 0 0 1.5 0 0 0 0
y
0.5
0
12
–4
–1.5
–6 –2
–6 –4 –2 0 2 4 6
x
FIGURE 4.19
1
Streamlines for z + .
z
Harmonic Functions, Conformal Mapping, and Some Applications 157
y
Thus, ψ ( x , y ) = Im Φ ( x , y ) = y − . If we equate the preceding
x + y2 ( 2
)
to zero, we find that the equation is satisfied by either y = 0 or x2 + y2 = 1
(which is |z| = 1) as the figure suggests. Thus, the unit circle is a streamline
of this given complex potential.
The complex velocity for this flow is found from Equation 4.24. With the
given potential, we have Vx + iVy = 1 − 1/z 2. We see that as z → ∞, Vx → 1 and
Vy → 0. There is a flow of fluid that moves from left to right. It begins as a
uniform flow and ends the same way. Knowing the direction of the flow, we
added arrows to some of the streamlines.
The contour |z| = 1 is a streamline, which means that flow is everywhere
tangent to this circle. We may place a rigid barrier in coincidence with this
circle and not affect the flow of fluid in and outside this barrier. Of course,
no fluid will get inside the barrier. Thus, we may interpret the streamlines
outside the unit circle in Figure 4.19 as showing the flow around what
might be an infinitely long wooden log of unit radius that has been placed
inside a uniform stream of infinite extent. Under these circumstances, the
streamlines shown inside the unit circle in this same figure have no physical
meaning, and the fact that we cannot read the numbers on these lines is of
no consequence. If you want to know the actual fluid velocity at any point
outside the log, you can use
hold on
axis([−2 2 −2 2])
th=linspace(0,2*pi,1000);
z=exp(i*th);
plot(z,'linewidth',2)
158 A MATLAB® Companion to Complex Variables
We have added arrows to the streamlines after the plot has been formed.
Figure 4.20 presents the result.
Our complex potential is now
Φ ( z ) = φ ( x , y ) + iψ ( x , y ) = iz + i/z = − y + ix + i/( x + iy ) = − y + ix +
( y + ix ) (4.27)
x2 + y 2
1.5
1
–0.5 –1 1.5
0.5
0
0.5
–2
2
5 1
–
1.
–2
0
y
2
2
–0.5
–1
–1.5
–0.5
1.5
0.5
–1
–2
–1.5
1
2
0
2
–2 –1.5 –1 –0.5 0 0.5 1 1.5 2
x
FIGURE 4.20
A plot of a unit circle and the streamlines of arrows.
Harmonic Functions, Conformal Mapping, and Some Applications 159
1.5
β
1
C´ α
0.5
Closed contour C
0
–0.5
–1
–1.5
–2
–2 –1.5 –1 –0.5 0 0.5 1 1.5 2
FIGURE 4.21
A contour for studying ψ.
160 A MATLAB® Companion to Complex Variables
(see W chapter 8 and its appendix) that in heat conduction, the expression
H = kΔψ gives the flux of heat flow (the rate at which energy is transported
by heat conduction) across a surface of unit length (perpendicular to the x–y
plane) whose edge is this segment C′. Positive flow is from the interior to
the exterior of the domain whose boundary is C. Recall that k is the heat
conductivity of the medium in use. In fluid mechanics, the expression
G = −Δψ = ψ(β) − ψ(α) is the rate at which fluid moves across the same surface
(assumed permeable) from interior to exterior. Finally, in electrostatics, the
formula F = εΔψ gives the flow of electric flux lines across the surface. Here,
ε is a constant, called the permittivity, that describes the electrical properties
of the medium in which the electric field exists. Note that all of the preceding
statements involving Equation 4.28 presume that ψ varies continuously as we
move along the surface in question.
Let us look at the configuration of Figure 4.19. If the cylinder were not
present, then the flow of fluid would be uniform and given by the potential
Φ(z) = x + iy. How much fluid flows through a rectangular surface like the
one described above whose edge is the line segment x = 1, −1 ≤ y ≤ 1? Now
following the notation of Equation 4.27, we have α = (1, −1) and β = (1, 1).
Since ψ = y, we have Δψ = −1 − 1 = −2 . The rate of flow of fluid is G = −Δψ = 2.
This might be measured in such units as liters per second or gallons per
minute, depending on the system in use. If the cylinder of unit radius shown
in Figure 4.19 is now placed in the fluid, so as to impede the flow, we have
y
shown that ψ ( x , y ) = Im Φ ( x , y ) = y − 2 . Evaluating ψ at points at α
( )
x + y2
and β, we have –½ and ½, respectively. Thus, G = −Δψ = 1. The flow through
the surface has been reduced from 2 to 1 by this impediment.
Exercises
Solve the following problems by means of suitable MATLAB programs. All
of the functions given are harmonic.
1. If the real part of an analytic function is sin(x2/2 − y2/2 + x) cosh(xy + y),
find the imaginary part. Evaluate any arbitrary constant in your answer
by assuming that the sought-after function is zero at the origin.
2. If the real part of an analytic function is y+ arctan(y/(x − 1)), find the
imaginary part. Evaluate any constant by assuming that the func-
tion is zero at z = 0.
x2 − y 2
3. If the real part of an analytic function is x 2 − y 2 + 2 + 2 , find
( )
x2 + y 2
the imaginary part. Evaluate any constant by assuming that the
function is zero at z = 1.
Harmonic Functions, Conformal Mapping, and Some Applications 161
1 y
2 ( )
sin log x 2 + y 2 + y + 1 cosh arctan − x ,
x
find the real part to within an additive constant.
5. If the imaginary part of an analytic function is
e ( )
arctan y /x
( )
cos Log x 2 + y 2 + 1 + 2 y − x
find the real part. Assume that the real part equals 1 at z = 1.
6. In the previous section, Example 4.5, we used gradient and quiver
in MATLAB to create arrows pointing in the direction of the gradi-
ent of the function u(x, y) = x2 − y2. The gradient at each point in
space must be normal to the surface, on which u is constant, passing
through that point. The gradient must therefore be tangent to the
streamline passing through that point. Determine the stream func-
tion for this function u(x, y) and plot the streamlines on the same
figure as the vectors for the gradient. Verify that the arrows from
quiver are along the streamlines.
7. Suppose fluid motion is caused by a flow that is uniform at infin-
ity and in the x direction. Suppose that there are present, normal to
the complex plane, a line source of fluid and a corresponding sink
of identical strength. The source and sink penetrate the x axis. The
streamlines for this overall arrangement form interesting shapes.
One in particular forms an oval shape known as a Rankine Oval.
Consider the complex velocity potential given by Φ(z) = ϕ(x, y) +
iψ(x, y) = V∞ z − C Log(z − 1) + C Log(z + 1). Here V∞ is the velocity
of the fluid at infinity, while C (a positive real) is the strength of the
fluid source at z = –1. There is a corresponding sink at z = 1.
a. Take V∞ = 1 and C = 1. Using MATLAB, plot the streamlines of
this flow. A suggestion for a nice plot: let the values of ψ on the
plot be the nine integers satisfying –4 ≤ ψ ≤ 4.
Consider |x| ≤ 5 and |y| ≤ 5.
b. Study your plot. What is special about the curve on which ψ = 0?
This is called a Rankine Oval. Other such ovals are obtained
by adjusting the separation of source and sink, the strengths of
these, C, and the value of V∞.
c. Consider a rectangular surface that freely allows the passage of
fluid through itself. The surface is normal to the x axis and is
described by x = 2, 0 ≤ y ≤ h, where h is real. The surface is one
unit long in the direction normal to the z plane. Write a MATLAB
program, using the stream function, that plots the rate of fluid
flow (the flux of fluid) through this surface as h varies from 0 to 4.
162 A MATLAB® Companion to Complex Variables
D D1
∂φ ∂φ
2 2
∂2φ1 ∂2φ1
+ =0 + =0
∂x2 ∂y2 ∂u2 ∂v2
C (boundary) C1 (boundary)
f(z) = w
z-plane w-plane
(a) (b)
FIGURE 4.22
A domain D (a) and its image D1 (b).
Harmonic Functions, Conformal Mapping, and Some Applications 163
which is analytic everywhere except on the negative real axis and the origin.
Separating into real and imaginary parts, we have
i arg ( w ) i
Φ (w) = − Log w = − Log w = φ ( u, v ) + iψ ( u, v ) (4.30)
π π π
We will confine our attention to the half space v ≥ 0 with the origin excluded.
Now
1 1 v
φ ( u, v ) = arg ( w ) = tan −1 (4.31)
π π u
1 1 1
ψ ( u, v ) = − Log w = Log 2 (4.32)
π 2π u + v2
1 v
Notice that the harmonic function φ ( u, v ) = arg ( w ) =
tan −1 is continu-
π u
ous in the upper half of the w plane and equal to zero on the positive u axis
and equals 1 on the negative real axis. It is undefined at the origin.
The equipotential surfaces are simply rays extending out from the origin,
the edges of the surfaces on which arg(w) is constant. A plot of this is pre-
sented in Figure 4.23.
164 A MATLAB® Companion to Complex Variables
0.6
6
0.4
0.8 2
0.
4
0.6
v
0.4
0.8
0.2
2
0.6
0.02 .4
0.8
0 1 1 0 0
–2
–6 –4 –2 0 2 4 6
u
FIGURE 4.23
−i
The contour lines for real Re Log w in the upper half plane.
π
clf
x=linspace (−7,7,100);
y=linspace (0, 7,100);
[x,y]=meshgrid(x,y);
z=x+i*y;
phi=−i*log(z)/(pi);
phir=real(phi);
phim=imag(phi)
values=linspace(0 ,1,6);
figure (1)
[g,h]=contour (x,y,phir,values,'linewidth',2);
clabel(g,h);
grid
xlabel('u');ylabel('v');axis equal
x=linspace (−7,7,100);
y=linspace (0, 7,100);
[x,y]=meshgrid(x,y);
z=x+i*y;
phi=−i*log(z)/(pi);
phir=real(phi);
phim=imag(phi)
Harmonic Functions, Conformal Mapping, and Some Applications 165
values=linspace(0 ,−1,6);
figure (2)
[g,h]=contour (x,y,phir,values,'linewidth',2);
clabel(g,h);
grid
xlabel('u');ylabel('v');axis equal
If you run the above code, you see (with Release 2015a) that MATLAB fails
to correctly label the ray y = 0, x > 0 as being the contour on which our func-
tion is zero. We have added in this zero by editing Figure 4.23. I am told that
this weakness in MATLAB will likely be fixed in a future version.
The imaginary part of the complex potential is
1 1 1
− Log w = Log 2 (4.33)
π 2π u + v2
7
–0.6
–0.6
6 6
–0.
–0
5 .6
.6
–0
4
–0.4
v
–0.
3
6
–0
.4
–0
–0.6
.4
2 –0.2
1
–0.6
–0.4
–0.2
–0.4
–0.2
0
–6 –4 –2 0 2 4 6
u
FIGURE 4.24
−i
The contour lines for Im Log w in the upper half plane.
π
166 A MATLAB® Companion to Complex Variables
Comments:
−i arg ( w − 1) i
Φ1 ( w ) = Log ( w − 1) = − Log w − 1 = φ1 ( u, v ) + iψ 1 ( u, v )
π π π
3 0.2
0.2
2
0.3
0.2
v
0.4
0.3
1
0.5
0.2
00. 4
.3
0.2
0.5
0 0 0 1 0 0
–1
–4 –3 –2 –1 0 1 2 3 4
u
FIGURE 4.25
−i i
The contour lines for Re Log (w − 1) + Log (w + 1) in the upper half plane.
π π
[u,v]=meshgrid(u,v);
w=u+i*v;
phi=−i*log(w−1)/(pi)+i*log(w+1)/(pi);
phir=real(phi);
phim=imag(phi);
[g,h]=contour (u,v,phir,[ .2 .3 .4 .5],'linewidth',2);
clabel(g,h);
xlabel('u');ylabel('v');axis equal
grid
The elements in the vector [.2 .3 .4 .5] are the numerical values chosen that
apply on each equipotential surface. They were selected after some experi-
mentation to produce a useful plot. As mentioned above, we seek values for
the elements lying on or between 0 and 1.
The contours of potential 0 and 1 were plotted separately and given extra
width. The reader should be able to supply the additional code.
The streamlines created by the complex potential Φ0(w) are plotted with a
similar code and are shown in Figure 4.26.
4
0
3 -0.1 0.1
0
2
v
-0.
0.1
1
-0.2 0.2
1
0
0.3
-0.3
–0.2
–0.1
0.2
0.1
–0.2
–0.3
0.2
0.3
–1
–4 –3 –2 –1 0 1 2 3 4
u
FIGURE 4.26
−i i
The contour lines for Im Log (w − 1) + Log (w + 1) in the upper half plane.
π π
Harmonic Functions, Conformal Mapping, and Some Applications 169
Solution:
Consider the conformal mapping w = z2 applied to the configuration
shown in Figure 4.27. This would bend the boundary into the straight line
v = 0, −∞ < u < ∞. The image of a portion of the boundary, the L-shaped
conductor maintained at 1 volt in the z plane, is now the line segment
in the w plane, v = 0, −1 < u < 1. We assign to this the same potential,
2.5
1.5 0 volt
y
0.5 1 volt
1 volt 0 volt
0
FIGURE 4.27
An electrostatic Dirichlet problem.
170 A MATLAB® Companion to Complex Variables
Φ 0 (w) = − i
(
Log z 2 − 1 ) + i Log ( z 2
+1 ) (4.37)
π π
1
φ0 =
π
( ) (
arg z 2 − 1 − arg z 2 + 1 (4.38) )
ψ 0 (w) = −
(
Log z 2 − 1 ) + Log ( z 2
+1 ) (4.39)
π π
2.5
1.5
v
0.5
–3 –2 –1 0 1 2 3
u
FIGURE 4.28
A transformation of the previous figure.
Harmonic Functions, Conformal Mapping, and Some Applications 171
2.5
2 0.1
0.1 0.1
1.5
y
0.2
0.1
0.2
0.3
1 0.3
0.1
0.2
0.6
0.5
0.9 0.1
0. 0.3
0.6
0
0.9 0.1
0 0.5 1 1.5 2 2.5 3
x
FIGURE 4.29
The equipotentials for Figure 4.27.
clf
x=linspace (0,3,100);
y=linspace (0,3,100);
[x,y]=meshgrid(x,y);
z=x+i*y;
phi=-i*log(z.^2−1)/(pi)+i*log(z.^2+1)/(pi);
phir=real(phi);
phim=imag(phi);
values=[0 .1 .2 .3 .6 .9 1];
[g,h]=contour (x,y,phir,values,'linewidth',2);
clabel(g,h);
xlabel('x');ylabel('y');axis equal
grid
We notice that the equipotential at .9 volts nearly has the same shape as
the nearby L-shaped conductor at 1 volt. Some trial and error was used
before assigning the numbers in the line of code for values, in order to
get an interesting plot. The same goes for the code used for streamlines.
We can plot the streamlines for this configuration using nearly the
same code as above. We use phim in the above code (the imaginary part
of the complex potential) to get the contour lines, which are the stream-
lines. The result is as shown in Figure 4.30.
172 A MATLAB® Companion to Complex Variables
2.5
-0 0
.1
0
–0
1.5
y
.2
–0.1
1
.6
0 0.1
–0
–0.3
–0.2 0.1
0.5 0.2
–0.1
0.6
0.1
0.2
3
0
0.
0
0 0.5 1 1.5 2 2.5 3
x
FIGURE 4.30
The streamlines for Figures 4.27 and 4.29.
We have chosen values of ψ ranging between –1 and 1 for our contour val-
ues. We used the line of code: values=[−1−.6−.3−.2−.1 0.1.2.3.6 1];.
We have added arrows to the plot, placing them on the streamlines so
that they point in the direction of the electric field (i.e., going from higher
to lower potential). There is a streamline (along y = x) that goes from the
corner (at zero potential) to infinity.
A problem like the above can sometimes be done more easily if we use
the polar coordinates r, θ, where now z = reiθ. This could be the case, for
example, if the 90° angle in Figure 4.27 was changed to some other angle,
say 45° or 60°. To work in polar coordinates, we use the following code
which is written here for the case of a 90° bend. Note the values used
for theta:
clf
r=linspace (0,3,100);
theta=linspace (0,pi/2,100);
[r,theta]=meshgrid(r,theta);
z=r.*exp(i*theta);
phi=−1i*log(z.^2−1)/(pi)+1i*log(z.^2+1)/(pi);
phir=real(phi);
phim=imag(phi);
values=[ 0 .1 .2 .3 .6 .9 1];
x=real(z);y=imag(z);
[g,h]=contour (x,y,phir,values,'linewidth',2);
clabel(g,h);
xlabel('x');ylabel('y');axis equal
grid
Solution:
The fluid cannot penetrate the walls of the channel. Hence, the veloc-
ity vector V can have no component along the normal to the walls
at any point. The velocity vector is given by V = grad ϕ, where ϕ is
the velocity potential for the fluid flow. Thus, the gradient of ϕ will
have no component normal to the walls of the closed channel. This
is ensured if the walls of the channel coincide with streamlines
because the velocity vector is tangent to the streamlines. This is
part of our boundary conditions, and because it involves the normal
component of V = grad ϕ, it is a Neumann problem. The remainder
consists of our finding a velocity potential ϕ(x, y) that will satisfy the
prescribed condition on the velocity at the center of the bottom of
the channel.
If we can find a conformal mapping that will straighten the walls of the
channel into a line in the w plane (e.g., into the real axis), we have simpli-
fied the problem. A table of conformal mappings (see, e.g., S section 8.4)
is useful in discovering this transformation. We end up employing the
following:
π π π π π
w = u + iv = sin z = sin x cosh y + i cos x sinh y (4.40)
2 2 2 2 2
0.9
0.8
0.7
0.6
0.5
y
0.4
0.3
0.2
0.1 V0
0
–0.1
–2 –1.5 –1 –0.5 0 0.5 1 1.5 2
x
FIGURE 4.31
Flow into and out of a channel.
174 A MATLAB® Companion to Complex Variables
Notice that for x = ±1, y ≥ 0, which holds for points on the left- and right-
π
hand boundaries, cos x = 0. Points here are mapped onto the part of the
2
u axis where |u|≥1. The bottom of the channel, where y = 0, −1 ≤ x ≤ 1, is
π
mapped onto the line v = 0, −1 ≤ u ≤ 1. Notice that dw/dz = cos ( πz/2 )
2
vanishes at z = ±1, which means that the transformation is not conformal
at these two points. This enables the transformation to map the U-shaped
boundary into a straight line v = 0, −∞ ≤ u ≤ ∞.
Because the boundary is a streamline in the z plane, it follows that the
u axis in the w plane must also be a streamline. The simplest nonconstant
potential, satisfying such a condition, which is analytic in the upper half
of the w plane is
2 π 2 π π π π
Φ( z) = V0 sin z = V0 sin x cosh y + i cos x sinh y (4.42)
π 2 π 2 2 2 2
From Equation 4.24 and the above, we find that the fluid velocity in
the channel is
π π π π π
Φ ′( z) = V0 cos z = V0 cos x cosh y + i sin x sinh y
2 2 2 2 2
= Vx ( x, y ) + iVy ( x, y )
clf
x=linspace (−1.1,1.1,100);
y=linspace (−.1, 3,100);
[x,y]=meshgrid(x,y);
z=x+i*y;
phi=2/pi*sin(pi/2*z);% this is the complex potential
phim=imag(phi);
values=[0 .5 1 3 5 10 15 20];
[g,h]=contour (x,y,phim,values,'linewidth',2);
clabel(g,h);
xlabel('x');ylabel('y');xlim([−2 2]);ylim=([0 3]);
axis equal
grid
Harmonic Functions, Conformal Mapping, and Some Applications 175
Comment:
The reader should note this subtlety. At the point x = 0, y = 0+, the
complex velocity vector is simply V0. The image of this point in the
w plane is w = 0. The complex fluid velocity vector in the w plane is
2
Φ ′ ( w ) = V0 . These are numerically different and illustrate a general
π
principle: Although the complex potential assumes identical numerical
values at a point in the z plane and at the image of that point in the w
plane, the same cannot be said in general for the magnitude (or direc-
tion) of the complex velocity vector at points that are images of each
dΦ
other. This is because in the w plane, we have a fluid velocity of ,
dw
while in the z plane it is
dΦ ( w ( z )) dΦ ( w ) dw
=
dz dw dz
3 20
1 0 0.5
1
15 0
53
1
15
20
2.5 15 10
5
0.5 0
10
2 5
3
3 5
1 0.5
1
0
1.5 3
y
0
0.5
1
1 1
0.5
0.5 0.5
0
0 0 0 0
0
0
FIGURE 4.32
Streamlines for flow into a closed channel.
176 A MATLAB® Companion to Complex Variables
Further Comment:
We were fortunate in doing this problem, which began in the z plane,
to find an explicit expression for w, as a function of z, that would map
our geometry in the z plane into a more tractable one in the w plane.
Sometimes we can find a function of z, call it z(w), that will change a sim-
ple geometry in the w plane into a more complicated but useful geometry
in the z plane. However, the inverse of this function w(z) may not be read-
ily available from known algebraic and transcendental functions. Such
an instance occurs in problems 5 and 6 of the exercises. However, we can
often still trace the equipotentials and streamlines in the given problem
(in the z plane) using a technique shown in problem 5 and, as shown
in problem 6, obtain the fluid velocity by using the solve command in
MATLAB to obtain numerical values of w for specified values of z.
Here the constants A and a are nonzero reals, and a is positive. We will call
A the strength of the line source. With
We have that
a
φ ( z ) = φ ( x , y ) = A log (4.44)
z − z0
ψ(z) = ψ(x,y) = −A arg(z − z0) (4.45)
Suppose the line source, in the z plane, resides near a boundary on which
the value of ϕ is specified (a Dirichlet problem) or the boundary is required
to be a streamline (a Neumann problem). Because of the presence of the
boundary, we must assume that the complex potential created by the line
source is no longer identical to what the source would create were it iso-
lated. We can sometimes solve such a problem through a conformal mapping
into the w plane where w = f(z) creates a simpler or more familiar boundary.
The line source is transformed into a line source passing through w0 = f(z0).
The strength of the line source measured by A will remain the same as in the orig-
inal problem. This is because (see W section 8.7) the change in ψ measured
along a curve in the z plane and measured along the image of that curve in
the w plane will be identical. Example 4.9 presents the technique.
Example 4.9
Consider the line charge (or “line source”) that produces the complex
1
electric potential A Log , h > 0, when the line is in an infinite uni-
z − ih
form material; we take A as positive real which means that the charge
is positive. The source passes through x = 0, y = h. The source is placed
h units above an infinite “grounded” conducting plane as shown in
Figure 4.33. The x axis is the cross section of the plane that is at the
potential (or voltage) ϕ = 0. We use Φ(x, y) to describe the actual complex
potential that now exists above the plane. The real potential ϕ(x, y) must
1.8
1.6
y
1.4
1.2
1 y = h line source
0.8
0.6
0.4 φ = 0 on y = 0
0.2
x
0
FIGURE 4.33
A line source at y = h above a grounded plane.
178 A MATLAB® Companion to Complex Variables
vanish on the plane. Find the complex potential above the plane and use
MATLAB to sketch the equipotentials and stream lines.
Solution:
Suppose we do a conformal mapping that will have the line source at
z = ih pass through the origin in the w plane. We map the infinite line
y = 0 into the unit circle in the w plane. The symmetry thus obtained is
one in which we might find a solution to the problem of finding Φ(w) in
the w plane.
Referring to the previous section on bilinear transformations, we find
that one such transformation is
z − ih
w= (4.46)
z + ih
1.5
φ=0
0.5
1 Line source
0 *
v
–0.5
–1
–1.5
–1.5 –1 –0.5 0 0.5 1 1.5
u
FIGURE 4.34
A conformal transformation of the previous figure.
Harmonic Functions, Conformal Mapping, and Some Applications 179
1 1
Φ ( w ) = A Log = A Log − iA arg ( w ) = φ(u, v) + iψ ( u, v ) (4.47)
w w
Combining the preceding with Equation 4.46, we have for the complex
potential in the z plane:
z + ih z + ih z + ih
Φ ( z ) = A Log = A Log + iA arg (4.48)
z − ih z − ih z − ih
Let us use the above to plot the equipotentials and streamlines in the
upper half space of the z plane. Below the line y = 0, there is no electric
field. The infinite grounded conducting plane prevents any penetration
into y < 0. We take A = 1, h = 1 for our plots.
Thus, the following code generates the lines of constant ϕ. We did some
experimentation to discover that values of ϕ = 0, .1, .5, 1, 2, 5
produce good plots. We have placed an o at the location of the line
source: (1,0). We present the code and results below:
clf
x=linspace (−3,3,100);
y=linspace (−.1,5,100);
[x,y]=meshgrid(x,y);
z=x+i*y;
phi=log((z+i)./(z−i));
phir=real(phi);
values=[0 .1 .5 1 2 5];
[g,h]=contour (x,y,phir,values,'linewidth',2);hold on
clabel(g,h);
xlabel('x');ylabel('y');axis equal
plot(0,1,'o')
grid
4.5
4 0.5
3.5
2.5
0.5
y
0.5
2 1
1.5 2
1
1
0.5
0.1 0.5 0.1
0.5
0.1
0 0 0 0
–3 –2 –1 0 1 2 3
x
FIGURE 4.35
The equipotentials for line source above a ground plane.
clf;
clear;
x = linspace(−3, 3, 100);
y = linspace( 0, 5, 100);
[x, y] = meshgrid(x, y);
z = x + i*y;
phi = log((z+i)./(z−i));
phim = imag(phi);
del=.05
phim(abs(x) < del & y < 1) = nan; % added this line
values = [−2 −1, −.5,−.3 0,.3, .5, 1 2];
[g,h] = contour(x,y,phim,values,'linewidth',2);
hold on
clabel(g, h);
xlabel('x');
ylabel('y');
axis equal
plot(0, 1, 'o')
grid
The line of code phim(abs(x) < del & y < 1) = nan ensures that
MATLAB does not seek to find values of ϕ, in the contour command,
Harmonic Functions, Conformal Mapping, and Some Applications 181
4.5
0
3.5
–0.3
0.3
3
2.5
y
2
–0.5 0.5
1.5
–0
0.5 0.3
.3
0
–1 1
1
–2
0.5
0
–3 –2 –1 0 1 2 3
x
FIGURE 4.36
The streamlines for a line source above a ground plane.
182 A MATLAB® Companion to Complex Variables
z+i 1 1
Φ( z) = A Log = A Log − A Log
z−i z−i z+i
It is customary to interpret this by saying that the potential cre-
ated above the grounded plane by the line source at z = i is the sum
of the potential created by the original line source, of strength A (in
the absence of the plane), plus the potential created by an image of that
source, located at z = –i, and having a strength of the opposite value,
namely, –A.
Similarly, if the line source were at z = ih, we would place its image at
z + ih
z = –ih and use the potential Φ ( z ) = A Log .
z − ih
Exercises
1. a. The space y > 0 is filled with a material that conducts heat. Let
ϕ(x, y) be the temperature in the space y ≥ 0. The boundary at y = 0
is maintained at prescribed temperatures as follows: −∞ < x < −1,
ϕ(x, 0) = 1; 1 < x < ∞, ϕ(x, 0) = −1; −1 < x < 1, ϕ(x, 0) = 0. Following an
argument like that used in solving the problem shown in Figures
4.25 and 4.26, find the complex temperature Φ(x, y) = ϕ(x, y) +
iψ(x, y) in the space y ≥ 0.
i
Hint: Try an expression of the form Φ ( x , y ) = A
Log ( w − 1) +
π
i
B Log ( w + 1) + C , where A, B, and C are real constants. Notice
π
that a constant (like C) will satisfy Laplace’s equation.
b. Write a MATLAB program that will use the above result to plot
the isotherms on which ϕ assumes the values + (0, .1, .3, .5, .7, .9).
Try plotting in the space |x| ≤ 3, 0 ≤ y ≤ 3.
c. Write a MATLAB program that will use the same result to plot
the streamlines on which ψ assumes the values given above for ϕ,
except you will probably want to leave off positive values greater
than 0.3. to prevent bunching.
2. A piece of conducting sheet metal is bent into a 60° wedge as shown
in Figure 4.37 in the w plane.
On y = 0, 0 ≤ x < 1, the electric potential is maintained at ϕ = 1 volt,
on the locus y = 3 x the potential on the metal is also at 1 volt for a
distance of up to 1 unit from the origin, while on the remainder of
Harmonic Functions, Conformal Mapping, and Some Applications 183
2.5
φ=0
2
1.5
y
φ=1
0.5
φ=1 φ=0
60⁰
0
0 0.5 1 1.5 2 2.5 3
x
FIGURE 4.37
A piece of conducting sheet metal is bent into a 60° wedge.
3.5
2.5
2
y
1.5
0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4
x
FIGURE 4.38
Fluid flow into a corner.
Hint: Find a simple mapping that will map the corner into the
real axis in the w plane with the first quadrant of the z plane
mapped onto the upper half of the w plane. Now solve the prob-
lem of flow above the streamline Im(w) = 0.
b. Find an expression for the complex velocity vector along the line
y = x, x ≥ 0.
4. A Quonset hut in the shape of a semicylindrical conducting metal
cylinder sits on top of a perfectly conducting earth. The hut is main-
tained at a potential of 1 volt, and the earth is at ground potential (zero
volts). The half cylinder has a radius of unity (in some set of units).
There is a tiny gap between the semicylinder and the ground plane
so that they can be maintained at different potentials (Figure 4.39).
a. Find an expression for the complex electric potential, in the
region Im(z) ≥ 0, |z| ≥ 1, z ≠ ±1 for this problem.
1
Hint: Consider the mapping w = ( z + 1/ z ) applied to the given
2
configuration. How is the boundary consisting of the semicircular
roof of the hut and the ground (which is y = 0, |x| > 1) mapped by
this function? Note that on the roof we can use z = eiθ, 0 < θ < π. Also,
notice that w′(z) = 0 if z = ±1. Having applied this transformation,
Harmonic Functions, Conformal Mapping, and Some Applications 185
1.5
φ=1
0.5
y
0
φ=0 φ=0
–0.5
–1
–2 –1.5 –1 –0.5 0 0.5 1 1.5 2
x
FIGURE 4.39
A metal hut on a grounded plane.
1.5
φ=1
1
0.5
y
φ=0
0
–0.5
–1
–2 –1.5 –1 –0.5 0 0.5 1 1.5 2
x
FIGURE 4.40
An infinite plate and a semi-infinite one.
1
a. Consider the transformation z =
π
( w + 1 + Log ( w )), w = u + iv
applied to the line v = 0, 0 < u < ∞ in the w plane. What is the
image of this line in the z plane?
b. Under the same transformation, find the image of the line v = 0,
−∞ < u < 0 in the z plane. Be sure to prove that the most positive
value achieved by Re(z) on the image in the z plane is 0.
c. Assigning the values 0 and 1, respectively, to the potential ϕ(u, v)
on the line segments, in the w plane, in parts (a) and (b), show that
−i
the function in the upper half space Im(w) ≥ 0 of Φ ( w ) = Log w
π
will meet the required boundary condition.
d. We cannot solve the equation given in part (a), for w as a function
of z, in terms of elementary functions. Thus, we cannot neatly
obtain Φ(w(z)) for use in the z plane. However, there is a way to
use MATLAB to display both the equipotentials and streamlines
without using the contour function in MATLAB. Suppose that
Φ0 = ϕ0 + iψ0, where ϕ0 and ψ0 are specific real values assumed
by the potential and stream functions. Show that the value
of z where this value of complex potential occurs, is given by
1 i 1
z = −ψ 0 + iφ0 + e − πψ 0 cos ( πφ0 ) + e − πψ 0 sin ( πφ0 ) + .
π π π
Harmonic Functions, Conformal Mapping, and Some Applications 187
Or,
1 πiΦ0 1
z = iΦ 0 + e + .
π π
e. We know, because of the values prescribed on the given bound-
aries, that all values of the voltage must satisfy 0 ≤ ϕ ≤ 1. Suppose
we were to choose a value for ϕ0 satisfying this inequality, say
ϕ0 = 1/2. From our expression
−i 1 i
Φ ( w ) = Log w = arg ( w ) − Log w = φ + iψ
π π π
−1
we can see that Log w = ψ can assume any real value in the w
π
plane. Thus, fixing the value for ϕ0 in our expression for z in part
(d) and allowing ψ to vary through a set of real values, we can
trace out the equipotential on which ϕ0 has the prescribed value ϕ0.
Write a MATLAB program that will plot the equipotentials on
1 1 3
which φ = 0, , , , 1 . Some experimentation might be required
4 2 4
to choose the range of values for ψ. For a start, let ψ vary between
–1 and 10. Do not make the lower limit on ψ become very nega-
tive as the expression for z in part (d) shows that the magnitude
of z becomes exponentially unbounded as ψ → −∞, which cre-
ates problems in plotting. Write your program in such a way that
each equipotential is labeled with the numerical value of ϕ on that
curve.
f. Write a MATLAB program that will generate the streamlines
for the given configuration. In electrostatics, these lines are tan-
gent to the electric field. To generate the lines, realize that on
each streamline ψ has a fixed real value (positive or negative),
while ϕ varies continuously between 0 and 1. Place arrows on the
streamlines so that they point in the direction of the electric field
(i.e., from higher to lower potential).
Suggestion: It should not be necessary to consider values of ψ
more negative than about –.5.
6. a. A Neumann problem—a continuation of problem 5 is as follows.
The transformation described in problem 5, part (a) can be used
to solve a problem arising in fluid mechanics. A fluid is guided
between two planes as shown in Figure 4.41.
The upper plane ends at x = 0, y = 1 allowing the fluid to flow
upward as well as from left to right. In the channel, on the far
left, we want the flow between the two plates to be uniform and
to the right. Thus, we say that the complex velocity between the
plates is V = 1 + i0 in the limit x → −∞, 0 < y < 1. The two planes,
the infinite one and the semi-infinite one, must coincide with
188 A MATLAB® Companion to Complex Variables
1.5
0.5
y
–0.5
–1
–2 –1.5 –1 –0.5 0 0.5 1 1.5 2
x
FIGURE 4.41
Fluid flow between two planes.
w + ih w + ih w + ih
Φ ( w ) = A Log = A Log + iA arg for Im(w) ≥ 0
w − ih w − ih w − ih
3.5 φ=0
π
3
2.5
0.5
φ=0
0
–0.5
–1
–2 –1.5 –1 –0.5 0 0.5 1 1.5 2
x
FIGURE 4.42
A line charge between two planes at zero potential.
1.5
0.5
φ=0
0 Line charge
y
–0.5
–1
–1.5
–2
–2 –1.5 –1 –0.5 0 0.5 1 1.5 2
x
FIGURE 4.43
A line charge and a half plane at zero potential.
1.5
0.5
α
0
y
–0.5
–1
–1.5
–2
–2 –1.5 –1 –0.5 0 0.5 1 1.5 2
x
FIGURE 4.44
The half plane is this wedge as α → 0+.
192 A MATLAB® Companion to Complex Variables
Hint: Do a simple transformation that will rotate the axes from
Example 4.9.
1
Log z
b. Consider the transformation w = z1/2 = e 2 applied to the
wedge shape (having angle 2α) shown in part (a). How is
the wedge mapped by this, and how is the domain outside
the wedge mapped by this transformation?
c. Combine the result above and that given in part (a) to show that
with A = 1 the complex potential for the given problem can be
z1/2 + 1
obtained by taking α → 0+ and results in Φ ( z ) = Log 1/2 .
z −1
Note for the next two parts that this function has a branch cut
along the negative real axis in the z plane because of the function
z1/2. It will also have a branch cut wherever the argument of the
z1/2 + 1
Log, namely, 1/2 , is negative real. This is where y = 0, −1 < x
z −1
< 1, which partly coincides with the first cut. In what follows, use
the NaN command for these cuts where needed.
d. Using MATLAB, plot the equipotentials for the line charge/
conducting plane configuration.
e. In the same way, plot the streamlines, adding arrows so that they
point outward from the line charge.
9. A cylinder of unit radius, whose axis passes through the origin and
is perpendicular to the z plane, is maintained at a temperature of
T°. A similar cylinder of unit radius has an axis that passes through
x = 3, y = 0 and is maintained at 0°. Our goal is to find the temper-
ature anywhere outside the cylinders and to use MATLAB to plot
the isotherms and streamlines in the material. The configuration is
presented in Figure 4.45.
a. A bilinear transformation with real coefficients must be found
that will map the circle (the cross section of the left-hand first
cylinder) into a circle of unit radius, in the w plane, where the
points z = 1 and z = –1 are mapped into w = 1 and w = –1, respec-
tively. With the same transformation, the second cylinder is
mapped into a cylinder in such a way that z = 4 is mapped into
Harmonic Functions, Conformal Mapping, and Some Applications 193
2.5
2
1.5
1
T° 0°
0.5
0
y
–0.5
–1
–1.5
–2
–2.5
–2 –1 0 1 2 3 4 5
x
FIGURE 4.45
Two cylinders at different temperatures.
5.1 Introduction
The question of where an equation like f(z) = 0 is satisfied in the complex
plane, when f(z) is an analytic function, is a major subject in complex variable
theory. This problem often arises in engineering and scientific applications.
A value of z for which the equation is satisfied is said to be a “zero” of f(z).
Similarly, we must pay attention to the related problem of where g(z) = 1/f(z)
possesses pole singularities because of the vanishing of f(z). Some of these
questions are directly resolved in MATLAB®, while others require the more
sophisticated technique called the principle of the argument.
The Nyquist stability criterion, based directly on the principle of the argu-
ment, which we discuss, is a favorite technique of engineers; it is accessed
directly in a MATLAB toolbox.
in the variable z, where a0, a1, … are constants (real and/or complex); n is a
positive integer; and an ≠ 0. We say that the polynomial is of degree n, although
some authors prefer the term order instead of degree. The theorem states that
P(z) = 0 (5.2)
195
196 A MATLAB® Companion to Complex Variables
a = [1 1 0 2 3]
>> roots(a)
ans =
0.7140 + 1.1370i
0.7140 − 1.1370i
−1.2140 + 0.4366i
−1.2140 − 0.4366i
Note the presence of the zero, the middle element, in the vector a. It arises
because there is no z2 term in the given polynomial. As the theorem pre-
dicted, we obtain four roots. Observe that because the coefficients in the
* In some texts, it is stated that the equation has one root. But the existence of the other roots
can be proven from this through a procedure of successive division of the polynomial on the
left in Equation 5.1 by (z – zj), where zj is any of the roots. See W section 4.6, problem 18.
Polynomials, Roots, the Principle of the Argument, and Nyquist Stability 197
polynomial are real, complex roots must appear in conjugate pairs as is the
case here.
We can use roots when the coefficients in the polynomial are complex. Let
us look at our first case from above: z3 + (2 − i)z2 + z(1 − 2i) − i = 0. Proceeding
as before, we have
a = [1 (2 − i) (1 – 2∗i) −i]
a = 1.0000 2.0000 − 1.0000i 1.0000 − 2.0000i 0 − 1.0000i
>> roots(a)
ans =
−0.0000 + 1.0000i
−1.0000 − 0.0000i
−1.0000 + 0.0000i
Note that −1.0000 − 0.0000i and −1.0000 + 0.0000i are numerically the same,
and so we really have only two numerically distinct roots. The root at –1 is of
multiplicity 2 and thus is printed twice. However, if you convert our above
answer to long format you will get
On the left side of the preceding, the only term not containing the vari-
able z is a0, while multiplying out the factors on the right shows that the
only term not containing z is an(–z1)(–z2) … (–zn) = an(–1)nz1z2 … zn. Thus,
a0 = (–1)n anz1z2 … zn and so
a0
(−1)n = z1 z2 ... zn (5.5)
an
This gives us a simple way to check the roots obtained for a polynomial.
The product of the roots for the polynomial on the right side of Equation 5.1 is
the ratio of the last coefficient to the first, times plus or minus one, depending
on the degree of the polynomial. We can say, for example, that the product
198 A MATLAB® Companion to Complex Variables
of the roots of the polynomial 2z3 + z2 + i is (−1)3i/2 = −i/2, which the reader
should see is the case.
Suppose we were to multiply out all the factors on the right side in Equation
5.3. The root −z1 will multiply z in each of the other terms. There are n – 1
of these terms. Thus, −z1 will appear on the right side multiplied by zn–1.
Similarly, −z2 will be multiplied by the same factor, as will the other roots.
The upshot is that the product of the terms in the parentheses on the right
side of Equation 5.3 will contain the expression (−z1 −z2 … −zn)zn–1. The vari-
able zn–1 does not appear in any other way. The right side of Equation 5.3
when expanded contains an(−z1 −z2 … −zn)zn–1 as the only term containing
zn–1. The left side contains only an–1zn–1 with this same power of z. Equating
these expressions gives us another check on the sum of the roots of the poly-
− an−1
nomial: the sum of the roots must equal . Thus,
an
The reader immediately should see that the sum of the roots of
2z3 + iz2 + 17 is –i/2, while the sum of the roots of z4 + z + i is zero because
there is no z3.
Aside from these above checks, it is interesting to verify that roots
works correctly by using it to give the roots of a large polynomial for
which the roots can be found by some other method. This is illustrated in
Example 5.1.
Example 5.1
1. Using roots, find all the roots of the polynomial 1 + z + z2 + … z9.
Use long format. Notice that there is a negative real root that is
available by inspection.
2. Using MATLAB, find the sum of the roots just obtained.
Confirm that the result is correct through the use of the coef-
ficients in the polynomial.
3. In a similar way, find the product of the roots obtained in (1),
and confirm that the sum is correct by using the coefficients in
the polynomial.
4. Check the values of your roots by using a simple formula equal
to this finite series and finding where this expression is zero.
How well do the results agree with part (1)?
Solution:
Here is the code for parts (1) through (3):
%parts 1-3
coeffs=ones(1,10);
('answer to part 1')
Polynomials, Roots, the Principle of the Argument, and Nyquist Stability 199
the_roots=roots(coeffs)
('answer to part 2')
sum(the_roots)
('this should equal ratio given in eq(5.6)')
('answer to part 3')
prod(the_roots)
('this should agree with eq(5.5)')
Comments:
It should be obvious that the given polynomial has a root at –1. Try pair-
ing the first and second terms, the third and fourth, and so on, and you
will see that they cancel at –1.
Notice that −0.999999999999999 in the vector giving the roots should
ideally have come out as –1, the value of the root.
The sum of the roots should be –a8/a9 = –1, while our result here is
–1.000000000000001, which is close.
9 a
The product of the roots should be ( −1) 0 = −1, which our program
a1
indeed produced.
Recall the finite series and its sum (see W section 5.2 and S
problem 2.41):
1 − z n+ 1
1 + z + z 2 + z 3 + ... z n = , n ≥ 0, z ≠ 1 (5.7)
1− z
The fact that we cannot use the formula on the right for z = 1
is of no consequence, because this value is clearly not a root of
the polynomial. Equation 5.7 can be verified by our multiplying
both sides by 1 – z.
200 A MATLAB® Companion to Complex Variables
The roots of the polynomial on the left must coincide with the solu-
tions of zn+1 = 1 (excluding the solution z = 1). We recall (see W section 1.4,
and S section 1.13) that roots of the preceding are given by z = ei2πk/(n+1)
k = 1, 2, … n. Notice that we do not have k = 0 here, otherwise we would
get the unwanted z = 1.
To treat the present problem, we take n = 9 in Equation 5.7 and in our
formula for z.
The numerical values of z are given by the following code and result.
We also sum these values.
k=[1:9];
format long
new_roots=exp(i*2*k*pi/10).
new_sum_roots=sum(new_roots)
The output is
for part 4
new _ roots =
0.809016994374947 + 0.587785252292473i
0.309016994374947 + 0.951056516295154i
−0.309016994374947 + 0.951056516295154i
−0.809016994374947 + 0.587785252292473i
−1.000000000000000 + 0.000000000000000i
−0.809016994374947 − 0.587785252292473i
−0.309016994374948 − 0.951056516295154i
0.309016994374947 − 0.951056516295154i
0.809016994374947 − 0.587785252292473i
new _ sum _ roots = −1.000000000000000
The above yields the required roots. Notice that if we have a polynomial in
which all or many of the coefficients are 1, we can do a similar trick: setting
the value of a by using the command ones instead of zeros. This was done
in Example 5.1.
which yields
ans = (z − 1)∗(z + 1)∗(z − 3)^2
This clearly shows roots at 1, –1, and 3, the latter being a root of multiplic-
ity 2. The terms in the polynomial do not have to be entered into factor in
descending powers of z.
Had we sought the roots of the polynomial by using roots, and if we were
working in long format, we would have obtained this less satisfactory result:
root and nk its multiplicity only when zk is rational (which of course means
it is real as well). The limitations of factor are illustrated in these examples:
>> syms z
>> factor(z^2−4)
202 A MATLAB® Companion to Complex Variables
ans = (z − 2, z + 2)
% the above is done successfully
>> factor(z^2−5)
ans = z^2 − 5
% the above factorization is not done as it would involve sqrt
(5), an irrational.
>> factor(z^2+4)
ans = z^2 + 4
he above factorization is not done because it would involve
%t
i2 which is not real and thus not rational
>> factor(z^3−z^2+4∗z−4)
ans = (z − 1, z^2 + 4)
%
the above factorization is only partially successful. The
factors involving +i2 are not present.
>> syms w z
>> w=−6∗i∗z^3+2∗z^2+1;
>> sym2poly(w)
ans = 0 − 6.0000i 2.0000 0 1.0000
Polynomials, Roots, the Principle of the Argument, and Nyquist Stability 203
We could easily now apply the command roots to the above answer and
obtain the roots of the given polynomial. Thus,
>> roots(ans)
ans =
0.0000 + 0.4587i
−0.4544 − 0.3960i
0.4544 − 0.3960i
The command poly2sym takes you from the row vector whose ele-
ments are the coefficients of a polynomial (in descending powers) to the
polynomial itself. The variable used in the polynomial (e.g., x or z) is
supplied by the user in calling poly2sym. Otherwise, x is employed by
default if you specify no variable. Here, we invoke poly2sum to recon-
struct the polynomial in z, used above, from the numerical values of the
coefficients.
Example 5.2
Consider the function
For the above fourth-degree polynomial, use MATLAB to find not only
the roots and their multiplicity but also all the derivatives of this func-
tion, up to the fifth; the last should be zero.
Verify that where this function has a root of multiplicity n at a
point, the derivatives of the function of all orders up to n – 1 are zero
there and that the function has a nonzero nth derivative at the same
point.
Solution:
syms w z
format short
a= [1 (-1) (-1+i) (1-2*i) i]
% note the use of parens in the above to avoid errors
204 A MATLAB® Companion to Complex Variables
Roots_of_poly=roots( a)
% above gives roots of given polynomial
k=1;
while k<6
('the order of the derivative')
k
a=polyder(a)
rts=roots(a)
A=poly2sym(a,z)
% the above is the polynomial in z
k=k+1;
end
This yields
.0000 + 0.0000i −1.0000 + 0.0000i −1.0000 +
a = 1
1.0000i 1.0000 − 2.0000i 0.0000 + 1.0000i
Roots_of_poly =
−1.3002 + 0.6248i
1.0000 − 0.0000i
1.0000 + 0.0000i
0.3002 − 0.6248i
ans = the order of the derivative
k = 1
a = 4
.0000 + 0.0000i −3.0000 + 0.0000i −2.0000 +
2.0000i 1.0000 − 2.0000i
rts =
−0.7699 + 0.3877i
1.0000 + 0.0000i
0.5199 − 0.3877i
A = z*(− 2 + 2*i) − 3*z^2 + 4*z^3 + 1 − 2*i
ans = the order of the derivative
k = 2
Comment:
We see that the given polynomial has roots of multiplicity 2 at z = 1,
a root of multiplicity 1 at z = –1.3002 + 0.6248i, and a root of multiplic-
ity 1 at .3002 − 0.6248i. After taking one derivative, we obtain a poly-
nomial with one root at 1, but now with roots at –0.7699 + 0.3877i and
0.5199 − 0.3877i.
Note that the new polynomial obtained by differentiating the
given one does have two roots at a location where the first one did
not. Now taking the second derivative of the original polynomial,
we obtain a polynomial with roots at 0.7562 − 0.1646i and −0.2562 +
0.1646i.
Taking the third derivative of the original polynomial, we obtain
a polynomial that has just one root: at 0.2500. The fourth deriva-
tive of our fourth-degree polynomial yields a constant, which has no
roots, while the fifth derivative (the first derivative of the constant)
is zero.
Exercises
1. Using MATLAB roots find all roots of (1 + i)z4 + 2z3 + iz2 − 3 = 0, and
verify that the number of roots is that predicted by the fundamental
theorem of algebra.
2. a. Using MATLAB roots, find all the roots of the polynomial
(1 − i)z10 + (1 + i)z9 + z + 2. Did you find 10 of them, as predicted
by the fundamental theorem of algebra?
b. Find the products of the roots in part (a), and show that they have
the value predicted by the coefficients in the given polynomial.
Use the MATLAB command prod.
c. Find the sum of the roots found in part (a), and verify that they
have the value predicted by the coefficients in the polynomial.
Use the MATLAB command sum.
3. In using roots to find the roots of a polynomial, we can be fooled
into accepting a wrong answer if we are not aware of the rounding-
off properties of MATLAB.
a. Do the following in the MATLAB “short” format. Consider
this product w = (z − a)(z − b) whose roots are obviously a
and b. Let a = 10 −6 and b = 106. Using MATLAB, create this
expression for w. Employ the command syms to make w
and z symbolic variables. Now use the command expand so
that w appears as a polynomial of degree 2 in the variable z.
Find the coefficients in the polynomial as a row vector using
206 A MATLAB® Companion to Complex Variables
1
∆ C arg f ( z) = N − P (5.8)
2π
Here P is the total number of poles of f(z) inside C, where the poles are
counted according to their order. Thus, for example, if C were a circle |z| = 4,
( z + i)( z − 5)
and f ( z) = , then N = 1 because of the zero of order 1 at –i.
z( z − i)2 ( z − 12)
Also, P = 3 because of the pole of order 2 at z = i and the pole of order 1 at
z = 0. We ignore the zero at z = 5 and the pole at z = 12 because they are both
outside the contour.
In Figure 5.1 we have sketched a hypothetical contour C in the complex z
plane.
The arrow shows the direction (positive) in which we negotiate the contour.
In Figure 5.2, we show the locus assumed by w = f(z) as we go once
along the closed contour C in the z plane. In this case, the argument of f(z)
increased by 2π = ΔC arg f(z). Notice that we encircled the origin of the w
plane exactly once in the positive sense. Thus in Figure 5.2, we show a situ-
ation in which N − P on the right in Equation 5.8 is one. This N − P is the
difference between the number of zeros and the number of poles of f(z)
within C. Observe that if f(z) had a zero on C, then the contour in Figure 5.2
would have passed through w = 0. And if f(z) had a pole on C, then the con-
tour in this same figure would have passed through infinity and could not
be drawn on the page.
* Recall that if an analytic function has a zero of order n at z 0, then it can be expressed as
f(z) = (z − z0)n ϕ(z) in a neighborhood of z0, where ϕ(z0) ≠ 0 and ϕ(z) is analytic at z0.
Polynomials, Roots, the Principle of the Argument, and Nyquist Stability 209
2.5
2
The contour C
1.5
0.5
z plane
0
–0.5
–1
–1.5
–2
0 1 2 3 4
FIGURE 5.1
A hypothetical simple closed contour.
1.5
0.5
arg f(z)
0 0
w plane
–0.5
–1
–1.5
–2
–1.5 –1 –0.5 0 0.5 1 1.5 2 2.5
FIGURE 5.2
The image of the preceding contour under the transformation w = f(z).
210 A MATLAB® Companion to Complex Variables
E = N − P (5.9)
Example 5.3
Part (a)
We know from the fundamental theorem of algebra that the polynomial
f(z) = z4 + iz3 + 4 + i has four roots. Using roots from MATLAB, we could
of course figure out where they are. Use the principle of the argument to
see how many roots lie inside the circle |z| = 3/2, and check your result
by using roots and establishing how far the roots are from the origin in
the z plane.
15
10
5
arg f(z)
0 0
–5
–10 w plane
–15
–10 –5 0 5 10 15 20
FIGURE 5.3
A contour going around the origin twice.
Polynomials, Roots, the Principle of the Argument, and Nyquist Stability 211
Solution:
Consider the following code:
theta=linspace(0,2*pi,1000);
%above establishes angles on a circle
z=3/2*exp(i*theta);
%above,are the points on a circle, radius 3/2,center origin
w=z.^4+i*z.^3+4+i;
plot(w)
coeffs=[1 i 0 0 (4+i)]
%above are coeffs of the polynomial we are given
the_roots=roots(coeffs)
abs_values=abs(the_roots)
Whose output is
coeffs = 1.0000 0 + 1.0000i 0 0 4.0000 + 1.0000i
the_roots =
1.0011 − 1.2337i
−0.8829 − 1.3673i
0.9136 + 0.8635i
−1.0318 + 0.7375i
abs_values =
1.5888
1.6276
1.2571
1.2683
10
0 0
–2
–4
–6
–8
–4 –2 0 2 4 6 8 10 12 14
FIGURE 5.4
3
Locus of f(z) = z4 + iz3 + 4 + i as it moves once around the circle z = .
2
212 A MATLAB® Companion to Complex Variables
Part (b)
Using the principle of the argument, determine how many roots the
function in part (a) has in the domain |z − 1 −i| < 1.
Solution:
We can use the same code as was employed in part (a) but replace
z=3/2*exp(i*theta); with z=1+i+exp(i*theta);. This generates a
circle having center at z = 1 + i and radius 1. This is the boundary of the
given domain.
The locus generated in the w plane as we negotiate this circle while
evaluating f(z) is shown in Figure 5.5.
30
20
10
O
0
–10
–20
–30
–40
–50 –40 –30 –20 –10 0 10 20
FIGURE 5.5
Locus of f(z) for the contour |z–1–i| = 1.
Polynomials, Roots, the Principle of the Argument, and Nyquist Stability 213
Notice that we have encircled the origin of the w plane exactly once,
which indicates that f(z) = z4 + iz3 + 4 + i has exactly one root in the
domain |z − 1 − i| < 1. This is confirmed if we look at the list of roots of
the polynomial:
1.0011 − 1.2337i
−0.8829 − 1.3673i
0.9136 + 0.8635i
−1.0318 + 0.7375i
If you were to plot these in the complex plane, you would quickly see
that only 0.9136 + 0.8635i lies inside the given domain |z − 1 −i| < 1.
Let us now turn to a problem where the function studied has both zeros
sin πz
and poles. We look at f ( z) = . Notice that this function has a pole of
z3
order 2 at the origin. This is because the denominator has a zero of order
3 at z = 0, and the numerator has a zero of order 1 at the same point (see W
section 6.2). The order of the pole is the difference of these orders. In gen-
eral, sin πz has zeros of order 1 when z lies at any integer except zero, which
means that f(z) has zeros of order 1 at the same locations. Let us plot the locus
1
roceeds in the positive sense around the circle z − = 1. Notice
of f(z) as z p
2
that this circle will enclose the pole of order 2 at the origin and the zero of
order 1 at z = 1. No other zeros or poles of f(z) are enveloped. Thus, according
to Equations 5.8 and 5.9, if we plot w = f(z) as the circle is negotiated, then we
should go once around the origin in the w plane in the negative (clockwise)
sense. Here is the code and the output that confirms this (Figure 5.6):
theta=linspace(0,2*pi,1000);
%above establishes angle on a circle
z=.5+1*exp(i*theta);
%above, the points on a circle, radius 1, center .5
w=sin(pi*z)./z.^3;
plot(w);grid;hold on
w1=w(500)
w2=w(501)
The output is
w1 = 7.9987 + 0.1509i
w2 = 7.9987 − 0.1509i
Note that the contour approaches the origin but does not pass through
it. The arrow was assigned by our studying the results for w(500) and
w(501). The plot moves from having a positive imaginary part to a negative
one. We do, as expected, go once around the point w = 0 in the clockwise
direction.
At this point, the reader may be wondering if the principle of the argu-
ment is useful. So far we have used it to confirm that it establishes the zeros
214 A MATLAB® Companion to Complex Variables
10
0 0
–2
–4
–6
–8
–10
–12 –10 –8 –6 –4 –2 0 2 4 6 8
FIGURE 5.6
1
Image of z – = 1 under the given transformation.
2
and poles of functions whose zeros and poles were at known locations. But
consider the following situation. Suppose we want to find solutions of the
equation sin z = e−z. We might proceed with MATLAB as follows:
%solution of exp(-z)=sinz
syms z
solve(exp(-z)==sin(z))
The output is
ans = 0.5885327439818610774324520457029
The above result is entirely plausible. To realize this, we create the plots of
sin z and e−z, where z = x is real (Figure 5.7).
There is no point in making a plot for x < 0 as the exponential is greater
than one here while sinx ≤ 1. The intersection of the curves near the value
obtained through solve (approximately .588) should be evident. Notice too
that the curves will have an infinite number of intersections that grow
asymptotically closer to nπ, where n is positive integer, increasing without
bound. Thus, solve has found us just one of an infinite number of real solu-
tions. As for complex solutions, we still do not have a clue.
Our solution using solve employed the symbolic math toolbox in
MATLAB. This in turn is based on the software called MuPAD, which
went into use in September 2008. Before that, MATLAB used the MAPLE
software in its toolbox. If you use a version of MATLAB marketed before
the above date, you will obtain a different solution to this equation,
Polynomials, Roots, the Principle of the Argument, and Nyquist Stability 215
0.8
0.6
sinx
0.4
sin(x) and exp(–x)
0.2
–0.2
–0.4
exp(–x)
–0.6
–0.8
–1
0 2 4 6 8 10 12 14
x
FIGURE 5.7
Plots of sin x and e–x.
* See, for example, B. Hunt, R. Lipsman, and J. Rosenberg. A Guide to MATLAB for Beginners and
Experienced Users, 2nd ed. (Cambridge, 2007): 21. This book gave me the idea of discussing
this equation.
216 A MATLAB® Companion to Complex Variables
We supply the program with the center z0 and the radius r of a circle. The
code generates a plot of the locus of sin(z) − exp(−z) as the circle is negotiated.
Trying a circle of radius 1 with center at −5+5∗i, we find that the origin in the
w plane is enclosed. Shrinking the radius to one half, we find that the origin
is not enclosed. Trying a circle at −5.5+5.5∗i, with radius 1, in the z plane,
we again encircle the origin, and we also encircle the origin if the radius is
reduced to .5. You may wish to study this figure using the “zoom in” feature
of the MATLAB figure tools to make sure that the origin is indeed encircled.
To locate the root, we use the MATLAB command vpasolve that allows us to
make an initial guess for our solution. In this way, we know that we will get
a solution near where we are expecting one. The function vpasolve employs
the Newton–Raphson method and does occasionally fail—it might produce
a root but one that is not the closest one to our initial guess. An advantage
that vpasolve has over solve is that the latter does not permit an initial guess
as to the location of the solution, and it might produce a solution that is not
near to the one you are hunting for. If you want vpasolve to look for complex
solutions, begin by providing it with a complex value to begin hunting for
solutions. Here is the code for our present problem. The reader may wish to
read the MATLAB documentation for vpasolve.
syms z
vpasolve(exp(-z)==sin(z),z,-5+5*i)
Whose output is
ans =
−5
.1512194593898245955379661256296 +
5.8443612804879991094759668093818*i
This result is not far from the guess made available by the principle of the
argument.
For many or perhaps most purposes, it is more convenient to seek roots
inside a domain whose boundary is a rectangle with sides parallel to the x–y
axes. One reason is that we are seeking solutions in a Cartesian system, so it is
natural to use a Cartesian-type contour. The other, equally important, is that
the rectangular boundary has 90° corners, and we are interested in seeing
how these corners will be mapped. The following code can be used to enter a
rectangular contour bounding our domain. We supply the coordinates of the
center as well as the width and height of the rectangle. The values of z in the
row vector are such that we negotiate the contour in the positive direction. We
have chosen to try out our program by plotting the locus of w = sin z − sinh z
as z negotiates a rectangle, a square in this case, with center at the origin. The
rectangle has a width and height of 2. Here are the code and the results:
wdth=input('width of rectangle')
x1
=linspace(-wdth/2,wdth/2,1000);
x2=linspace (wdth/2,-wdth/2,1000);
y1=linspace(-ht/2,ht/2,1000); y2=linspace(ht/2,-ht/2,1000);
%t
he preceding places 1000 points on the 4 sides of
rectangle
zbot=x1-i*ht/2;%z on bottom side of rectangle;
ztop=x2+i*ht/2;%z on top of rectangle
zrt= wdth/2+i*y1;%z on right side of rectangle
zlft=-wdth/2+i*y2;%z on left side of rectangle.
[zbot zrt ztop zlft]+cntr+i*cnti;%this centers the rectangle
z=
%where desired
%enter the function w(z) below
w=sin(z)-sinh(z);
plot(w,'linewidth',2);grid;hold on
plot(0,0,'*')
0.8
0.6
0.4
0.2
–0.2
–0.4
–0.6
–0.8
–0.8 –0.6 –0.4 –0.2 0 0.2 0.4 0.6 0.8
FIGURE 5.8
Locus of sin z – sinh z as z negotiates a square of side length z with center at z = 0.
218 A MATLAB® Companion to Complex Variables
series, we would find that the leading term (try this) is −2z3/3! Thus, there
is a zero of order 3 at the origin, and this accounts for the three zeros of w(z)
which were found inside the given contour. Of course, this function might
have had other zeros in the contour, but our procedure shows that there are
no others. Notice here the four cusps in the curve where the locus suddenly
changes direction by 90°. These arise from the four corners of the square that
we are mapping using this analytic function. The angles of the square are
preserved because this is a conformal transformation.
Suppose we apply the above program to the function w(z) = (sin z − sinh z)2,
using the same square in the z plane. We would expect the locus of f(z) to encir-
cle the origin of the w plane six times. This is because the leading term in the
Maclaurin expansion of the new w(z) would be (−2z3/3!)2 = 4z6/(3!)2.
However, we obtain the plot as shown in Figure 5.9.
There is something puzzling about this result: We expected to find six
encirclements of the origin, but the figure shows only three. Another puz-
zling feature, which is a clue to explaining our result, is that the plot exhibits
only two corners of 90° and not the expected four.
Notice that w = f(z) = (sin z − sinh z)2 is an even function of z (it is the square
of an odd function). For every point on the square contour (in the z plane)
we employed, there is another point on the contour that is its negative. Both
these points are mapped into the same point in the w plane by the given
function. Thus, if we proceed just halfway around the given square, we gen-
erate the entire curve shown in Figure 5.9. Proceeding the rest of the way
0.8
0.6
0.4
0.2
–0.2
–0.4
–0.6
–0.8
–1
–0.4 –0.3 –0.2 –0.1 0 0.1 0.2 0.3 0.4
FIGURE 5.9
The locus of (sin z – sinh z)2 as z negotiates the square being discussed.
Polynomials, Roots, the Principle of the Argument, and Nyquist Stability 219
x1=linspace(-wdth/2,wdth/2,4);x2=linspace(wdth/2,-wdth/2,4);
y1=linspace(-ht/2,ht/2,4); y2=linspace(ht/2,-ht/2,4);
zbot=x1-i*ht/2;%z on bottom side of rectangle;
ztop=x2+i*ht/2;%z on top of rectangle
zrt= wdth/2+i*y1;%z on right side of rectangle
zlft=-wdth/2+i*y2;%z on left side of rectangle.
z=[zbot zrt ztop zlft]+cntr+i*cnti;
w=(sin(z)-sinh(z)).^2;
('z and w')
disp([z.' w.'])
Adding this code shows in the program’s output that every value of w that
we generate is encountered twice. Thus, we negotiate the curve shown in the
preceding figure twice.
Suppose we had to investigate the locus of (sin z − sinh z)2 as z proceeds
around a rectangle whose center is displaced from the origin. Then it would
no longer be true that for every point on this rectangle, there is a point on
the rectangle that is its negative. Thus, the locus traced in the w plane would
not, unlike the preceding case, be covered twice. This matter is investigated
in problem 3.
Example 5.4
Show that the function w(z) = z4 + z3 + i has four zeros inside |z| = 1.5 and
no zeros inside |z| = .8.
Solution:
Let us first take f(z) = z 4 and g(z) = z3 + i. We take the contour C as
the circle |z| = 1.5. On this contour, |f(z)| = (1.5)4 = 5.0625. Also,
|g(z)| = |z3 + i| ≤ |z3| + |i| = |(1.5)3| + |i| = 3.375 + 1 = 4.375, from
which we see that indeed |f(z)| > |g(z)| on the contour. It follows that
the number of zeros of z 4 inside the contour must be the same as the
number of zeros of z 4 + z3 + i. It is obvious that z4 has four zeros, all at
the origin. From this, it follows that z4 + z3 + i has four zeros inside the
contour |z| = 1.5. Of course, the locations of the zeros are different in
these two cases.
The preceding should give an indication of how to prove the
Fundamental Theorem of Algebra. We must argue that the polynomial
anzn + an−1zn−1 + … a0 has n roots in the complex plane. We take f(z) = anzn
and g(z) = an−1zn−1 + … a0. We then choose a circle, |z| = r centered at the
origin, whose radius is sufficiently large that |anzn| > |an−1zn−1 + … a0|.
One can always find such a circle—the reader should convince herself of
this. The number of roots f(z) inside the circle is obviously n. Invoking
Rouché’s theorem, we proved the theorem.
To return to the problem, we now take g(z) = z4 + z3 and f(z) = i. On the
contour |z| = .8 we have |g(z)| ≤ |z|3 + |z|4 = .83 + .84 = 0.9216. On the
same contour, we have |f(z)| = |i| = 1. Thus, it is clear that on the contour
we have |g(z)| < |f(z)|. This tells us that f(z) + g(z) = z4 + z3 + i has the
same number of zeros inside |z| = .8 as does the number i. Thus, there
are no zeros. We can confirm all of the above by applying the function
roots to the polynomial z4 + z3 + i. We have the following:
The absolute values of all four roots exceed .8 and are less than 1.5, as
predicted.
Polynomials, Roots, the Principle of the Argument, and Nyquist Stability 221
Exercises
z3 + 1
1. a. Consider w( z) = . Identify the zeros and poles of this func-
z
tion, and give the orders of each.
b. Using MATLAB plot the locus of w(z) as z negotiates the circle
|z| = .9 once in the counterclockwise direction. Explain how
your result confirms the principle of the argument by referring
to part (a). Put an arrow on your locus to show the direction in
which it is negotiated.
c. Repeat part (b) but use as your locus |z| = 1.2.
2. a. Consider the function w(z) = z3, which obviously has a zero of
order 3 at the origin. Using MATLAB plot the locus assumed by
w(z) as z goes once around the circle |z| = 1. Notice that this
locus apparently encircles the origin in the w plane just once,
but the principle of the argument would suggest three encircle-
ments. Explain this apparent contradiction.
b. Repeat part (a) but use the circle |z − 1| = 3/2. Observe that your
locus does indeed encircle the origin three times as expected.
Explain why this differs from the result in part (a).
c. Repeat part (c) but use as your locus in the z plane the square
centered at the origin with sides parallel to the x and y axes. Each
side has length one. Did you get three encirclements?
3. Plot the locus of f(z) = (sin z − sinh z)2 as z goes, in the positive sense,
along the boundary of a domain bounded by a square. The length of
each side is 2. The sides are parallel to the x–y axes. The center of the
square is at x = .1, y = .1. How does your result confirm the conclusion
obtained from a Maclaurin expansion that f(z) has a zero of order 6
at z = 0, and how does it show that there are no other zeros for this
function in this domain? How many right angles are in your locus?
Explain why?
4. a. Using the principle of the argument and a MATLAB plot, show
that the equation sin(ez) = ez has no solution in the z plane inside
the domain |x| < 1/2, |y| < 1/2.
b. Repeat the above problem and show that there is no solution
inside the domain |x| < 1, |y| < 1. You will have to use the zoom
in feature of MATLAB to see that your locus does not encircle
the origin.
c. Use vpasolve to try to find a solution near the upper-right-hand
corner of the square domain (i.e., in the vicinity of x = 1, y = 1). Is
your solution outside the square, as it should be?
222 A MATLAB® Companion to Complex Variables
Log(1 + z)
5. a. Where are the zeros and poles of w = f ( z) = ? Give the
z2
location and the order. Note that this is the principal branch of
the logarithm.
b. Using MATLAB, plot the locus of this function as z goes around
the circle |z|= .9 in the positive sense. Be sure to place an arrow
on the plot showing the direction in which it is negotiated.
Explain how the number of encirclements of the origin confirms
the principle of the argument.
Log(1 + z)
c. The function w = f ( z) = has a removable singularity at
z
z = 0. How should this function be defined at this point if the
function is to be analytic in a neighborhood of the origin?
d. Repeat part (b) for the function given in (c). Discuss the number
of encirclements of the origin.
e. The function w = f(z) = Log z has a zero of order 1 at z = 1. Yet a
plot generated by evaluating f(z) as z proceeds once around the
circle |z|= 2 will show no encirclements of the origin in the w
plane. Try this. Why is there no encirclement?
6. a. Using the principle of the argument, show that the equation
sin(i cos(z)) = ez has just one root inside the square domain
−1 < x < 1, −1 < y < 1.
b. Does this root lie in the left half of this domain, the right half,
or on the imaginary axis? Answer using the principle of the
argument.
c. Using solve or vpasolve, find the location of this root. You may
have to experiment to find the root we are seeking. Did you find
other roots?
7. a. Show that on the circle |z|= 1.5 |z4| > |ez|.
b. From the above, state how many solutions the equation z4 + ez
has inside this circle. How many roots does z4 − ez have inside the
same circle?
c. Plot the locus of z4 + ez as z goes around the given circle.
Also plot z4 − ez. How do your results confirm your findings of
part b?
d. A plot of z4 as z goes around the circle once seems to show a
single encirclement of the origin. Does this contradict what you
have found in part (b)?
e. Using solve, find four solutions of z4 + ez = 0 inside the given cir-
cle. Note that solve yields solutions in terms of the lambert func-
tion. To get numerical (decimal) expressions from these results,
apply the MATLAB command eval to the results containing the
Polynomials, Roots, the Principle of the Argument, and Nyquist Stability 223
5.4 Nyquist Plots, the Location of Roots, and the Pole-Zero Map
A useful special case of the principle of the argument deals with the count-
ing of the number of zeros and poles of an analytic function in a half plane
(e.g., the right half of the z plane, the left half of the same plane, or the top or
224 A MATLAB® Companion to Complex Variables
bottom halves). Let us focus on the right half of the z plane, as this is of most
interest in engineering applications.
Suppose we have a polynomial of the form
15
y=R
10
5
R
x=R
0
–5
–10
y = –R z plane
–15
–5 0 5 10 15
FIGURE 5.10
Semicircle with diameter on the imaginary axis and center at the origin.
Polynomials, Roots, the Principle of the Argument, and Nyquist Stability 225
then when we pass through these roots, the locus would go through the
origin in the w plane. The above, with some modification shown later, is
the essence of the Nyquist method, a technique for finding the number of
roots of a function in the right half plane (RHP). We could, of course, use
a similar technique to find the number of roots in the left half plane or the
upper or lower half planes.
It is an interesting little exercise to see how large we must take R in order
for there to be no roots of w(z) in the RHP outside the semicircle. Suppose
we write
where P(z) = anzn and Q(z) = an−1zn−1 + an−2zn−2 + … a0. Note that where w(z) = 0,
then
nA
R> (5.13)
an
|z| ≥ R, and |z| ≥ 1, then |P(z)| > |Q(z)|, and Equation (5.12) is not satisfied,
which means that w(z) = anzn + an−1zn−1 + … a0 ≠ 0 for |z| ≥ R.
If the right side of Equation 5.13 is less than or equal to one, it is not hard to
show that w(z) has no roots outside |z| = 1.
Let us verify the above by establishing the number of roots of w(z) = 9z5 +
z + 2 in the right half of the z plane. Of course, the MATLAB function roots
4
will do this immediately, but this little exercise will lead us into the kind of
thinking involved in the Nyquist plot. From Equation 5.13, we see that the
radius of the circle used must exceed (5 × 2)/9 = 1.111 …. We choose R = 1.2.
There are advantages to making R not much bigger than we have to. If
R greatly exceeds its minimum value, then from Equation 5.10, we have
(approximately) on the semicircular portion of the contour, which is of
radius R, that w(z) ≈ anR neinθ, where θ = arg(z). Thus, the mapping of this
226 A MATLAB® Companion to Complex Variables
semicircle into the w plane will result in an arc of large radius anRn, which
might cause portions of the rest of the locus in the w plane to appear very
close to w = 0. The shape of this locus might not be discernible.
The following code generates the locus describing our polynomial w(z) as
z negotiates the closed semicircle of Figure 5.10 in the positive (counterclock-
wise) sense.
R=1.2;
y=linspace(R,-R,1000);
theta=linspace(-pi/2,pi/2,1000);
z1=i*y;%gives points on the diameter
z2=R*exp(i*theta);%gives points on the arc
w1=9*z1.^5+z1.^4+2;% the function at points on the diameter
w2=9*z2.^5+z2.^4+2;%the function at points on the arc
u1=real(w1);v1=imag(w1);u2=real(w2);v2=imag(w2);
plot(u1,v1);hold;
plot(u2,v2); grid;axis equal
plot(0,0,'o');%puts a o at the origin
roots([9 1 0 0 0 2])
%the above tells us where the roots are
ans =
−0.7639 + 0.0000i
−0.2513 + 0.7027i
−0.2513 − 0.7027i
0.5777 + 0.4344i
0.5777 − 0.4344i
20
15
10
5
10
15
20
–20 10 0 10 20 30
FIGURE 5.11
Locus of w(z) = 9z5 + z4 + 2 as the semicircle in the z plane is negotiated in the z plane.
where T(s) is a rational function of s, with real coefficients, and is often mul-
tiplied by an exponential function of s. In an elementary form, it is express-
ible as
Example 5.5
Obtain a Nyquist plot to determine the number of roots in the RHP of
−6(2 s 2 + s + 1) − sτ
F( s) = 1 + e
s3 + 5s2 + 9s + 5
where τ = .01.
Solution:
We use the following code:
−6(2 s 2 + s + 1) − sτ
F( s) = e , τ = .01
s3 + 5s2 + 9s + 5
we can conclude that
2 s2 + s + 1
F( s) = 1 − 6 e − sτ , τ = .01
s + 5s2 + 9s + 5
3
has three zeros in the right half of the s plane. Engineers would say
that this transfer function describes an unstable system. This expres-
sion for F(s) as may be verified has no poles in the RHP. We apply the
MATLAB function roots to the denominator of the preceding fraction to
establish this. In this example, the resulting Nyquist plot does not pass
through –1, confirming that there are no zeros of F(s) on the imaginary
axis in the s plane.
2 s2 + s + 1
F( s) = 1 + 6 e − sτ
s + 5s2 + 9s + 5
3
230 A MATLAB® Companion to Complex Variables
Nyquist diagram
1.5
0.5
–1
Imaginary axis
–0.5
–1
–1.5
–3 –2.5 –2 –1.5 –1 –0.5 0 0.5
Real axis
FIGURE 5.12
Nyquist plot for Example 5.5.
with the same value of τ as before, it is found that the resulting Nyquist plot
does not encircle the origin. There are no zeros of F(s) in the right half of the
s plane. The reader should verify this.
clear; clf
s = tf('s');
tau=.01;
transfer_func=1-6*(2*s^2+s +1)/(s^3+5*s^2+9*s+5)*exp(-tau*s)
pzmap(transfer_func)
Polynomials, Roots, the Principle of the Argument, and Nyquist Stability 231
Pole–zero map
1.5
1
Imaginary axis (seconds–1)
0.5
–0.5
–1
–1.5
–3 –2 –1 0 1 2 3 4 5 6 7
Real axis (seconds–1)
2 s2 + s + 1
F( s) = 1 − 6 e − sτ
s3 + 5s2 + 9s + 5
with the given τ has three zeros in the RHP. All three poles are in the left
half plane.
while the former function merely establishes the number of poles in the RHP
of a narrower class of functions.
To answer this question, we must see how Nyquist diagrams are used in
an electrical laboratory. Recall that the variable s is σ + iω. We can some-
times make a series of electrical measurements on an electrical system by
measuring T(s) (see Equations 5.14 and 5.15) while varying ω from 0 to such
a large positive value that T(s) becomes essentially constant. This constant is
lim T ( s) in the RHP. While making these measurements, we keep σ = 0. The
s →∞
results are typically complex numbers. Because the coefficients in the poly-
nomials in Equation 5.15 are real numbers, it follows that T ( s) = T ( s). With
s = iω, this means T (iω ) = T (− iω ). Thus, if we measure the complex values of T
for positive ω and take their conjugates, it follows that we have the values for
negative ω. For example, if T measured at ω = 1000 is 3+i4, then T measured
at ω = −1000 would be 3−i4.
Shown below is a hypothetical set of measurements for ω ≥ 0. We have dis-
played the data points, with a small o, and connected them with a smooth
curve. We have also plotted with a broken curve the conjugate of the curve for
positive ω. Thus, we have a hypothetical Nyquist plot. In this case, we see that
our plot encloses the point –1+i0 two times as we proceed along the ω axis from
−∞ to ∞. There are two zeros of 1 + T(s) in the right half of the complex plane.
Notice that Nyquist plots made from experimental data do not use the
function nyquist but just the plot function.
2.5
1.5
1 w= 0
w = 100,000
0.5
–1
w= 5
0
w = 5,000
–0.5
–1
–1.5
–2
w = .5
–2.5
–2 –1.5 –1 –0.5 0 0.5 1 1.5 2 2.5
Exercises
1. a. Explain why all roots of the polynomial 3z4 + z3 + 1 must lie inside
any circle in the complex plane, centered at the origin, whose
radius R exceeds 4/3.
b. How many of the roots lie in the RHP? Answer this not by finding
the roots but by moving along a contour, like that in Figure 5.11,
and plotting the results. Make a suitable choice of radius for the
semicircle. How does your contour show that the polynomial has
no roots on the imaginary axis?
c. Check your answer by using the MATLAB function roots.
2. a. Use the command Nyquist to determine if
( s2 + 1)e − s/10
F( s) = 1 + 20
s5 + 10 s 4 + 40 s3 + 80 s2 + 80 s + 33
has any zeros in the right half of the s plane or on the imaginary
axis.
b. Make a pole–zero map for the above function, and see whether it
confirms your answer.
3. a. Consider the function
β( s2 + 1)e − s/10
F( s) = 1 + 20
s5 + 10 s 4 + 40 s3 + 80 s2 + 80 s + 33
where β is a real number that can be positive or negative. Study
the Nyquist plot obtained in the preceding problem (which is
this problem except that in problem 2 we have β = 1), and use that
result to estimate (approximately) the smallest value for |β| that
will result in the function having at least one zero in the right half
of the s plane. Prove your result by generating a Nyquist plot
with this value of β, which you should have found is <0.
b. Confirm the result of part (a) by means of a pole–zero map of the
given function where you employ the value of β found above.
c. For the value of β that you selected, use the function fzero to find
the numerical value of s in the right half of the s plane that causes
the function F(s) to have a zero in that plane. The pzmap can help
you to choose where to search in the plane.
4. a. Suppose in Equation 5.14 that we have
−β
T ( s) =
( s + 1)(1 + e −1 e − s )
where β is a positive real number.
234 A MATLAB® Companion to Complex Variables
6.1 Introduction
Anyone working in engineering or the physical sciences will know some
of the transformations named in this chapter’s title. Laplace and Fourier
transforms are much used in electric circuit theory, electromagnetic theory
(including optics), and signal processing. The Z transformation has in the
past two generations proved a major tool in the field of digital signal pro-
cessing, while the Hilbert transform is useful in subjects as diverse as the
modulation of radio signals as well as the analysis of brain waves. Because
of the similarity of Laplace and Fourier transforms, we treat them first and
begin with the easier of the two, Laplace.
Lf (t) =
∫ f (t)e
0
− st
dt (6.1)
The order of taking the two limits on the right should be immaterial if the
definition is to be valid. Note the lower limit is achieved by our letting ε shrink
toward zero through negative values. For functions that are continuous at t = 0,
235
236 A MATLAB® Companion to Complex Variables
this subtlety can be ignored. Otherwise it should be observed. Note that some
textbooks use a lower limit in which ε shrinks toward zero through positive
values, and this can cause different results when we are transforming func-
tions that are discontinuous at the origin. The convention we use here is con-
sistent with MATLAB®. In general, we should think of s as a complex variable:
Le − bt
=
∫e
0
− st − bt
e dt
>> syms b t
>> laplace (exp(−b∗t))
ans = 1/(b + s)
L
e − ( s+b ) L − e − ( s+b ) ε e − (α+σ )L e − i(β+ω )L − 1
Le − at
= Llim lim
∫
→∞ ε→ 0 −
ε
e − bt e − st dt = lim lim
L→∞ ε→0− ( −b − s )
= lim
L→∞ − (b + s)
Transforms: Laplace, Fourier, Z, and Hilbert 237
Studying the expression on the above right, we see that the limit exists
only if α + σ > 0 or Re(s) > −Re(b). Thus, the result obtained by MATLAB
is valid only to the right of a vertical line in the complex s plane. Here, as is
typically the case, the Laplace transform is an analytic function of s. Thus,
one must be cautious in using the laplace operation in MATLAB.
The function 1/(b + s) is the Laplace transform of e−bt only in the domain of
the s plane where Re(s) > −Re(b). However, we see that this function, 1/(b + s),
is defined and analytic in any domain in the s plane from which the point
s = −b is excluded. The function 1/(b + s) evaluated anywhere in such a domain
where Re(s) > −Re(b) is not satisfied is said to be the analytic continuation of the
Laplace transform of e−bt. Usually we are not aware of this subtlety and say
simply that 1/(b + s) is the Laplace transform of e−bt and use it, except at s = −b,
in the s plane. Such analytic continuations will occur for other Laplace trans-
forms and are especially useful when we are inverting Laplace transforms
(recovering f(t)) by means of residues as described below. See W section 5.7
and S section 10.1 for more information on analytic continuation.
There is a sufficient condition that can guarantee that F(s) = Lf(t) is analytic
in a half plane to the right of a vertical line in the complex s plane. Briefly
stated, assuming that the integral in Equation 6.2 exists for some values of s
and that there exist real constants k, p, and T such that
then it can be shown* that the function F(s) is analytic in the half space
Re(s) > p.
Let us use MATLAB to find the Laplace transform of cos(bt), where
b = α + iβ is complex. We proceed as follows:
>> syms b t
>> laplace(cos(b∗t))
ans = s/(b^2 + s^2)
cos ( bt ) =
1 i(α+ iβ )t
2
(
e ) 1
2
(
+ e − i(α+ iβ )t = e −βt e iαt + eβt e − iαt )
* See, for example, R.V. Churchill. Operational Mathematics, 3rd ed. (McGraw-Hill, New York,
1971).
238 A MATLAB® Companion to Complex Variables
>> syms n s t
>> laplace( t^(1/n))
ans = piecewise([−1 < real(1/n), gamma(1/n + 1)/s^(1/n + 1)])
The gamma in the preceding refers to the Γ function that you may wish
to review (see W section 6.11 and S section 10.8). Recall that it is defined by
∞
Γ(w ) =
∫e
0
−t w−1
t dt
>> laplace(cosh(sqrt(t)))
ans = laplace(cosh(t^(1/2)), t, s)
Consider
>> syms s x t
>> laplace (cos(x+1/t))
ans = laplace(cos(x + 1/t), t, s)
Notice that MATLAB returns the question to us. It is unable to do the inte-
gration on the variable t. We wanted the integration done on the variable x.
We proceed as follows:
>> syms s x t
>> laplace (cos(x+1/t),x,s)
ans = −(sin(1/t) − s∗cos(1/t))/(s^2 + 1)
MATLAB obtains the relatively simple answer. The characters x,s in the
laplace command instruct MATLAB to do the integration in Equation 6.1 on
the variable x, not t, and to produce a function of s.
Our result is
π
F( s) =
( s − 1)1/2
How do we define this function in the complex s plane? Notice that the
given function of t, namely, e t/ t , can be made to satisfy Equation 6.4 if we
take p = 1 and k > 1 and T = 1. Thus, we are guaranteed that this Laplace
transform is analytic in the half plane Re(s) > 1. We may use any branch cut
of (s − 1)1/2 in the complex s plane that originates at s = 1, extends to infinity,
and does not pass into the domain Re(s) > 1. We might have guessed this,
because we know that if the Laplace transform exists, it must be analytic in
a domain to the right of a vertical line in the complex s plane. We can choose
any vertical line to the right of s = 1 and achieve this.
To establish a branch of a multivalued function, we require not only a
branch cut (or cuts) but also the numerical value of the function at one point.
240 A MATLAB® Companion to Complex Variables
u(t) = heaviside(t)
The plot shown in Figure 6.1 should make clear where the language “unit
step” comes from. The function u(t − τ) or heaviside (t − τ) (here τ is real) would
just be a step like the one shown in Figure 6.1 but with the discontinuous rise
displaced τ units to the right if τ > 0. Here we obtain the Laplace transform
of the Heaviside function with MATLAB:
>> syms s t
>> laplace (heaviside(t))
ans = 1/s
>> syms s t t1
>> assume(t1>0)
>> laplace (heaviside(t−t1))
ans = exp(−s∗t1)/s
Transforms: Laplace, Fourier, Z, and Hilbert 241
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
–2 –1.5 –1 –0.5 0 0.5 1 1.5 2
t
FIGURE 6.1
Heaviside function for −2 < t < 2.
Notice that the line of code assume(t1>0) establishes that t1 is positive and
that it is real. Without such an assume statement, MATLAB cannot evaluate
the Laplace transform if t1 is a symbol whose numerical value has not been
specified. If you used assume(t1<0), the answer would be 1/s, and t1 would
not appear. You should explain to yourself why this is true. In the preced-
ing work, you may use any real number instead of t1. But MATLAB will not
evaluate the Laplace transform of heaviside(t−i) because of the presence of
the non-real i. Verify this.
Studying Figure 6.1, we would expect that the derivative of the function
heaviside(t) might be thought of as infinite at t = 0 and zero for all t ≠ 0. A rig-
orous treatment, using the usual definition of the derivative as the limit of a
difference quotient, would show that this function has no derivative at t = 0.*
However, we nevertheless use the following:
d(heaviside(t))
dirac(t) =
dt
* A branch of advanced calculus called generalized functions permits the repeated differentia-
tion of the Heaviside function.
242 A MATLAB® Companion to Complex Variables
The function on the left, the Dirac delta function, is often written as δ(t) and
is nonzero only at t = 0 and is to be thought of loosely as “positive infinity”
at t = 0. Thus, we have also
δ(t) = dirac(t)
du(t) d
δ(t) = = heaviside(t)
dt dt
The integral of this expression must yield the Heaviside function. Thus,
t t
∫
L
δ(t ′) dt ′ = u(t) or
∫ dirac(t′) dt′ = heaviside(t)
L
L < 0 and t > L
>> syms b t
>> diff(heaviside(t−b))
ans = dirac(b − t)
>> int(dirac(t))
ans = heaviside(t)
Note that dirac(b − t)=dirac(t−b) as the dirac function is an even function of its
argument. Observe also that the operator diff treats t as the variable for which
differentiation is to take place. MATLAB assumes that you do not wish to dif-
ferentiate with respect to b and takes t as the default variable for differentiation.
A useful result is called the sampling property of the dirac delta function:
∞
∫ dirac(t − τ) f (t)dt = f (τ) (6.5)
−∞
The integral returns the value (or sample) of the function f(t) at t = τ. This
is sometimes known also as the sifting property as it sifts through possible
values of the function and supplies one. We assume that f(t) is continuous at
t = τ. Because the dirac function is zero except where its argument is zero,
the preceding equation is still valid if −∞ is replaced by the symbol b, and ∞
is replaced by the symbol c, provided b < τ < c.
Because of the sampling property, we have that
L
You should see that if τ is negative real, then the Laplace transform is zero.
Here is the same result from MATLAB where we use t1 instead of τ.
>> syms s t t1
>> laplace (dirac (t−t1))
ans = piecewise([t1 < 0, 0], [0 <= t1, exp(−s∗t1)])
1.8
1.6
1.4
1.2
0.8
0.6
0.4
0.2
0
0 1 2 3 4 5 6
t
FIGURE 6.2
Plot of f(t) = heaviside(t − 1) − heaviside(t − 4).
244 A MATLAB® Companion to Complex Variables
>> syms s t t1 t2
>> t1=1;t2=4;
>> laplace(heaviside(t−t1) − heaviside(t−t2))
ans = exp(−s)/s − exp(−4∗s)/s
use
∫ f (t′) dt′ in place of f(t).
0
cos at
If we know the Laplace transform of the function f (t) = − , then it
a
should be easy to find the Laplace transform of the function which is its first
derivative: f′(t) = sin(at).
− cos at
From Equation 6.6, we have L sin( at) = sL − (−1/a). From MATLAB,
a
we obtain
>> syms s a t
>> s∗laplace (−cos(a∗t)/a) − (− 1/a)
ans = 1/a − s^2/(a∗(a^2 + s^2))
>> simplify (ans)
Transforms: Laplace, Fourier, Z, and Hilbert 245
Note the agreement between the two ways of getting the Laplace trans-
form of sin(at).
The derivative of the Heaviside function is the Dirac function. Thus,
the Laplace transform of the Dirac function should be obtained if we use
MATLAB to obtain the Laplace transform of the Heaviside function, multi-
ply this result by s, and from this subtract the value of the Heaviside function
at 0− (this value is zero). We verify this as follows:
>> syms s t
>> s∗laplace (heaviside(t))
ans = 1
>> syms t
>> diff(heaviside(t))
ans = dirac(t)
>> diff(sign(t))
ans = 2∗dirac(t)
The Dirac function has, if we permit ourselves the use of generalized func-
tions, a first derivative. Generalized functions include the Dirac function
and/or any of its derivatives. In the language of MATLAB, we have that
d
dirac(t) = dirac(t , 1), where the notation dirac(t,1) means simply the first
dt
derivative of the Dirac function. MATLAB can handle higher-order deriva-
tives of the Dirac function and uses dirac(t,n) to mean the nth derivative of
dirac(t). If the number n is left unspecified, it is taken as zero—no derivative
is taken. Just as the function dirac(t − τ), where τ is real, samples the value of a
function that is continuous at τ when we do an integration (see Equation 6.5),
the function dirac(t−τ, 1) will sample the negative of the first derivative of a
function with a continuous first derivative. Thus,
∞
∫ dirac(t − τ, 1) f (t)dt = − f ′(τ) (6.9)
−∞
246 A MATLAB® Companion to Complex Variables
Thus, the nth derivative of the Dirac function, δ(n)(t − τ), samples the nth
derivative of the function f(t) and multiplies it by either 1 or –1.
for all |s| > R0 in this half plane.* Under these conditions, the function f(t), for
t > 0, can be obtained by a contour integral along an infinite vertical line in
the complex s plane as follows:
a + i∞
1
−1
f (t) = L F( s) =
2 πi ∫ F(s)e
a − i∞
st
ds (6.12)
The integration is done along the line Re(s) = a or along any other contour
into which this line can legitimately be deformed without affecting the value
of the integral. The preceding is known as the Bromwich integral and is per-
formed along a straight infinite vertical line like that shown in Figure 6.3.
The line is called the Bromwich contour. If we perform the integra-
tion for t < 0, it can be shown that the function of t obtained is zero.
1
* The reader might wish to verify that the function F( s) = will satisfy the preceding if we
s+1
were to take m = 1, k = 1, a = 0, and R0 as any positive number.
Transforms: Laplace, Fourier, Z, and Hilbert 247
Original
contour
Singularities
of F(s)
a σ
A valid
alternative
contour
FIGURE 6.3
A Bromwich contour and its valid deformation.
f(t) = the sum of the residues of F(s)est at all poles of F(s) (6.13)
If there are branch cut singularities of F(s) lying to the left of the vertical
line, the method cannot be used.
1
Let us see how this applies to the function F( s) = 2 . Notice that this
s ( s + 1)
function is analytic in a half plane Re(s) ≥ a, where a > 0. Also, in this half
1 1 1
plane |s| < |s + 1|, which means that in this same space ≤ 2 = 3.
s2 ( s + 1) s s s
Thus, we may employ the Bromwich integral to find the inverse transform.
248 A MATLAB® Companion to Complex Variables
1 1 1 2
= 2 ≤ 2 = 3 if s > 2 .
s2 ( s + 1) s s+1 s s /2 s
The conditions for using Equation 6.13 are satisfied, and we assert that
1 e st e st
L−1 = Res @ s = 0 + Res @ s = −1
s 2 ( s + 1) s 2 ( s + 1) s 2 ( s + 1)
d s2 e st
lim = t − 1.
s → 0 ds s 2 ( s + 1)
( s + 1) e st
lim 2 = e − t.
s →−1 s ( s + 1)
>> syms s t
>> ilaplace (1/(s^2∗(s+1)))
ans = t + exp(−t) – 1
1
The function F( s) = , where b is a constant and the function is
( s − b)1/2
defined by the principal branch, cannot be found from Equation 6.13 because
of the presence of branch point singularities to the left of the Bromwich con-
tour. Yet in all three cases just cited, MATLAB will yield the inverse Laplace
transform. Here is one example:
>> syms s b t
>> ilaplace (1/(s−b)^(1/2))
ans = exp(b∗t)/(pi^(1/2)∗t^(1/2))
1
The result is that the inverse Laplace transform of F( s) = is
( s − b)1/2
e bt
f (t) = . Notice that MATLAB recognizes that s is the variable and b the
πt 1/2
constant in the expression that it is asked to invert. It always takes s as the
default variable in these situations unless instructed otherwise. The branch
of (s − b)1/2 is assumed to be the principal one, and in general ilaplace uses the
principal branch of F(s). The square root of t in the preceding answer should
be interpreted as the principal value.
The preceding inverse transform can be found by analytic means (see W
section 7.1). Some idea of the method is outlined in problem 6 where b = –1.
In the present release of MATLAB (R2015a) that the author is using, there
are some quirks that perhaps will be ironed out in future versions. For exam-
ple, consider this operation:
>> syms s t
>> ilaplace (1)
whose output is
Undefined function ‘ilaplace’ for input arguments of type ‘double’.
>> ilaplace(sym(‘1’))
ans = dirac(t)
>> syms s t
>> ilaplace (s/s)
ans = dirac(t)
>> syms s t a
>> assume(a>0)
>> laplace (exp(−a∗t^2))
ans = (pi^(1/2)∗exp(s^2/(4∗a))∗erfc(s/(2∗a^(1/2))))/(2∗a^(1/2))
Our result is
π s2 /(4 a ) s
e erfc
2 a 2 a
Example 6.1
Solve the equation.
t
d2 f
dt 2
+
∫ f (τ) dτ = e sin t (6.14)
0
t
Solution:
Recalling that the Laplace transform is a linear operator, we take the
Laplace transform of the left-hand side of the above equation by add-
ing together the Laplace transform of each of the two terms on the left.
Transforms: Laplace, Fourier, Z, and Hilbert 251
We have with the aid of Equation 6.7 and 6.8 that the Laplace t ransform
of the left side of Equation 6.14 is s2 F(s) + F(s)/s. The Laplace transform
of the right side is best obtained from MATLAB, as follows:
>> syms s t
>> laplace (exp(t)∗sin(t))
ans = 1/((s − 1)^2 + 1)
Thus, equating the Laplace transform of the right- and left-hand sides
of Equation 6.14, we have
1
s 2 F( s) + F( s)/ s =
( s − 1)2 + 1
which yields
1 1
F( s) =
( s − 1)2 + 1 s 2 + 1/ s
2 t/2 3 e −t 3 t 1
f (t) = e cos t − − e cos t − sin t
3 2 15 5 3
Of course, there are other more direct ways to solve equations like the one
just treated by using MATLAB. Differentiating both sides of Equation 6.14
results in a differential equation that can be solved with the MATLAB func-
tion dsolve, but this topic takes us far from complex variable theory.
Exercises
1. By evaluating the Bromwich integral with the method of residues,
find the inverse Laplace transform of the following functions and
compare your results with those obtained by MATLAB.
1
a. F( s) = 2
( s − 1)
1
b. F( s) =
( s − 1)2 + 1
1 1
c. F( s) = 2 +
s +s+1 s+1
252 A MATLAB® Companion to Complex Variables
2. a. Suppose a function f(t) has Laplace transform F(s). Show that the
Laplace transform of the function f(t − τ)u(t − τ) is e−sτ F(s), where
τ is a nonnegative real.
Hint: Write the Laplace transform of f(t − τ)u(t − τ) as an integral,
and make a simple change of variable. Our result is known as
a translation theorem. The inverse transform of e−sτ F(s) is thus the
inverse transform of F(s) shifted τ units to the right on the t axis
and multiplied by u(t − τ). The latter ensures that the resulting
function is zero for t − τ. Thus, L −1e−sτ F(s) = u(t − τ)f(t − τ), where
f(t) = L −1F(s).
e st
b. Find the residue of the function at its pole and use that
( s − 1)2
result together with Equation 6.13 as well as the result derived in
e −2 s
part (a) to find the inverse Laplace transform of .
( s − 1)2
c. Check the result by using MATLAB to find the inverse transform
e −2 s
of F( s) = .
( s − 1)2
3. This problem explores some peculiarities of MATLAB in its han-
dling of inverse Laplace transforms.
a. Using ilaplace, find the inverse Laplace transform of the func-
s+1
tion .
s
b. Verify that you get the same result by applying ilaplace to the
1
function 1 + .
s
c. Since the inverse Laplace transformation is a linear operation,
1
you should get the same result by using ilaplace(1) + ilaplace .
s
Try this. You will see that there is a difficulty. This arises because
the operation ilaplace expects a symbolic function in its
argument.
d. Show that you can resolve this difficulty by first stating
one=sym(‘1’) in your code. This establishes that one is now a
symbol equal to unity. Now try taking the sum ilaplace(one) +
1
ilaplace and show that you get an inverse Laplace transform
s
s+1
of .
s
s 1
Also try taking the sum ilaplace + ilaplace and verify
s s
that this works, too.
Transforms: Laplace, Fourier, Z, and Hilbert 253
1
4. a. Consider the Laplace transform F( s) = . The principal
( s + 1)1/2
2
1 e st
2 πi ∫ ( s + 1)1/2
ds
3 R
0 –1 0
–1
–2 Radius ε
–3
–4
–5
–6 –4 –2 0 2
FIGURE 6.4
Contour for Part (c).
Transforms: Laplace, Fourier, Z, and Hilbert 255
q q
∫ u(θ) dθ ≤ ∫ u(θ) dθ
p p
if q > p
π
1 e st 1 R
∫ ∫e Rt cos θ
1/2 ds ≤ dθ
2 πi ( s − 1) 2 π R−1
π/2
Hint: Make the change of variable s = Reiθ for the integral on this
iθ
arc, where π/2 ≤ θ ≤ π. Find e t Re .
e. Observe that, by making a sketch, for π/2 ≤ θ ≤ π, we have the
inequality 1 − 2θ/π ≥ cosθ. Thus, show that
π
1 e st 1 R
∫ ∫e Rt (1− 2 θ/π )
1/2 ds ≤ dθ
2 πi ( s − 1) 2 π R−1
π/2
1 e st 1
2 πi ∫ ( s − 1) 1/2 ds ≤
4t R − 1
e − Rt − e −2 Rt
Argue that for t > 0, we must have that the integral on the left
goes to zero as R tends to infinity.
If we perform this integration along the arc in the third quad-
rant, we will again get zero, in this same limit, because the inte-
grand assumes the conjugate of the values it assumed in the
second quadrant at conjugate points on the two arcs.
256 A MATLAB® Companion to Complex Variables
2 πi ∫ ( s + 1)1/2
ds
which arise, respectively, from integrations along the top and bot-
tom of the branch cut in the above figure in the limits. Combine
these integrals and make the change of variable x′ = −x to show
that
∞
1 1 e − x ′t
L−1
( s + 1)1/2
=
π ∫ x′ − 1
dx ′
1
Investigate this for your version. Now show how to get the Laplace
transform of this function by using MATLAB to obtain the Laplace
2 − t2
transform of the function e and then employing Equation 6.8.
π
It is helpful in this problem to treat π as a symbol using the statement
syms pi. In this way, the program will not reduce the square root of
π to a number. Notice that your answers will be in terms of the com-
plimentary error function: erfc(t) = 1−erf(t).
Transforms: Laplace, Fourier, Z, and Hilbert 257
Ff (t) = F(w) =
∫ f (t)e
−∞
− iwt
dt (6.15)
integral
∫ f (t) dt exist and that discontinuities of the function f(t), if any, be
−∞
limited to a finite number of jump discontinuities in any finite interval on the
t axis. In reality, the engineer or scientist very often deals with functions that
do not satisfy this necessary condition but whose transforms do in fact exist.
A simple function sin t is such an example.
The function f(t) can be recovered from F(ω), and we write F −1 F(w) = f (t).
The procedure requires an integral:
∞
1
−1
f (t) = F F(w) =
2π ∫ F(w)e
−∞
iwt
dw (6.16)
The integration is done along the real axis in the complex w plane, and we
employ the analytic continuation of F(ω) as mentioned above. Like the inver-
sion formula for the Laplace transform, this formula comes with a caveat: If
f(t) has a jump discontinuity at a point, say t0, then the integral on the right
1
yields f (t0 ) = f (t0 +) + f (t0 −) , the average of the values assumed by f(t) on
2
each side of the jump.
The reader should note that there are a variety of ways in which to con-
sistently define the Fourier transform and its inverse. We have used the one
1
employed by MATLAB. In other definitions, is swapped from the right
2π
side of Equation 6.16 to the right side of Equation 6.15. This is the procedure in
W (pages 405–411). Sometimes the minus sign is swapped from the exponent
in the integral Equation 6.15 to the exponent in the integral in Equation 6.16.
Note that in the Wikipedia tables of Fourier transforms, three different
258 A MATLAB® Companion to Complex Variables
∫ ...(dt or dw) = lim ∫ ...(dt or dw).
−∞
R →∞
−R
The limits move out from the origin symmetrically. If f(t) has a singularity at
the real value t0, then we must perform our integration as follows:
t0 −ε R
lim lim
R →∞ ε→ 0 +
−R
∫ − iwt
f (t)e dt +
t0 +ε
∫
f (t)e − iwt dt
df d2 f dn f
= iwF(w), F 2 = ( iw ) F(w) ... F n = ( iw ) F(w) (6.17)
2 n
Ff (t) = F(w), F
dt dt dt
t
F(w)
F
∫ f (τ)dτ =
−∞
iw
+ F(w)δ(w) (6.18)
The first group, Equation 6.17, can be derived formally if we permit our-
selves to differentiate both sides of Equation 6.16 with respect to the variable
t and bring the derivative under the integral sign.
Transforms: Laplace, Fourier, Z, and Hilbert 259
Equation 6.18 can be derived from the properties of the convolution inte-
gral described below. It is especially helpful if we are seeking the Fourier
transform of a function such that we can readily transform its derivative.
A similar procedure was used for Laplace transforms.
These formulas in Equations 6.17 and 6.18 are useful for converting dif-
ferential/integral equations in the variable t to algebraic equations in the
variable w. These equations involve the unknown F(w), and the technique is
similar to that employed for Laplace transforms.
It is instructive for us to perform a Fourier transformation using the calcu-
lus of residues and verify these results with MATLAB. Here is an example.
Example 6.2
1
Using complex variable theory, find F 2 and check your result by
using MATLAB. t +1
Solution:
From Equation 6.15, we must evaluate
∞
1 − iwt
F (w ) =
∫t 2
+1
e dt
−∞
2
t plane
1
0 R
–1
R
–2
–3
Pole at –i
–4
–5
–6
–7
–6 –4 –2 0 2 4 6
FIGURE 6.5
Contour for Example 1.
260 A MATLAB® Companion to Complex Variables
Note the presence of the minus sign in front of 2πi, which arises
because the pole is enclosed in the negative (clockwise) direction. The
preceding result holds when w is a nonnegative real. We can write
∞ ∞ ∞
1 − iwt 1 1
F (w ) =
∫ t2 + 1
e dt =
∫ t2 + 1
cos wt dt − i
∫t 2
+1
sin wt dt
−∞ −∞ −∞
where we have employed Euler’s identity for the exponential. The sec-
ond of these integrals is zero as it represents the integral of an odd
function between symmetrical (even) limits. The first integral on the
∞
1
right,
∫
−∞
t2 + 1
cos wt dt , where w is real, is unaffected by a change in the
where w is real.
Let us verify the preceding result with the use of MATLAB. To take
a Fourier transform of a function of t, we use the command fourier.
This yields, unless MATLAB is instructed otherwise, a function of the
variable w. To recover the function of t from the function of w we use the
command ifourier. MATLAB will return, unless told otherwise, a func-
tion of the variable x. Because we are often solving problems involving
time, or t, we may wish to have a function of t. This is accomplished as
shown below.
>> syms w t
>> fourier (1/(t^2+1))
ans = pi∗exp(−w)∗heaviside(w) + pi∗heaviside(−w)∗exp(w)
Transforms: Laplace, Fourier, Z, and Hilbert 261
∞
1
=
2π ∫ πe −w
(cos wt)dw
−∞
∫
= Re e − w(1− it ) dw
0
>> syms t x
>> fourier(1/(t^2+x))
ans = −pi∗exp(t^2∗w∗i)∗i − pi∗exp(t^2∗w∗i)∗sign(imag(t^2))∗i + pi∗heaviside(−w)
∗exp(t^2∗w∗i)∗2∗i
>> syms t x
>> fourier(1/(t^2+x),t,w)
(pi∗exp(−w∗x^(1/2))∗heaviside(w))/x^(1/2) + (pi∗heaviside(−w)∗exp(w∗x^(1/2)))/
x^(1/2)
Fδ(t) =
∫ δ(t)e
−∞
− iwt
dt = 1 = F(ω ) (6.20)
Now suppose we wish to recover our function of t, namely, δ(t), from F(ω).
Employing Equation 6.16, we have
∞ ∞ ∞
1 1 i
f (t) = F −1 (1) =
2π ∫ e iwt dw =
2π ∫ cos wtdw +
2π ∫ sin wtdw
−∞ −∞ −∞
1 R i
R
2 sin Rt
lim
f (t) = lim
R →∞ 2 π
−R
∫cos wtdw +
2π
−R
∫
sin wtdw =
2 π R →∞ t
Transforms: Laplace, Fourier, Z, and Hilbert 263
R
i
We have used the fact that the second integral above,
2π
−R
∫
sin wtdw, which
>> syms t
>> ifourier(1,t)
ans = dirac(t)
The delta function has been recovered. To deal with this contradiction, we
might simply postulate that because the Fourier transform of δ(t) is 1, then
by definition the inverse Fourier transform of 1 must be δ(t). In other words,
we dispense with the integral definition of the inverse transform. Sometimes
we will be forced to do this—a widespread practice in engineering but one
generally abhorrent to mathematicians.*
Here is a further example: The reader should verify with Equation 6.15 that
the Fourier transform of δ(t − τ) is e−iwτ, where τ is a real number. The reader
should also verify that the inverse transformation of e−iwτ cannot be obtained
through the use of Equation 6.16 as the integral does not exist. We have, how-
ever, from MATLAB:
The assume statement above tells MATLAB that tau is real. This is a pre-
caution. In the present version that we are using (R2015a), MATLAB assumes
as a default that the argument of the Dirac function is real.
The reader might find it helpful to memorize not only that Fδ(t − t0 ) =
−1 e iω 0t
e − iωt0 (which includes that Fδ(t) = 1), but also F δ(w − w0 ) = which means
1 2π
that F −1δ(w) = .
2π
Sometimes we can be surprised, in the subject of Fourier transforms,
when comparing results obtained from calculus with the results produced
* A presentation of a rigorous treatment of such practices can be found in the book by Hans
Bremermann, Distributions, Complex Variables, and Fourier Transforms. (Reading, MA: Addison
Wesley, 1965).
264 A MATLAB® Companion to Complex Variables
by MATLAB. For example, let us look at the transform of f(t) = 1/(t − 1)2. The
definition of Fourier transforms requires that we do this integration:
∞ − iwt
e
∫ (t − 1)2
dt
−∞
−∞
1−τ
and assume that cos wt > 0 in the interval of integration. If cos wt > m > 0,
we have
1+τ 1+τ
cos wt m
∫ (t − 1)2
dt >
∫ (t − 1) dt
2
1−τ 1−τ
If we attempt the second integral, we find the result is infinite. Thus, the
integral on the left of the inequality cannot exist and, therefore, neither does
the Fourier transform we are seeking. Note that it does not exist as a Cauchy
principal value either. However, consider this from MATLAB:
>> syms t
>> fourier(1/(t−1)^2)
ans = −pi∗w∗exp(−w∗i) + 2∗pi∗w∗heaviside(−w)∗exp(−w∗i)
>> simplify (ans)
ans = −pi∗w∗exp(−w∗i)∗(2∗heaviside(w) − 1)
1
According to MATLAB, the function has the Fourier transform
(t − 1)2
1
F
( − ) 2 = −πwe
− iw
( 2u( w ) − 1)
t 1
How can we explain this? Notice that the Fourier transform of the function
1 e − iwt
g(t) = does exist as a Cauchy principal value. The expression has
(t − 1) (t − 1)
an integrable singularity at t = 1.
Transforms: Laplace, Fourier, Z, and Hilbert 265
∞ − iwt
e
∫
−∞
(t − 1)
dt
1 e − iwt
F = −πi Res @ t = 1 = −πie − iw
t − 1 t−1
2
t plane
1
0 1
0 R
–1
Radius ε
–2 R
–3
–4
–5
–6
–7
–6 –4 –2 0 2 4 6
FIGURE 6.6
An indented contour for this problem.
266 A MATLAB® Companion to Complex Variables
1
F = −πie − iw (2 u(w) − 1)
t − 1
We have used the Heaviside function to bring about the required change
in sign. Multiplying the preceding by −iw, we obtain −πwe−iw(2u(w)−1), which
1
is indeed the result that will be produced by MATLAB for F . The pre-
(t − 1)2
ceding is also verified with MATLAB as follows:
>> syms w t
>> a1=fourier(1/(t−1))
a1 = pi∗exp(−w∗i)∗(2∗heaviside(−w) − 1)∗i
% the above is the Fourier transform of the given function.
>> a2=−i∗w∗a1
a2 = pi∗w∗exp(−w∗i)∗(2∗heaviside(−w) − 1)
% the above is –iw times times the transform of 1/(t−1)
>> a3=fourier(1/(t−1)^2)
a3 = −pi∗w∗exp(−w∗i) + 2∗pi∗w∗heaviside(−w)∗exp(−w∗i)
% the above is the transform of 1/(t−1)^2
>> a2−a3
ans = pi∗w∗exp(−w∗i) + pi∗w∗exp(−w∗i)∗(2∗heaviside(−w) − 1)
− 2∗pi∗w∗heaviside(−w)∗exp(−w∗i)
>> simplify(ans)
ans = 0
% the preceding shows that the Fourier transform of 1/(t−1)^2 is identical to –iw
%times the transform of 1/(t−1)
∞
1
L heaviside(t) =
∫e
0
− st
dt =
s
Transforms: Laplace, Fourier, Z, and Hilbert 267
∞
i
F heaviside(t) =
∫e − iwt
dt = πδ(w) −
w
0
>> syms t
>> laplace(heaviside(t))
ans = 1/s
>> fourier(heaviside(t))
ans = pi∗dirac(w) − i/w
If we replace s in the first result with iw, we do not get the second result—
the Fourier transform. Simply put, the function obtained from the first inte-
gral is not defined at s = 0, so the variable change w = −is, when applied to
this function, is not valid at w = 0, which is exactly where the two transforms
disagree. In general, if a result obtained from a Laplace transform is used
to obtain a Fourier transform by the substitution s = iw, then we should, if
possible, perform the inverse transform on the Fourier result, as a check,
using the command ifourier. The same applies when going from Fourier to
Laplace transforms.
f (t) ⊗ g(t) =
∫ f (t − τ)g(τ) dτ (6.21)
−∞
This definition is consistent with the one used in the previous section.
This is because if we agree to employ functions f(t) and g(t) that are 0 for
t < 0, as we did in dealing with Laplace transforms, then the lower and
upper integration limits in Equation 6.21 can be replaced by 0 and t, respec-
tively. It can be shown that the Fourier transform of the convolution of two
functions is the product of the Fourier transform of each. Conversely (and less
frequently used), it can be shown that if H(w) is a Fourier transform obtained
by the convolution of the functions F(w) and G(w), then the inverse Fourier
transform of H(w) is f(t)g(t), where f(t) and g(t) are the inverse transforms
268 A MATLAB® Companion to Complex Variables
of F(w) and G(w), respectively. Let us try out Equation 6.21 with MATLAB.
1 1
We take f (t) = 2 and g(t) = 2 . We use MATLAB to form the convolu-
t +1 t +9
tion of these functions, and take the Fourier transform of this result, using
MATLAB. Then we use MATLAB to find the Fourier transform of f(t) and
g(t) and show that the product of these results is the Fourier transform of
the convolution of f(t) with g(t).
Here is the MATLAB code:
syms t tau
assume(t,'real')
assume(tau,'real')
%f(t)=1/(t^2+1)and g(t)=1/(t^2+9)our funcs of t.
ftau=1/((tau)^2+1);
gtau=1/((t-tau)^2+9);
h=ftau*gtau;
the_conv=int(h,tau, -inf,inf)
% the above is the convolution of two functions
syms w
assume(w,'real')
Fourier_of_conv=fourier(the_conv,t,w)
%t
he above is the Fourier transform the convolution of the two
%functions
F=fourier(ftau,tau,w)
G=fourier(1/(t^2+9),t,w)
prod_transforms=simplify(F*G)
%t
he above is the product of the Fourier transforms of each
%function
check_me=prod_transforms-Fourier_of_conv
%
the above should work out to zero, it checks to see that the
%product
%of the transforms is the transform of their convolution.
whose output is
Exercises
1. a. Using MATLAB, find the Fourier transform of the function
t
f (t) = 2 , where a is assumed to be a positive real. Be sure
t + a2
to use the statement assume (a > 0) in your code. Use the sim-
plify statement to get your final result. Now check your work
by using the statement ifourier on the transform, and verify that
you recover the given f(t). Explain why the Fourier transform of
your f(t) must be a pure imaginary odd function.
b. Find the Fourier transform requested above by using residue
calculus. Consider w positive and also negative.
sin( at)
2. a. Repeat problem 1, parts (a) and (b), but take as f (t) = and
t
a is again real. Explain why the Fourier transform of f(t) must be
an even function of w.
b. Taking a = 1, use MATLAB to plot F(w) for –5 < w < 5.
3. a. Using the definition of the inverse Fourier transform (Equation 6.16),
find the inverse transform of δ(w − w0), where w0 is a real ≥ 0. Give
your result as a function of t, not x (the default). Repeat this for
the function δ(w + w0). Check these results using MATLAB and
the function ifourier.
b. Using the above results for the inverse Fourier transform, state
the Fourier transform of the function sin(w0t).
Hint: Write this as the sum of two exponentials. Now check this
result by applying the operation fourier to this function.
c. Find the Fourier transform of cos(w0t) from the transform for
sin(w0t), which you found in part (a), by using the second entry
in Equation 6.17. Check your result by using MATLAB to find the
Fourier transform of cos(w0t).
4. Assuming that the convolution property for Fourier transforms,
following Equation 6.21, is true, use it to prove Equation 6.18.
Hint: Let f(t − τ) = heaviside(t − τ). Simplify the integral in
Equation 6.21 for the Heaviside function in the integrand and find
the Fourier transform of heaviside(t − τ).
5. a. The present release of MATLAB, R2015 a, will not produce the
Fourier transform of the function arctan(t). Verify that this is
so in the version that you are using. If indeed your MATLAB
will compute the transform of this function, take note of the
result as it will confirm the calculations to be made in what
follows.
270 A MATLAB® Companion to Complex Variables
Proceed as follows:
a. Take the Fourier transform of both sides, recognizing that the left
side is a convolution, and obtain an algebraic equation in F(w).
b. Solve this equation for F(w).
c. Using MATLAB, obtain the inverse Fourier transform of F(w),
thus solving the problem. Simplify your answer and show that it
is real, as it must be, as the equation that it satisfies involves real
functions of a real variable.
Transforms: Laplace, Fourier, Z, and Hilbert 271
Equation 6.22 says, with slight rearrangement, that the value of f(n + 1) is 2
added to f(n). Thus, if we take as a “boundary condition” that f(0) = 1, then it
is apparent that f(1) = 3, f(2) = 5 … or f(n) = 2n + 1.
Equation 6.23 says that each term in the sequence f(0), f(1), … is twice the
one before it. Taking the zeroth (n = 0) term as 1, you quickly see that the
nth term is f(n) = 2n. Equation 6.24 says that each term is the sum of the two
preceding ones—that is, f(n + 2) = f(n + 1) + f(n); this is the basis of the famous
Fibonacci sequence that often appears in biology and population growth.
By definition, Fibonacci numbers assume that f(0) = 0, f(1) = 1, which would
mean that f(2) = 1, f(3) = 2, f(4) = 3, f(5) = 5, ….
In Equation 6.25, we have that the n + 1 element, f(n + 1) is n + 1 times the
preceding element. Taking f(0) = 1, you quickly discover that f(n) = n!.
Except for Equation 6.24, the problem of finding the nth term was quite
simple. The method of Z transforms provides us with a systematic way
of solving equations such as these, especially, as in Equation 6.24, where
the answer is not readily apparent. Notice that in all these equations f(n),
f(n + 1), … appear only to the first power and that these functions are not
multiplied together as, for example, f(n + 1) f(n − 1). This is why we say that
we are dealing with linear difference equations.
272 A MATLAB® Companion to Complex Variables
In the sequence f(0), f(1), f(2), …, the first element is of course f(0), and the
second is f(1), and so on. But we also refer to the zeroth element, the first
element, and so on, in correspondence with the number n. The usage should
be clear from the context.
Sometimes one is concerned not with f(n) but with f(nT), where T is a posi-
tive real number that represents a time interval from which samples of a
time-varying function f(t) are collected.
Expressions involving f(nT) instead of f(n) frequently appear in
the field of digital signal processing. Such an expression might be
1 1
f (( n + 2 ) T ) = f (( n + 1) T ) + f ( nT ), which would indicate that each new
2 2
value of the sample is the average of the preceding two samples.
Figure 6.7 illustrates a signal from which values f(T), f(2T), f(3T), f(4T), have
been sampled.
MATLAB is set up so as to assume that T = 1, and we follow that convention.
A Z transformation creates an analytic function of the complex variable z
by first forming a Laurent series in the variable z whose coefficients are found
from f(0), f(1), … f(n), …. The series contains no values of z raised to positive
powers. The closed-form expression for the sum of this series, an analytic
function, is said to be the Z transform of the sequence. (See W section 5.8.)
Here is the form of the series:
0.35
0.3
f(T) f(2T )
0.25
f(3T )
0.2
f(t)
0.15 f(4T )
0.1
0.05
T 2T 3T 4T
0
t
FIGURE 6.7
Sampling a signal or function at intervals of length T.
Transforms: Laplace, Fourier, Z, and Hilbert 273
or equivalently,
1 z 1 1 1
= = 1+ + 2 + 3 + … z >1
1 z−1 z z z
1−
z
z
Thus, Z(1) = is the Z transformation of our given function. The inverse
z−1
z z
Z transform of is simply 1. In other words, Z −1 = 1.
z−1 z − 1
Suppose f(n) = 1/n!, n = 0, 1, 2, …. Thus, our Laurent series in Equation 6.19 is
1 1 1 1 1
+ + + +…+ +…
z 0 z 2! z 2 3! z 3 n! zn
The alert reader will recognize this as the Laurent series for e1/z. We say
1 1
that Z = e 1/z. Of course, the inverse Z transform of e1/z is .
n ! n !
It should quickly become apparent that we can choose an expression for
f(n) such that we cannot find its Z transform by inspection. Here is where
MATLAB comes in handy. The reader should now read the documentation
for the MATLAB function ztrans.
Suppose we want to obtain the Z transform of the function f(n) = sin (n).
We proceed as follows:
>> syms n
>> ztrans(sin(n))
ans = (z∗sin(1))/(z^2 − 2∗cos(1)∗z + 1)
>> pretty(ans)
z sin(1)
z − cos(1)z 2 + 1
2
z sin 1
Thus, the Z transform of sin n is 2 , which is the sum of the
Laurent series z − 2 z cos 1 + 1
Transforms: Laplace, Fourier, Z, and Hilbert 275
>> syms n
>> ztrans(heaviside (n))
ans = 1/(z − 1) + ½
The preceding is not the Z transform of unity. From earlier in this sec-
z
tion, we know the correct answer is . The problem is that when n = 0,
z−1
the Heaviside function yields one half. However, we can do the following
trick:
This does yield the desired result because heaviside (n+1) is unity for
n = 0, 1, 2, ….
The question of the inverse Z transform (see Equation 6.29) is poten-
tially vexing. The reader should at this point read the help documentation
for the MATLAB function iztrans, which yields the inverse Z transform.
If we have a function that is analytic in the domain |z| > a > 0, then this
f unction has a unique Laurent expansion in integer powers of 1/z—that
is, the coefficients f(0), f(1), … in Equation 6.26 are determined. The Z
transform is unique. However, there can often be more than one closed-
form expression that will generate these coefficients. For example, sup-
1 1
pose these numbers are 1, , ,.... These could have been derived from
1 2 3
f (n) = or from
n+1
sin 2 (( 2 n + 1) π/2 )
f (n) =
n+1
276 A MATLAB® Companion to Complex Variables
∫ C
z − mdz = 2 πi, m = 1,
∫ C
z − mdz = 0, m ≠ 1 (6.31)
and now suppose we integrate both sides around a simple closed curve C
that encloses the origin and lies entirely in a domain |z| > a.
∫ z ∫ z ∫ z ∫ z
n− 1 n− 1 n− 2 −1
F( z) dz = f (0) dz + f (1) dz + … + f (n) dz
C C C C
∫ z
−2
+ f (n + 1) dz + …
C
From Equation 6.31, we see that every integral on the right has the value
zero except the one containing z−1. Thus, from Equation 6.31,
∫ z
n− 1
F( z)dz = 2 πif (n)
C
Transforms: Laplace, Fourier, Z, and Hilbert 277
1
∫ z
n− 1
f (n) = F( z)dz n = 0, 1, 2, … (6.32)
2 πi
C
Example 6.3
z
What is the inverse Z transform of F( z) = ?
1+ z
Solution:
>> syms z
>> iztrans(z/(1+z))
ans = (–1)^n
1 1
f (n) =
∫ z
n
dz
2 πi 1+ z
C
The contour C must enclose all poles of the integrand. There is but one
pole—it is simple—and it lies at z = −1. Using the calculus of residues,
we have that
2 πi zn
f (n) = Res @ z = −1
2 πi 1+ z
z sin 1
F ( z) =
z 2 − 2 z cos 1 + 1
Let us use residues to take the inverse Z transform of F(z) and try to
obtain our f(n). We must find
1 z sin 1
∫ z n− 1
dz n = 0, 1, 2, … (6.33)
2 πi z 2 − 2 z cos 1 + 1
C
278 A MATLAB® Companion to Complex Variables
z n − 1z sin 1
n = 0, 1, 2, …
2
z − 2 z cos 1 + 1
2 cos 1 ± 4 cos 2 1 − 4
z= = e±i
2
z sin 1
z n− 1 dz @ z = e ± i
z 2 − 2 z cos 1 + 1
Notice the canceling of the 2πi factors when we apply residue calculus
to the expression in Equation 6.33. The expression
z sin 1
z n− 1
2
z − 2 z cos 1 + 1
has only simple poles at its two singularities. The residues are the
numerator divided by the first derivative of the denominator, evaluated
at the poles (see W section 6.3 and S section 7.2).
The residues are
z sin 1
z n− 1
2 z − 2 cos 1
evaluated at ei and e−i. Because these numbers are conjugates of each
other, it should be seen that the residues themselves are also (try plug-
ging these numbers into this expression for the residue). The sum of the
residues is twice the real part of the residue at ei. You may use the other
pole if you prefer. You should convince yourself that the residue at ei is
e in
2 sin 1
(
e − i − cos 1 )
Twice the real part of this expression is sin n, which you should confirm.
This is the desired answer.
The preceding example was not entirely simple, and it would have been
much easier to obtain the desired inverse Z transform with MATLAB. Here
is the procedure:
>> syms a b z
>> a=sym(‘sin(1)’);
>> b=sym(‘cos(1)’);
>> iztrans(a∗z/(z^2–2∗z∗b+1))
ans = sin(n)
Transforms: Laplace, Fourier, Z, and Hilbert 279
>> syms z
>> iztrans(z∗sin(1)/(z^2 – 2∗cos(1)∗z + 1))
>> syms z
>> iztrans(1/(z^2–1))
ans = (–1)^n/2 – kroneckerDelta(n, 0) + ½
1 1 1
F ( z) = + + + ...
z 2 z 4 z6
>> syms z
>> iztrans(exp(1/z))
ans = 1/factorial(n)
>> iztrans(exp(z))
ans = iztrans(exp(z), z, n)
280 A MATLAB® Companion to Complex Variables
Notice that MATLAB gave us the inverse Z transform of e1/z without any
trouble but refused to give us the inverse transform of ez. This is because
(refer to Equation 6.30) lim e z does not exist. In fact, this function has an
z →∞
essential singularity at infinity.
How can we use Z transforms to solve difference equations? Note the
following.
Suppose the function f(n) has the Z transform shown on the right of
Equation 6.28. What is the Z transform of f(n − 1)? Recall that f(n − 1), by defi-
nition, will be zero if n − 1 < 0, or equivalently if n < 1. Thus,
In general,
F ( z)
Zf (n − k ) = (6.34)
zk
f ( k ) f ( k + 1) f ( k + 2)
Zf (n + k ) = + + +…
z0 z1 z2 (6.37)
k −1 k−2
= z F( z) − z f (0) − z
k k
f (1) − z f (2) … − zf ( k − 1)
Example 6.4
Suppose each term in a sequence is simply the average of the two pre-
ceding terms, and that the initial term in the sequence is 1 and the sub-
sequent term is 2. Calling these the zeroth and first terms, what is the
general (nth) term?
We must solve this difference equation:
1 1
f (n + 2) = f (n + 1) + f (n).
2 2
1 z z
( zF( z) − zf (0)) = F( z) − ,
2 2 2
1 1
while obviously the Z transform of f (n) is F( z). We are left with this
transformed equation: 2 2
z z 1
z 2 F ( z) − z 2 − 2 z = F ( z) − + F ( z)
2 2 2
whose solution is
2 z 2 + 3z
F ( z) = .
2z2 − z − 1
We need the inverse Z transform of this. The easy way is with MATLAB.
We have
>> syms z
>> iztrans((2∗z^2+3∗z)/(2∗z^2–z–1))
ans = 5/3 – (2∗(–1/2)^n)/3
282 A MATLAB® Companion to Complex Variables
>> pretty(ans)
n
5 2 −1
−
3 3 2
n
5 2 −1
Thus, we see that our answer f(n) is − . As n → ∞, this has a
3 3 2
5
limit of . We should check our answer by trying the values n = 0 and 1
3
and seeing that we do indeed obtain the initial values of 1 and 2, respec-
tively. It is interesting to plot this function against n to see how rapidly
the sequence converges to its limit.
Here is the code we used for Figure 6.8 on the next page:
n=[0:10];
y=5/3–2/3∗(–1/2).^n;
plot(n,y,’k∗:’);grid
f (n) = ∑ residues z n− 1 2 z 2 + 3z
2z2 − z − 1
@ all poles.
z + 3/2
zn @ its poles.
z 2 − z/2 − 1/2
The zeros of the denominator are readily found to be at 1 and –1/2. Thus,
the poles are simple. The residue at 1 is 5/3, while the residue at –1/2 is
2
− (−1/2)n. The sum of these residues is exactly what MATLAB gave us
3
above.
This is the same equation as the one in the previous problem, but there is
no one half on the right side. The convention is to take f(0) = 0, f(1) = 1, which
would of course mean that f(2) = 1, f(3) = 2, f(4) = 3, f(5) = 5. We want the
* The Wikipedia entry on this subject is short and good. See http://en.wikipedia.org/wiki/
Fibonacci_number
Transforms: Laplace, Fourier, Z, and Hilbert 283
1.9
1.8
1.7
1.6
f (n)
1.5
1.4
1.3
1.2
1.1
1
0 1 2 3 4 5 6 7 8 9 10
Index n
FIGURE 6.8
n
5 2 −1
Plot of − .
3 3 2
general, nth term. We take Z transforms of both sides of the above equation
and apply the conditions on f(0) and f(1). The problem is very similar to the
previous one. We have, after transforming,
z
The solution is F(z) = . Let us try to get the inverse transform of this
2
z −z−1
function with MATLAB.
>> syms z
>> iztrans(z/(z^2–z–1))
ans = (2∗(–1)^n∗cos(n∗(pi/2 + asinh(1/2)∗i)))/i^n – (2∗(–1)^(1 – n)∗(–1)^n∗5^(1/2)∗(1/2
– 5^(1/2)/2)^(n – 1))/5 + (2∗(–1)^(1 – n)∗(–1)^n∗5^(1/2)∗(5^(1/2)/2 + 1/2)^(n – 1))/5
>> simplify(ans,100)
ans = 2∗(–1)^(n/2)∗cos(n∗(pi/2 + asinh(1/2)∗i)) + 1/2^n∗(5^(1/2)/5 – 1)∗(5^(1/2) +
1)^n – 1/2^n∗(5^(1/2)/5 + 1)∗(1 – 5^(1/2))^n
nπ 1 5 1 5
− 1 ( 5 + 1) − n + 1 ( 1 − 5 )
n n
f (n) = 2 i n cos + ni arcsinh(1/ 2) + n
2 2 5 2 5
284 A MATLAB® Companion to Complex Variables
The first term on the left is still daunting. One could simplify it by first
assuming n is an odd integer, applying the formula cos(a + b) = cos a cos b −
sin a sin b, and also by using the logarithmic representation of the arcsinh.
Later one assumes that n is even and repeats the process. A more fruitful
approach is to use MATLAB to again compute the inverse Z transform, but
one first simplifies the problem by using the method of partial fractions
(see W section 5.5, or any standard calculus book).
Notice that z2 − z − 1 = 0 has solutions
1 5 1 5
z1 = + and z2 = − ,
2 2 2 2
z 1 ( 5 + 1)/2 1 ( 5 − 1)/2
F ( z) = = +
z2 − z − 1 5 z − 1 (1 + 5 ) 5 z − 1 (1 − 5 )
2 2
The reader may wish to review the method of partial fractions to see how
this result was obtained. We then find the inverse Z transform of F(z) by tak-
ing the inverse transform of each of these fractions separately and adding
the results. To make our answer useful, we should enter the square root of 5
as a symbol in MATLAB, otherwise it will be converted to a decimal expres-
sion. Here is our code for finding f(n):
syms a z b c f_n
a=sym(‘sqrt(5)’);
b=iztrans((a+1)/2∗1/(z–(1+a)/2))/a;
c=iztrans((a–1)/2∗1/(z–(1–a)/2))/a;
f_n=b+c;
simplify(f_n)
1 ( 1 + 5 )n − ( 1 − 5 )n (6.38)
f (n) =
2 n
5
Transforms: Laplace, Fourier, Z, and Hilbert 285
nmax=input('nmax =')
N=[0:nmax];
a=sqrt(5);
for j=1:length(N)
n=N(j);
nth_fibo(j)=1/a*((1+a)^n-(1-a)^n)/2^n;
end
'number= fibonacci number='
disp([N' round(nth_fibo)'])
Notice the use of the function round. This ensures that we do not see any
round-off errors arising from the use of the square root of 5 raised to various
powers.
Here are the first 10 Fibonacci numbers from this program:
ans =
number = fibonacci number =
0 0
1 1
2 1
3 2
4 3
5 5
6 8
7 13
8 21
9 34
10 55
f (n + 1) 1 + 5 1 − p n+ 1
=
f (n) 2 1 − p n
286 A MATLAB® Companion to Complex Variables
where
1− 5
p=
1+ 5
Notice that |p| < 1 and observe that as n → ∞ the expression in the brackets
has a limit of 1. Thus, the ratio of a Fibonacci number to the one preceding
( )
it has in the limit n → ∞ the value 1 + 5 /2. This irrational expression is
the golden ratio often written as φ and is approximately 1.618033988749895…
There is a vast amount of literature on this number, and the reader may wish
to begin with the Wikipedia entry on this subject to get started. A rectangle
having these proportions has historically been said to be the most pleasing
possible and to serve as the basis for classical Greek architecture.* The ratio
of the 10th Fibonacci number to the 9th, which we obtain from the above list,
is obtainable from MATLAB as follows:
>> vpa(55/34)
ans = 1.6176470588235294117647058823529
which looks almost like an irrational number (it cannot be, of course, and
note the repeating decimal starting with 1764…) and which is remarkably
close to the value φ. Note that we used vpa (i.e., variable precision arithme-
tic) so as to obtain as many decimal places as we could for our comparison.
One can see that the use of Fibonacci numbers is a way to generate num-
bers whose numerical ratio (the (n+1)th divided by the nth), which unless
you can find the repeating decimal, appears to be irrational. Of course, as
n tends to infinity, the limit of this ratio will be irrational. The code that we
used to generate the Fibonacci numbers, which is based on Equation 6.38,
may not be the best way to find the Fibonacci numbers, as demonstrated in
problem 12.
Here is another useful formula. Consider the Z transform:
Recall that
* H. E. Huntley, The Divine Proportion: A Study in Mathematical Beauty. (Mineola, NY: Dover
Books on Mathematics, 1970).
Transforms: Laplace, Fourier, Z, and Hilbert 287
Notice that the preceding right side can be turned into the Z transform of
nf(n) (see above) if we multiply it by –z. Thus,
dF
Z(nf (n)) = − z (6.39)
dz
dF d2 F
Z(n2 f (n)) = z + z 2 2 (6.40)
dz dz
d z z
Z ( n × 1) = − z =
dz z − 1 ( z − 1)2
We can check this result with MATLAB by either asking for ztrans(n) or
z
iztrans 2
.
( z − 1) z
We can also take the inverse Z transform of with residues as
( z − 1)2
described in Equation 6.32.
We have that the inverse Z transform of
z
( z − 1)2
is
1 z
∫ z
n− 1
dz
2 πi ( z − 1)2
288 A MATLAB® Companion to Complex Variables
where we might use a circle of radius exceeding 1 and centered at the ori-
gin. Notice that the integrand has a pole of order 2 at z = 1. We use a stan-
dard formula for computing the residue at this pole (see W section 6.3 or
S problem 7.3). Recall that if a function f(z) has a pole of order 2 at a point
z0, then
d
Res[ f ( z), z0 ] = lim (( z − z0 )2 f ( z))
z → z0 dz
d n
Employing this, we have that our inverse Z transform is z evaluated at
z = 1. The result is simply n, as required. dz
It is useful to have the Z transform of n2 for a problem that is to follow. We
use Equation 6.40, taking, as in the example just done, f(n) = 1 (whose Z trans-
z z2 + z
form is ). We obtain as the required transform. To summarize,
z−1 ( z − 1)3
z
Z(1) = (6.41)
z−1
z
Z(n) = (6.42)
( z − 1)2
z2 + z
Z(n2 ) = (6.43)
( z − 1)3
Example 6.5
Problem
Find the sum of the squares of the first N integers (i.e., find a closed-form
expression for S = 12 + 22 + 32 + … N2).
Solution:
The reader is probably already aware of the simpler result
1
1 + 2 + 3 + ... + N = N ( N + 1).
2
This result was known to the ancient Greeks (e.g., Pythagoras). In the
early 18th century, a young Swiss boy, Leonhard Euler, who was to
become a great mathematician, figured it out by writing down the
sum of the terms on a horizontal line and then placing the same sum
u nderneath in reverse order. He then added the two lines, term by
term. The present problem is harder.
We begin with the difference equation
z 2 ( z + 1)
Z(n + 1)2 = .
( z − 1)3
z 2 ( z + 1)
F ( z) = .
( z − 1)4
syms z
r=iztrans(z^2*(z+1)/(z-1)^4)
The output is
a!
The expression nchoose(a,b) means , which is obviously a
b ! ( a − b)!
binomial coefficient.
We thus rewrite our answer as
After placing the last expression over the common denominator 6 and
doing a little more simplification, we have the result that
n(n + 1)(2 n + 1)
f (n) = 1 + 2 2 + 32 + ... n2 =
6
This yields
If we know the Z transforms of f(n) and g(n), is there some way we can
obtain the Z transform of h(n) without doing the calculation in Equation 6.44?
The answer is yes, as we now show.
Now f(n) has Z transform F(z), and g(n) has Z transform G(z). Here,
∞
F ( z) = ∑ c /z
m= 0
m
m
cm = f (m) (6.45)
G( z) = ∑ d /z
n= 0
n
n
dn = g(n) (6.46)
We assume that both F(z) and G(z) are analytic in the domain |z| > a > 0.
Next we introduce a new variable w and work with F(w) and G(z/w). We
place these two variables in the above series and have
F (w ) = ∑c w
m= 0
m
−m
(6.47)
and
∞ ∞
G( z/w) = ∑ n= 0
dn ( z/w )− n = ∑ dnw nz− n (6.48)
n= 0
∞ ∞
∞ ∞
cmdnw n−m
∑ ∑ ∫
1 F(w)G( z/w) 1
2 πi ∫
w =b
w
dw =
2 πi m= 0 n= 0
z− n
w =b
w
dw (6.50)
From the theory of residues, we know that the integral, which is the in
1
variable w, will vanish except if n = m. Recalling that
w
dw = 2 πi when the
∫
integral is taken around any simple closed contour enclosing the origin, we
have that
∞ ∞
∑ ∑ f (n)g(n)z
1 F(w)G( z/w)
∫ cndn z − n = −n
dw = (6.51)
2 πi w n= 0 n= 0
w =b
Looking at Equation 6.44, we see that the right side of the above equation is
the Z transform of the product f(n)g(n). Thus, to summarize,
1 F(w)G( z/w)
Z f (n) g(n) =
2 πi ∫
w =b
w
dw (6.52)
where F(z) and G(z) are the Z transforms of f(n) and g(n), and the integration
is taken around a circle centered at the origin such that F(w) and G(w) are
analytic on and outside of it. With b as the radius of the circle, we require
that |z| > b|w|. But since |w| = b on the path of integration, this becomes
simply |z| > b2.
Example 6.6
Using MATLAB find the Z transforms of
1
f (n) = e in and g(n) = .
n+1
With these results as well as Equation 6.52 and the calculus of resi-
e in
dues, find the Z transform of h(n) = . State any restrictions that
( n + 1)
must apply to the variable z in your answer. Check your result by using
MATLAB to get Zh(n).
292 A MATLAB® Companion to Complex Variables
Solution:
From MATLAB,
>> syms n
>> ztrans(exp(i∗n))
ans = z/(z – exp(i))
>> ztrans(1/(n+1))
ans = –z∗log(1 – 1/z)
z z
Thus, F( z) = and G( z) = − z log(1 − 1/z) = z log .
z − ei z−1
e in
According to Equation 6.52, the Z transform of h(n) = is the
integral n+1
w
Notice that F(w) = is analytic on and outside any circular con-
w − ei
tour in the w plane given by |w| = b > 1. This is because the only singu-
larity of this function is at w = ei, which lies on the unit circle. Now
w
G(w) = w log .
w−1
We use the principal branch of this function. This is defined by means
of a branch cut on the real axis of the w plane that is given by 0 ≤ w ≤ 1. On
this segment, the argument of the log will be negative real, 0, or infinity.
Notice that G(w) is also analytic for |w| ≥ b. As discussed in our deriva-
tion, we take |z| > b2 in Equation 6.53. Notice that
z 1
log = log
z−w 1 − w/z
w
and that because < 1 on the path of integration |w| = b, the path does
z z
not intersect the branch cut for log .
z−w
Now the reader should evaluate the integral in Equation 6.53, noting
the apparent pole at w = 0. In fact, this is not a pole but a removable singu-
larity (see W section 6.2 and S section 3.11), which has no residue. There
is a residue to be found at w = ei. Our final answer is
e in z z 1
Z = i log = ze − i log
n+1 e z−e i
1 − e i/z
>> syms n
>> ztrans(exp(i∗n)/(n+1))
ans = –z∗exp(–i)∗log(1 – exp(i)/z)
1
The above is identical to ze − i log .
1 − e i/z
c1 c 2
F ( z) = c 0 + + +… c0 = f (0), c1 = f (1), … cn = f (n) (6.54)
z z2
d1 d2
G( z) = d0 + + +… d0 = g(0), d1 = g(1), … dn = g(n) (6.55)
z z2
Let us multiply the two Laurent series together. We get the Laurent series
for the product of the Z transforms:
c0 d1 + c1 d0 c0 d2 + c1 d1 + c2 d0
F( z)G( z) = c0 d0 + + + … (6.56)
z z2
k=n
∑c d
k=0
k n− k = an n = 0, 1, 2, … (6.57)
and so
a1 a1
F( z)G( z) = a0 + + +…
z z2
We say that the sequence of numbers a 0, a1, a2, … results from the con-
volution of the sequences c 0, c1, … and d 0, d1, …. Alternatively, we say that
the function f(n) is convolved with the function g(n). We write this as
f(n) ∗ g(n). The convolution is commutative—it is easy to see that f(n) ∗ g(n) =
g(n) ∗ f(n). This definition of the convolution, for functions defined only for
discrete values of their independent variable (n = 0, 1, 2, 3, …), is the ana-
log of the convolution for continuous functions that we discussed for the
Laplace transform.
What we have discovered is that the Z transform of the convolution of two
sequences is the product of the Z transforms of each sequence. But perhaps
294 A MATLAB® Companion to Complex Variables
just as important, we see that the inverse Z transforms of the product of two
functions is the convolution of the sequences giving rise to each function.
Here is an example.
Example 6.7
We saw in our work above that
z z
Z(1) = and Z(e in ) = .
z−1 z − ei
Solution:
Note that our result can be obtained through a convolution of f(n) = 1 and
g(n) = ein. Thus, our resulting sequence is a0 = 1 × ei0, a1 = 1 × ei1 + 1 × ei0,
a2 = 1 × ei2 + 1 × ei1 + 1 × ei0 …
It should become apparent that
( ) + (e ) ( )
0 i 1 n
an = 1 + e i + e 2 i + … e in = e i + … + ei
1 − r n+ 1
1 + r + r2 + … rn = , r≠1
1− r
we see that
1 − e i( n + 1)
1 + e i + e 2 i + … e ni = .
1 − ei
This is
z2 1 − e i( n + 1)
Z −1 = .
( z − 1)( z − e )
i
1 − ei
z2 1 z2
Z −1 =
( z − 1)( z − e ) 2 πi
i ∫ z n− 1
( z − 1)( z − e i )
dz, n = 0, 1, 2, …
C
We will take the contour C as a circle centered at the origin and having
radius greater than 1. Notice that there are simple poles of the integrand
at z = 1 and z = ei. Our result is
z n+ 1 z n+ 1
Res @ 1 + Res @ ei
( z − 1)( z − e )
i
( z − 1)( z − e i )
Transforms: Laplace, Fourier, Z, and Hilbert 295
This becomes
1 e i( n + 1)
−
1 − e (1 − e i )
i
which agrees with our answer obtained above. We can also check our
answer by using the command iztrans in MATLAB, but there are some
subtleties involved, as shown in exercise problem 13.
Exercises
1. a. Using MATLAB find the Z transform of f(n) = eian, where a is an
arbitrary constant that in MATLAB you must treat as a symbol.
Check this result by summing the series
∞ n
e ia
∑ z
n= 0
8. In solving the problem of obtaining the formula for the sum of the
squares of the first n integers, in one of our worked examples, we
had to find the inverse Z transform of
z 2 ( z + 1)
F ( z) = .
( z − 1)4
We did this using MATLAB. Confirm your result by using resi-
dues in the complex plane.
9. a. Use MATLAB to obtain the Z transform of f(n) = ein.
b. Obtain the Z transform of g(n) = n2ein by using your result from
part (a) as well as Equation 6.40.
c. Check your result by using MATLAB to find the Z transform of g(n).
10. a. We found the Z transform of the function f(n) = n in this sec-
tion. Use one of the translation formulas we derived to find the Z
transform of g(n) = n + 1.
b. Now use the transforms of n and n + 1 to find the Z transform of
the function h(n) = n(n + 1) by means of Equation 6.52. Evaluate
the integral with residues.
c. Check your answer to part (b) by asking MATLAB to compute
the Z transform of n(n + 1).
11. a. Use MATLAB to find the Z transform of the function given by
1
f (n) = , n ≥ 1 and f (n) = 0, n ≤ 0.
n
The Heaviside function is useful here. Notice that an expres-
sion such as heaviside(x − 1/2)/x will, when evaluated at x = 0 by
MATLAB, yield the result NaN (not a number) because of the ratio
0/0. MATLAB skips this point when evaluating a Z transform.
b. Check your answer to part (a) by recovering f(n) by applying
Equation 6.32 to the answer to part (a). Notice that the answer to
part (a) requires the use of a branch cut. What are the requirements
on this cut? The integral that you will get by applying Equation
6.32 cannot be evaluated with residue calculus because the inte-
rior of the contour you use contains branch cut singularities of the
integrand. However, you should make the change of variables w =
1/z and perform your integration in the w plane. Notice the branch
cut is now outside the contour of integration, and you are now
integrating in the clockwise (negative) direction. The series
1 2 1 3 1 4
log(1 − w) = − w − w − w − w −… w <1
2 3 4
is useful here.
298 A MATLAB® Companion to Complex Variables
12. We have seen that the Fibonacci numbers can be obtained as the
coefficients in the Laurent series expansion
∞
2
z
z −z−1
= ∑ zc n
n
n= 0
1
Suppose we make a change of variables w = in both sides of the
z
preceding equation. The right side becomes a Maclaurin series in the
variable w, which converges to the rational function in w that now
appears on the left. Now look up the MATLAB documentation for
the function taylor. Recall that a Maclaurin series is a Taylor series
expansion about the origin.
a. Use taylor to find the first 11 Fibonacci numbers (i.e., the first 10
nonzero ones). Note that MATLAB will give you them in reverse
order.
b. Where does this infinite Taylor series converge in the complex w
plane?
13. a. Try to use MATLAB to obtain the inverse Z transform of the
function
z2 1
F ( z) =
z − 1 z − ei
z( z 2 + 4 z + 1)
F ( z) =
( z − 1)5
n2
f (n) = (n + 1)2
4
How can you be sure this will always produce an integer?
If you elect to use Equation 6.32, you have to compute a fourth
derivative. It is best to do this with MATLAB to avoid mistakes.
Check your f(n) by putting in n = 0, 1, 2, 3, ….
6.5.1 Definition
Suppose g(t) is a function of the real variable t. In most applications this is a
real function, but this is not a requirement. It will, however, simplify our dis-
cussion if we make this assumption. We call the function’s Hilbert transform
gˆ ( x) and define it by the following integral, assuming that x is real and that
the integral exists:
∞
1 g(t)
gˆ ( x) =
π ∫ x − tdt (6.58)
−∞
We also write
gˆ ( x) = Hg(t) (6.59)
g(t) = H−1 gˆ ( x)
where H−1 indicates that we are to take the inverse Hilbert transform. (See
W section 6.10.) Let us use the calculus of residues to find Hsin t. We must do
the integration
∞
1 sin t
π ∫ x − tdt
−∞
We use the contour shown in Figure 6.9, which is in the complex τ plane, not
the z plane. The real axis in the τ plane is the t axis. The integral
1 e iτ
π ∫ x−τ
dτ
Transforms: Laplace, Fourier, Z, and Hilbert 301
6
CR τ plane
5
2 R Radius ε
CE
1
0 –R R
t axis x–ε x x+ε
–1
–2
–6 –4 –2 0 2 4 6
FIGURE 6.9
An indented contour to compute our Hilbert transform.
taken around this contour is zero because the integrand is analytic on and
in the contour.
We pass to the limits R → ∞ and ε → 0+. Notice, from Jordan’s lemma, that
1 e iτ
lim R → ∞
π ∫ x−τ
dτ = 0
over the arc CR, while over the arc Cε, we have
1 e iτ πi e iτ
lim ε → 0 +
π ∫ x−τ
dτ = − Res
π x−τ
@τ = x
1 e iτ
π ∫ x−τ
dτ = ie ix
or
Hsint = −cos x
for our Hilbert transform.
Once a function, say g(t), has been Hilbert transformed into gˆ ( x), how do
we recover g(t)? In other words, how do we find the inverse transform? The
answer is that for a wide class of functions, we can take the Hilbert transform
of gˆ ( x) and put a minus sign in front of the result. There are two proofs in W
(section 6.10). The simplest is based on Fourier transforms and requires that
we accept the validity of the Fourier transform inversion formula. A more
complicated proof requires complex variable theory and the use of indented
contours and residues. The Fourier transform proof has the advantage that it is
less restrictive as to what functions can be transformed (e.g., delta functions).
To summarize the results, if
∞
1 g(t)
gˆ ( x) = Hg(t) =
π ∫ x − tdt
−∞
then
∞
−1 gˆ ( x)
g(t) =
π ∫ t − xdx = H
−∞
−1
gˆ ( x) (6.60)
The middle expression in the above equation is the negative of the Hilbert
transform of g(t).
Of course, the preceding assumes that both integrals exist as Cauchy prin-
cipal values.
How can we use MATLAB to evaluate a Hilbert transform and its inverse?
We do not use the MATLAB command hilbert for the problems we have
been doing, as it is intended to be used with functions defined for discrete
uniformly spaced values of some independent variable.
Study Equation 6.58 for a moment. If
∞
1 g(t)
gˆ ( x) =
π ∫ x − tdt
−∞
1
then the function gˆ ( x) is seen to be the convolution of the functions g(t) and
.
πt
See Equation 6.21 as a reminder, and recall that the Fourier transform of a
convolution of two functions is the product of the Fourier transform of each.
Let us now work with gˆ (t) instead of gˆ ( x). Thus,
1
Fgˆ (t) = Fg(t)F
πt
Transforms: Laplace, Fourier, Z, and Hilbert 303
1
gˆ (t) = ifourier fourierg(t) × fourier (6.61)
πt
1
The Fourier transform of is easily calculated with either residues or
MATLAB, and we have πt
>> syms t
>> Fourier(1/(pi∗t))
ans = heaviside(–w)∗2∗i – i
This function is equal to –i for w > 0 and i for w < 0. It is zero for w = 0. The
following MATLAB script M file will determine the Hilbert transform of a
function that we supply. We have elected to give this M file the name hiltrial.
After creating the file and saving it, you can type this word in the command
window. You will be prompted to produce the function of t that you want to
be transformed.
If you elect to use this M file, you may save it with any other name that
MATLAB does not use for a function or file. Do not use the name hilbert—it
has been taken.
Here is the M file:
syms t
g=input('g is equal to ')
G=fourier (g);
syms pi
h=1/(pi*t);
H=fourier(h);
C=ifourier (G*H);
assume(x,'real')
The_Hilbert=simplify(C)
You will be surprised at how complicated and clumsy the answer looks. It
does not resemble the correct answer of −cos t. MATLAB is much more sophis-
ticated in handling Fourier and inverse Fourier transforms than in perform-
ing integrations using int. This may change in later versions.
Suppose we wish to use either hiltrial or hlbtrn to find the Hilbert trans-
form of the number 1. Here we try both. Notice that both hiltrial and hlbtrn
expect to be fed a symbolic function, not a number. Thus, we create a symbol
to stand for the number 1, and then summon either the M file or the function:
>> a=sym(‘1’)
a=1
>> hiltrial
g is equal to a
g=1
The_Hilbert = 0
>> hlbtrn(a)
ans = 0.
In both cases, we obtain zero. In fact, if you try any constant, you will find
that its Hilbert transform is equal to zero. You may confirm this by using
real variable calculus to evaluate Equation 6.58, taking the integrand as a
real constant. This is alarming as it tells us that the Hilbert transform is not
unique and therefore neither is its inverse transform. Thus, you could argue
that the inverse Hilbert transform of zero is any number you wish.
How can we avoid this situation? From W (see pages 420–421) we learn
the following: Consider the function f (t) = g(t) + igˆ (t). Here the imaginary
part is the Hilbert transform of the real part. Now consider the function
f (τ) = g(τ) + igˆ (τ), where τ is a complex variable whose real part is t.
Now assume that
1 f (τ)
lim R → ∞
π ∫ x − τdτ = 0,
where the integration is performed over a semicircle of radius R in the com-
plex τ plane, and x has any real value. The center of the circle is at the origin
of the τ plane, and the semicircle lies in either the upper or lower half plane.
The function f(τ) must be analytic on and inside at least one of these semi-
circles. If this behavior is satisfied, the transform is unique. A function g(t)
equal to a constant will not satisfy this condition as f(τ) will not satisfy the
requirement on the arc of the semicircle when R → ∞.
Because MATLAB has more sophistication in handling Fourier and
inverse Fourier transforms than it does in ordinary symbolic integration,
306 A MATLAB® Companion to Complex Variables
Ff (t) = F(w) =
∫ f (t)e − iwt
dt
−∞
Suppose we take
g(t)
f (t) = (6.62)
x−t
If we evaluate the Fourier transform of the above and then set w = 0, we
have arrived at the Hilbert transform of g(t). In other words,
∞
g(t)
gˆ ( x) = lim w → 0
∫ π(x − t) e
−∞
− iwt
dt (6.63)
Exercises
1. Do the following problems by using either one or the script files or
functions described above, like hiltrial, or hilfor or hlbtrn, or a pro-
gram of your own devising that does Hilbert transforms. Find the
Hilbert transforms of these functions, g(t). Check your answers by
doing contour integration directly.
a. cos 2t
b. sin(t + 1)
1 − cos 2t
c.
t
Transforms: Laplace, Fourier, Z, and Hilbert 307
∞
1 f (t) sin x
π ∫ x − tdt + x
= 2 cos x
−∞
Notice that the integral on the far left is the Hilbert transform of
the function f(t). Thus, if we take the inverse Hilbert transform of
the expression, we recover f(t). Take the inverse Hilbert transform
of both sides of the above equation (using the linearity property
of the Hilbert transformation and its inverse) and find f(t). Check
your answer by using either residue calculus to find the Hilbert
transform of your answer or by using the program hilfor devel-
oped in this section.
This page intentionally left blank
7
Coda: Fractals and the Mandelbrot Set
In this book, I have sought to create a bridge between complex variable the-
ory and the MATLAB programming language. It seems fitting to end with
a branch of mathematics, which, although dating in its origins to the early
1900s, really did not come into flower until the widespread use of high-speed
digital computers in the 1980s and cannot really be appreciated without a
programming language such as MATLAB®. This is the subject known as
fractals, which is a branch of a larger field in mathematics called chaos theory.
The public is exposed to chaos theory in newspaper articles that speak of
“the butterfly effect.” The term was coined in 1969 by Edward Lorenz, an
MIT Professor of Earth Sciences, who is famous for his research in weather
prediction. He is usually credited with the observation that if a butterfly
flaps its wings, it might trigger a storm appearing many hundreds of miles
away. To a mathematician, this is saying that the solution of a differential
equation, or some iterative process, is acutely sensitive to the initial conditions
imposed on the equations. Lorenz was at the time working on solutions of
309
310 A MATLAB® Companion to Complex Variables
This does look very simple, but you are in for a surprise. Before showing
how this formula defines the Mandelbrot set, we need to review the concept
of a sequence of complex numbers that remains bounded.
Suppose the elements of the sequence are the set of numbers z0, z1, z2, ... zn,
zn+1, .... This sequence is bounded if and only if the following is true: given any
positive real number M there exists a real number N such
Thus, the sequence i, i2, i3, ... in, ... is bounded (the magnitude of each term
is one), while the sequence 1+i, (1+i)2, (1+i)3, ... (1+i)n, ..., whose magnitude for
( )
n
the nth term is 2 , is not bounded. You should be able to show that the
sequence consisting of principal values 1i, 2i, 3i, ... ni, ... is bounded, but if we
replace i with 1 + i, we do get a sequence that is not bounded.
Here is how we find the elements of the Mandelbrot set, the most famous
fractal. We choose a numerical value for c (any number, real or complex)
and choose for our “seed” the number z0 = 0. We plug this into Equation 7.2
and compute z1, which is of course equal to c. Knowing z1, we return to this
* Fractals, Chaos, Power Laws: Minutes from an Infinite Pradise by Manfred R. Schroeder, New York:
WH Freeman, 1990.
312 A MATLAB® Companion to Complex Variables
equation and see that z2 = c2 + c, and in the same way, we have z3 = (c2 + c)2 + c =
c4 + 2c3 + c2 + c. The expressions become increasingly complicated. The
Mandelbrot set is defined as follows:
It is the set of values of c for which the sequence of values obtained from
Equation 7.2 is bounded when we use as our starting value z0 = 0.
q=1;
while q>0
c=input('the complex value of c to be checked')
tic
nmax=10e6;
%this is the max number of iterations, but
%the iterations will stop if |zn|>2
n=1;
z=0;
while(abs(z)<=2)
z=z^2+c;
n=n+1;
if n>nmax
break
end
end
if n<=nmax
disp('the value of zn that causes early termination if n<nmax')
z
end
disp('number of iterations used')
n−1
if n−1==nmax
* See A. J. Crilly, R. A. Earnshaw, and H. Jones. Fractals and Chaos (New York: Springer, 1991): 36.
314 A MATLAB® Companion to Complex Variables
Let us try the program out by seeing if the point .2+.5∗i is in the Mandelbrot
set. Here is what occurs on our computer screen when we run the above
program:
>> mandelcheck
the complex value of c to be checked .2+.5∗i
c = 0.2000 + 0.5000i
number of iterations used
ans = 10000000
the number c is in the set
Elapsed time is 8.165984 seconds.
The calculation took around 8 seconds. If the point chosen lies outside the
set, the calculation takes less time because the iteration procedure termi-
nates before the 10 millionth value of zn is found. We see that in determining
whether c = .2 +.7∗i lies in the set—it does not—we require a lot less time.
Here are our results:
>> mandelcheck
the complex value of c to be checked .2+.7∗i
c = 0.2000 + 0.7000i
the value of zn that causes early termination if n<nmax
z = −1.0957 + 1.7956i
number of iterations used
ans = 6
the number c is not in the set
Elapsed time is 0.003120 seconds.
We see that by the time we reach z6, whose magnitude exceeds one, we can
conclude that .2+.7∗i is not in the Mandelbrot set.
Even though we are allowing for 10 million possible iterations, the pro-
gram is not perfect. It can be shown that if c is positive real, then it must
satisfy c ≤ 1/4. This is derived in problem 3. Thus, we might wish to test our
program by choosing c just to the right of one quarter. Here is an instance
where we try both c = .25 + 1000∗eps and also .25+100∗eps. In the second
case, we got an incorrect answer. The number should have been found to not
Coda: Fractals and the Mandelbrot Set 315
lie in the set. Recall that eps is the smallest positive real that MATLAB can
handle. For my version of MATLAB, this was found as follows:
>> eps
ans = 2.2204e−16
If you type eps you will find the value in use on your computer. Our results
for these two values of c are as follows:
>> mandelcheck
the complex value of c to be checked .25+1000∗eps
c = 0.2500
the value of zn that causes early termination if n<nmax
z = 2.3790
number of iterations used
ans = 6666992
the number c is not in the set
Elapsed time is 0.136802 seconds.
q = negative to stop, positive to keep going 2
q=2
the complex value of c to be checked .25+100∗eps
c = 0.2500
number of iterations used
ans = 10000000
the number c is in the set
Elapsed time is 0.202285 seconds.
As noted, the second answer is erroneous. But, if you change the number
of iterations to something larger (e.g., 100 million), the computer determines
that the number is not in the set.
At this point, we might recall Lorenz’s statement about a butterfly flapping
its wings. Here is an analogous finding from the Mandelbrot set. Suppose
c = i. We saw above that c = i does lie in the Mandelbrot set. If you try out
our program Mandelcheck with any of these four values i±10−6 or i±i10−6,
you will find that none of them lies in the Mandelbrot set. In other words,
if we use the iterative formula Equation 7.2 with any of these four values of
c, we develop sequences the magnitudes of whose elements grow without
bound. Yet these points seem to lie “close” to z = i. These small deviations
from i might make us think of the flapping of the butterfly’s wings causing
a storm.
The reader might be thinking, “What’s so special about that? After all, the
series 1 + z + z2 + z3 + ... will converge if z = .99999999 but will diverge to infin-
ity if z = 1.” The difference is that we can state quite simply where this series
will converge, namely, it converges if and only if |z| < 1. If asked to find all
316 A MATLAB® Companion to Complex Variables
* Kenneth Falconer, Fractals: A Very Short Introduction (New York: Oxford University Press, 2013).
Coda: Fractals and the Mandelbrot Set 317
q=1;
while q>0
xo=input('x coord center of box=')
yo=input('y coord center of box=')
dx=input('half width of box, x direction=')
dy=input('half width of box, y direction=')
nx=input('number of x divisions')
ny=input('number of y divisions')
tic
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0 2 4 6 8 10 12 14 16 18 20
FIGURE 7.1
Self similarity.
318 A MATLAB® Companion to Complex Variables
cr=linspace(xo-dx,xo+dx,nx);
ci=linspace(yo-dy,yo+dy,ny);
[Cr,Ci]=meshgrid(cr,ci);
c=Cr+i*Ci;%this creates a grid of complex numbers for c
nmax=200;% we use 200 iterations of the recursion relation
j=1;
z=
zeros(size(c));%this starts off z, for each value of c,
%at the value zero
ile j<=nmax;%iterates the expression below nmax times;
wh
%200 here;
z=z.*z+c;
j=j+1;
end
ck
=abs(z)<=2;%puts a symbol of 1 in the matrix where |z|<=2;
%otherwise puts %0
=1.0*ck;%converts symbolic elements to numerical in above
dk
%matrix.
p=pcolor(cr,ci,dk);
se
t(p,'EdgeColor','none');colormap(gray);grid;%use gray for a
%black and white %picture
set(gca,'layer','top'); %required if you hope to see the grid
axis([xo-dx xo+dx yo-dy yo+dy])
q=input('negative q to stop')
end
In this program, we are asked for the center and dimensions of a rectan-
gular box. The program then creates a plot on your screen where points in
the box that lie in the Mandelbrot set are given the color white, while the
other points are given the color black. Recall that we introduced the function
pcolor at the end of Chapter 2. If you wish to reverse this convention, use the
line of code p=pcolor(cr,ci,-dk). Notice the minus sign in front of the symbol
dk. However, there is then the risk that a spot of dark dirt on your screen
might be erroneously taken for an element of the set.
We know that the Mandelbrot set must lie on and within a circle of radius
2 centered at the origin of the complex c plane. We generate our set inside a
square box centered at the origin. The sides are parallel to the real or imagi-
nary axes, and each side is of length 4. Thus, we are guaranteed that the set
will be inside the box and no part will be left out (Figure 7.2). We will use
slightly over 1 million date points, as follows:
>> mandel_one
x coord center of box=0
xo = 0
y coord center of box=0
yo = 0
half width of box, x direction=2
dx = 2
Coda: Fractals and the Mandelbrot Set 319
1.5
0.5
–0.5
–1
–1.5
–2 –1.5 –1 –0.5 0 0.5 1
FIGURE 7.2
The Mandelbrot set.
We chose odd numbers (namely 1001) for nx and ny, the number of x and y
subdivisions of our box in the x and y directions, to ensure that there would
be elements lying on the horizontal and vertical lines passing through the
center of the box. This is especially useful if the center of the box lies on the
x axis.
By choosing ny as odd, we ensure that we are choosing elements that lie on
the x axis, which is an axis of symmetry for the Mandelbrot set.
In 1981–1982, two mathematicians, A. Douady (a Frenchman) and
J.H. Hubbard (an American) proved that the Mandelbrot set is simply
connected and closed. The set has no holes and contains all its boundary
points. Choosing any two points in the set, we should be able to con-
nect them by a chain of curved and straight segments all of whose points
lie in the Mandelbrot set. We know that z = i is in the Mandelbrot set.
320 A MATLAB® Companion to Complex Variables
q=1;
while q>0
xo=input('x coord center of box=')
dx=input('half width of box, x direction=')
yo=input('y coord center of box=')
dy=input('half width of box, y direction=')
nx=input('number of x divisions')
ny=input('number of y divisions, preferably use odd=')
tic
cr=linspace(xo-dx,xo+dx,nx);
ci=linspace(yo-dy,yo+dy,ny);
[Cr,Ci]=meshgrid(cr,ci);
c=Cr+i*Ci;
figure(1)
z=zeros(size(c));
for j=1:20
z=z.*z+c;
end
Coda: Fractals and the Mandelbrot Set 321
D=abs(z);
d=(D<=2);%this gives a matrix having ones for those values of c
%that are apparently in the Mandelbrot set after 20 iterations
grid;axis equal;
w=z;
for j=21:1000
w=w.*w+c;
end
DD=abs(w);
=(DD<=2);%this gives a matrix having ones for those
dd
%values of c
%t
hat are taken to be in the Mandelbrot set after 1000
%iterations
p=
pcolor(cr,ci,d/2+dd/2);%the matrix d/2+dd/2 will have
%ones at those
%values of c that are in the matrix after 1000 iterations
%
it will have the value 1/2 at those values of c that are
%in the
%
matrix after 20 iterations but not after 1000; these
%values are not
%i
n the Mandelbrot set;values of c that are eliminated
%after just 20
%iterations are represented by zeros
set(p,'EdgeColor','none')
colormap(hot);hold on
grid on;axis equal
xlim([xo-dx xo+dx])
ylim([yo-dy yo+dy])
set(gca,'layer','top');% this allows you to see the grid
toc
q=input('choose a negative q to stop')
end
From our previous plot, we have some idea of the rough outlines of the set.
Thus, we will run the program so that xo=−.5, yo=0, dx=1.5, dy=1.5. We have
then a box centered at [−.5,0]. The sides of the box are each of length 3. We
choose nx=ny=501 so that the grid on which we determine the Mandelbrot
set has slightly over a quarter million data points. We used a “hot” colormap
whose middle tones are orange. The reader might wish to study the topic
“colormap” in MATLAB help. We have chosen to place points in the set if
after 1,000 iterations of Equation 7.2 we have not achieved |zn| > 2. These are
portrayed with a white dot. Points that appeared to be in the set after 20 itera-
tions but are found not to be in the set (they escaped from it) after we were
somewhere between 21 and 1,000 iterations are portrayed by this program
with an orange dot. All the points that were found to be outside the set in the
first 20 iterations appear in black. The reader might wish to experiment with
these settings.
322 A MATLAB® Companion to Complex Variables
1.5
0.5
–0.5
–1
–1.5
–2 –1.5 –1 –0.5 0 0.5 1
FIGURE 7.3
The Mandelbrot set enhanced with escape points.
Coda: Fractals and the Mandelbrot Set 323
Shown below is the filled-in Julia set for the case c = .25 + .45i. Note that
|c| < 2. The points in the plane are to be interpreted as values of z0. We have
used 1,000 iterations in the formula (Equation 7.2) and have decided that if
the magnitude of the value of zn has not exceeded 2 after this many iterations,
then the starting value z0 is in a Julia set.
The filled-in Julia set is in white. The border consisting of the boundary
points is complicated. This is the Julia set for c = .25 + .45i. The filled-in Julia
set—the interior plus boundary—looks like the map of a country. Think of
France, for example. The number of data points used in creating this image
is (1001)2—slightly over a million.
Here is another example of a Julia set (see Figure 7.4). This one uses c = –1 +
.287i. We obtain the Figure 7.5. It looks like a constellation of stars in the sky.
Note that although there appear to be portions of the set containing points
that are not isolated (i.e., interior points whose every neighborhood contain
elements other than the point in question), all members of this set are indeed
isolated; the computer is not capable of showing the true dust-like nature of
this Julia set. How do we know that all the elements are isolated? We answer
this in a moment.
The image was created using a grid for possible values of z0 equal to (501)2
data points. There is an art to choosing the fineness of the grid. If you make
the grid too fine, the number of pixels assigned to each value of z0 will be so
few that a white spot will not appear on the computer screen or be reproduc-
ible from your printer.
1.5
0.5
0.5
–1
1.5
–2
–2 –1.5 –1 –0.5 0 0.5 1 1.5 2
FIGURE 7.4
An example of a Julia set. This one uses c = .25 + .45i.
Coda: Fractals and the Mandelbrot Set 325
0.5
0.4
0.3
0.2
0.1
–0.1
–0.2
–0.3
–0.4
–0.5
–1.5 –1 –0.5 0 0.5 1 1.5
FIGURE 7.5
Julia set for c = –1 + .287i.
The use of “escape time algorithms” which enhanced our pictures of the
Mandelbrot set can also be advantageously applied also in the code used to
display Julia sets.
When does a value of c yield a connected set, and when does it yield
“dust”—a set consisting entirely of boundary points? The answer to this
is sometimes called The Fundamental Theorem of the Mandelbrot Set. The
Julia set is connected (and this applies to the filled-in set as well) if c lies
in the Mandelbrot set. The Julia set is not connected (nor is any subset
of it connected) if c lies outside the Mandelbrot set. The proof was made
independently, circa 1919, by the two French mathematicians Gaston Julia
and Pierre Fatou. The theorem was proved long before the Mandelbrot set
received its name—the naming did not take place until the early 1980s and
originated with the mathematicians John Hubbard and Andrew Douady,
who wished to honor Mandelbrot for his contribution to our understand-
ing the set.
The point c = –1 + .287i does not lie in the Mandelbrot set. You can verify
this with our program called Mandelcheck. Thus, Figure 7.5 shows a Julia
set—every point is boundary point and every point is an isolated member
of the set. The figure preceding that shows a closed connected set. This is
because .25 + .45i lies in the Mandelbrot set, as can be verified with our pro-
gram Mandelcheck.
Here is a hint for writing the software to generate Julia sets and filled-in
Julia sets. We use Equation 7.2, zn+1 = zn2 + c; our Julia plot is for some chosen
326 A MATLAB® Companion to Complex Variables
Appendices to Coda
Appendix A
We prove here that if |c| > 2, then c is not in the Mandelbrot set.
We make considerable use in this discussion of a version of the triangle
inequality (see W section 1.3 or S section 1.5).
If u = v + w with |v| > |w|, then we have
c
Now z1 > from Equation 7.6. Thus, from our triangle inequality, |z2| >
z1
|z1|(|z1| − |c|/|z1|).
Coda: Fractals and the Mandelbrot Set 327
|z2|>|c|(|c| − 1) (7.7)
c 1
< < 1 (7.9)
z2 ( c − 1)
Recognizing from Equation 7.9 that |c|/|z2| < 1 and |z2| > 2 we have with
our triangle inequality |z3| = |z2||z2 + c/z2| > |z2|(|z2| − |c|/|z2|), so that
|z3|>|z2|(|z2| − 1) (7.10)
|z3| > |c|(|c| − 1)2
One should see that a pattern is emerging. We now make the following
proof by the method of induction. Our goal is to prove if |c| > 2 and if for
some integer n > 0 that
In other words, we will have proved that Equation 7.12 remains valid for
all values of n larger than the one where we already knew it to be valid.
Notice by the way that we have already proved that Equation 7.11 is true
for n = 2,3.
From our iterative formula, taking magnitudes:
Going back to Equation 7.11, which we assume to be true, for some n, and
recalling that |c| > 2, it should be apparent that |zn| > |c| > 2 and also from
Equation 7.11 that
1
c / zn < < 1 < zn
( c − 1)n−1
Using our triangle inequality, we have from Equation 7.13,
Replacing |zn| on the far right with our assumption in Equation 7.11, we have
finally our desired result |zn+1| > |c|(|c|− 1)n. We can repeat this process indefi-
nitely, each time using the latest result, so that |zn+k+1| > |c|(|c|− 1)n+k, where
k ≥ 0 is any integer. Notice that as n → ∞ in Equation 7.12, we find that |zn+1|
grows without bound, in other words, the sequence diverges to infinity, a subject
we touched on in Chapter 3. Thus, if |c| > 2, then c is not in the Mandelbrot set.
Appendix B
In this appendix, we prove the following. If we assume that |c| ≤ 2 (which
means that c might lie in the Mandelbrot set), and if we perform our iterative
procedure (Equation 7.2) and discover a value of |zn| > 2, then |zn+1| >
|zn|, |zn+2| > |zn+1|, and so on, so that the magnitude of each term in the
sequence exceeds that of any term preceding it. This, of course, does not
prove that the sequence becomes unbounded. But we will in fact prove that
the sequence |z0|, |z1|, |z2|, ... does grow without bound and thus c is not in
the Mandelbrot set.
From Equation 7.5, zn+ 1 = zn2 + c, which gives us the familiar
c c
zn+ 1 = zn2 + c = zn zn + > zn zn − > zn ( zn − 1) (7.14)
zn zn
Since |zn+1| > |zn|(|zn| − 1), we have that |zn+1| > |zn|. And since |zn| > 2,
we can argue from the preceding that |zn+1| > 2. Notice that for this reason it
is now permissible to change the index from n to n + 1 in Equation 7.14 to get
|zn+2| > |zn+1|(|zn+1| − 1) (7.15)
We now use Equation 7.14 and the fact that |zn+1| > |zn| to rewrite
Equation 7.14 as
|zn+2| > |zn|(|zn| − 1)2 (7.16)
Coda: Fractals and the Mandelbrot Set 329
|zn+k| > |zn|(|zn| − 1)k (7.17)
provided |zn| > 2 and k ≥ 0. Since |zn| > 2, the limit of |zn+k| is infinity as k → ∞.
Thus, as soon as we find a |zn| > 2, we know that the value c we are using
cannot belong in the Mandelbrot set.
The equation |zn+1| > |zn|(|zn|− 1) can be applied whenever |zn| > 2. Thus,
it can be applied to the sequence z1, z2, …, zn, …, provided you choose a term zn
whose magnitude exceeds 2. Hence, for this term or any term to the right of
it, you can say that the succeeding term is larger in magnitude than the one
before it. As soon as you find a term whose magnitude exceeds 2, you will
know that from then on the terms will get bigger and bigger in magnitude
and grow without bound.
Appendix C
Here we prove that if a point z0 satisfies the condition that |z0| is greater than
the larger of 2 and |c|, then this point is not in a Julia set.
We have that z1 = z02 + c , so that
c c
z1 = z02 + c = z0 z0 + > z0 z0 − (7.18)
z0 z0
c
Recall that < 1 by assumption. Also |z0| > 2 by assumption. Thus, it
z0
must be true that |z1| >|z0| and that |z1| is greater than the larger of 2 and
|c|, since z0 is. Continuing in this way we could argue that
c
z2 > z1 z1 − (7.19)
z1
and that |z2| is greater than the larger of 2 and |c|. Combining our two
inequalities, we have
c c
z2 > z0 z1 z0 − z1 −
z0 z1
c c c
zn > z0 z1 ... zn− 1 z0 − z1 − ... zn− 1 −
z 0 z1 z n− 1
330 A MATLAB® Companion to Complex Variables
Suppose we pass to the limit as n → ∞. The product |z0||z1| ... |zn−1| consists
of terms each of which exceeds 2 and thus it grows without bound. Each of
the other terms in the product
c c c
z0 − z0 z1 − z1 ... zn − zn
exceeds one. Thus, our limit goes to infinity—the product is unbounded
and the iterative process leads to an unbounded result. As in the above two
appendixes, we obtain a sequence diverging to infinity.
Notice that had we begun with a value of z0 whose magnitude was not
greater than the larger of 2 and |c| but, through a process of iteration,
encountered a value of zn whose magnitude did exceed these two quanti-
ties, we could readily modify the preceding proof to show that the resulting
sequence did become unbounded, and we could then conclude that z0 is not
in a Julia set.
Exercises
1. Consider the sequence |z0|,|z1|,|z2|, ... For the expressions zn given
below, explain whether this sequence is bounded. If the expression is
a function of z, state the domain or set of points where the sequence
becomes unbounded.
a. zn = ncos(nπ/2)
b. zn = enz
c. zn = nz
2. a. We established that z = i is in the Mandelbrot set. Since the
Mandelbrot set is connected, every neighborhood of this point
must contain at least one other point in the set. Consider z = x + iy
satisfying −.1 ≤ x ≤ .1, .9 ≤ y ≤ 1.1. Using our program Mandelcheck,
try to find a point in this region other than z = i that lies in the
Mandelbrot set. This could be quite tedious. It is doubtful that you
will succeed by proceeding by trial and error.
b. A systematic way to solve the preceding problem is with the follow-
ing code. In order to understand it, read the MATLAB documen-
tation for the command find. Try running the code for the region
described below using nx=ny=1001 subdivisions for the square
region. Find at least one point in the Mandelbrot set (the program
should yield many). Test that this point lies in the Mandelbrot set by
using the code Mandelcheck given earlier in this chapter.
Coda: Fractals and the Mandelbrot Set 331
q=1
format long
while q>0
xo=input('x coord center of box=')
yo=input('y coord center of box=')
dx=input('half width of box, x direction=')
dy=input('half width of box, y direction=')
%below use odd numbers for nx and ny to include center of box
%in your calculations
nx=input('number of x divisions')
ny=nx; %this is number of y divisions
% the two lines below give the real and imaginary parts of c.
tic
cr=linspace(xo-dx,xo+dx,nx);
ci=linspace(yo-dy,yo+dy,ny);
[Cr,Ci]=meshgrid(cr,ci);
c=Cr+i*Ci;%this creates a grid of complex numbers for c
nmax=1000;% we use 1000 iterations of the recursion relation
j=1;
zeros(size(c));%this starts off z, for each value of c,
z=
%at the value zero
while j<=nmax;%iterates the expression below nmax times;
z=z.*z+c;
j=j+1;
end
=abs(z)<=2;%puts a symbol of 1 in the matrix where |z|<=2 ;
ck
%otherwise puts zero
dk
=1.0*ck;%converts symbolic elements to numerical in above
%matrix.
ows,cols,vals] = find(dk);%this finds the nonzero elements
[r
%in dk
for k=1:length(rows)
locations=c(rows(k),cols(k))
figure(1)
plot(locations,'k.'); hold on
%the above is optional and will plot the points
%you just found as dots
%t
he "locations" are points in the complex plane lying in
the % mandelbrot set
end
toc
q=input('negative q to stop')
end
332 A MATLAB® Companion to Complex Variables
3. We can prove that if c is real and c > 1/4, then c is not in the
Mandelbrot set.
a. Why is zn+ 1 − zn = zn2 − zn + c ?
Note that all values of zn obtained through iteration are real if c
is real.
b. Using the result of (a), argue that zn+1 − zn is always greater than
or equal to some positive constant that is independent of n.
Hint: Look at the equation in the x–y plane y = x2 − x + c, c >
1/4 and argue that this is always positive. One way to do this
is to find where the first derivative vanishes and show that the
second derivative is positive there. Thus, the function displays a
minimum. It is easy to show that the function is positive at the
minimum. What is its value at the minimum? It is convenient to
1
take c = + ε, where ε > 0.
4
c. Since zn+1 − zn ≥ ε, how does this show that as m → ∞ zm grows
positive without bound? This completes the proof. Notice that
we already know that if c is real and c < −2, then c is not in the
Mandelbrot set because |c| > 2.
4. Our code Mandelescape shows points that are presumed to be in the
Mandelbrot set when we have made 1,000 iterations with our working
iterative formula (Equation 7.2). It also shows points that are presumed
to be in the set after 20 iterations but are found not to be in the set when
we have made between 21 and 1,000 iterations. It also shows points
found to not be in the set when we have made 1 to 20 iterations.
Improve upon the code as follows. It should show points that are
presumed to be in the Mandelbrot set when we have made 1,000
iterations with our working iterative formula (Equation 7.2). Also
show points with a distinctive color that are presumed to be in the
set after 5 iterations but are found not to be in the set when we have
made between 6 and 15 iterations. Similarly, show points found to
not be in the set when we have made 16 to 1,000 iterations. And show
points found not to be in the set when we have made 1 to 5 iterations.
5. Show that no matter what value is chosen for c, the correspond-
ing Julia set or filled Julia set must contain the two points given by
1 1 1 1
z0 = + ( 1 − 4c ) c ≠ . If c = , this reduces to the fact that the
1/2
2 2 4 4
1
filled Julia set contains z0 = .
2
Hint: Study Equation 7.2 and look for fixed points (i.e., points which
the iterative procedure transforms back into themselves).
6. a. Write code similar to our code called Mandelbrot, above, to
generate a Julia set. The code will prompt you for the value of c
Coda: Fractals and the Mandelbrot Set 333
COMPANION
functions of complex variable theory and MATLAB, this supplemental text
enables instructors to easily add a MATLAB component to their complex
variables courses.
to COMPLEX
A MATLAB® Companion to Complex Variables provides readers with a
clear understanding of the utility of MATLAB in complex variable calculus.
An ideal adjunct to standard texts on the functions of complex variables,
the book allows professors to quickly find and assign MATLAB program-
ming problems that will strengthen students’ knowledge of the language
and concepts of complex variable theory.
VARIABLES
The book shows students how MATLAB can be a powerful learning aid in
such staples of complex variable theory as conformal mapping, infinite se-
ries, contour integration, and Laplace and Fourier transforms. In addition to
MATLAB programming problems, the text includes many examples in each
chapter along with MATLAB code.
Fractals, the most recent interesting topic involving complex variables, de-
mands to be treated with a language such as MATLAB. This book concludes
with a Coda, which is devoted entirely to this visually intriguing subject.
A. David Wunsch
K27481
w w w. c rc p r e s s . c o m