Lecture Notes Week 1b
Lecture Notes Week 1b
Lecture-3
Visual Thinking-3
Auditya Sharma and Ambar Jain
Dept. of Physics, IISER Bhopal
Outline
In this lecture you will
2. learn to plot 2-D and 3-D plots such as vector plots, streamline plots and contour plots.
10-Jan-2019
2 Module 3 - Visualization and functions.nb
Zero
Zero: A function f (x) has zeros at points x* where f (x* ) = 0. Identifying these points should be the first step in sketching a function.
f ( x) = x2 - 3 x + 2
(1)
= (x - 2) (x - 1).
Divergence
1
Divergence: A function f (x) has divergences (or singularities) at points x* where f ( x* )
has a zero. Identifying these points (and sometimes the form of the divergence nearby) helps
us figure out where and how the function blows up.
1
f ( x) = . (2)
(x - 2) (x - 1)
1
Plot , {x, 0, 3}
(x - 1) (x - 2)
Module 3 - Visualization and functions.nb 3
15
10
-5
-10
-15
Extrema
* ' *
Extrema: A function f (x) has extrema at points x where f (x ) = 0. Further work would be essential to clarify if the point is a minimum or a maximum or an inflection point.
Identifying these points help in getting the broad shape of the function. Let us take the example of the same function f (x) = x2 - 3 x + 2. Here it turns out that rather than factoriza-
tion, it is more useful to `complete the squares’.
f ( x) = x2 - 3 x + 2
3 2 1 (3)
= x- - .
2 4
Asymptote
1
Asymptote: An asymptote is a curve that a function f (x) approaches arbitrarily closely in some limit. A familiar example is the curve f (x) = x
, which asymptotically approaches
the X-axis as x → ∞, and asymptotically approaches the Y-axis as x → 0.
4 Module 3 - Visualization and functions.nb
1
Plot , {x, - 10, 10}
x
1.0
0.5
-10 -5 5 10
-0.5
-1.0
1
Let’s increase the y-range of the plot and examine it whether the curve x
approaches y-axis. We will do this by invoking an option for the Plot function called PlotRange
1
Plot , {x, - 10, 10}, PlotRange → {- 10, 10}
x
10
-10 -5 5 10
-5
-10
Module 3 - Visualization and functions.nb 5
Properties of Functions
Example-1
For the function f (x) shown below find the extremum points if any and find the nature of the extremum:
f ( x) = x ) x* (4)
Example-3
For the famous function known as Lorentzian shown below, plot the function and identify what happens by changing the parameter a. What is the asymptotic behaviour of the
function?
a2
fLorentzian (x) = (6)
x2 + a2
6 Module 3 - Visualization and functions.nb
a2
In[" ]:= ManipulatePlot , {x, - 5, 5}, PlotRange → {0, 1}, PlotLegends → "Lorentzian", "a2 /x2 ", {a, 0.5, 2, 0.1}
2 2
x +a
1.0
0.8
Out[" ]= 0.6
Lorentzian
0.4
0.2
-4 -2 0 2 4
Example-4
2
Let’s change the sign of a in the Lorentzian to get the not-so-famous function shown below. Can you plot this and identify the divergences?
1
f ( x) = (7)
x - a2
2
Do this on paper and pen before we test it out on the computer. Discuss in groups of three.
Module 3 - Visualization and functions.nb 7
1
ManipulatePlot , {x, - 5, 5}, PlotRange → Full, PlotLabel → Style["a" → a, 16, Blue], {a, 0.5, 2, 0.1}
x - a2
2
a → 1.3
100
50
-4 -2 2 4
-50
-100
Example-5
For the function below, find the asymptotes.
(x - 1) (x - 2)
f ( x) = (8)
x
Do this on paper and pen before we test it out on the computer. Discuss in groups of three.
8 Module 3 - Visualization and functions.nb
10
-4 -2 2 4
-5
-10
-15
Example-6
Here is another famous function: Gaussian
2 2
fGaussian (x) = ⅇ-x a (9)
Study the properties of this function and explore the role of parameter a.
Module 3 - Visualization and functions.nb 9
- x2
In[" ]:= ManipulatePlotExp , Exp[- 1], {x, - 5, 5}, PlotRange → Full, PlotLabel → Style["a" → a, 16, Blue],
a2
PlotLegends → "Gaussian", ⅇ-1 , "Lorentzian", {a, 0.5, 2, 0.1}
a → 0.5
1.0
0.8
Out[" ]=
0.6 Gaussian
1
ⅇ
0.4
0.2
-4 -2 2 4
10 Module 3 - Visualization and functions.nb
Problem
(a) For sinh(x), sech(x), tanh(x) and coth(x), make the plots in suitable ranges for the function. Identify the salient features, such as extrema, zeros, asymptotes, discontinuities,
derivative discontinuities.
(b) Using the Manipulate command explore the effects of parameter a in functions sinh(a x), sech(a x), tanh(a x) and coth(a x)
1 2
(c) Compare the functions , ⅇ-x and sech(x) on the same plot. What is the difference between them for large x?
x 2 +1
Module 3 - Visualization and functions.nb 11
Vector Fields
0 A vector field in 3-dimensions is a function represented by a 3-tuple of functions
4 4 4 (12)
v(r) = vx (r) i + vy (r) j + vz (r) k
4 4
0 In two dimensions r = x i + y j
4 4 (13)
v(r) = vx (r) i + vy (r) j
0 It is straightforward to generalize it to n-dimensions but it will be difficult to think about plots in n-dimensions 7. So for now let’s focus on 2 and 3-dimensions.
Example-1
(a) For the vector fields given below find their divergence and curl:
4 4
v=xi+y j
4 4
u=yi+x j (14)
4 4
w = -y i + x j
(b) By creating a vector plot verify the results you found for divergence and curl of these functions.
(c) If these vector fields represented flow of a fluid, make a streamline plot to demonstrate it:
Sol (a):
∇ ·v = 2
∇ ×v = 0
∇ ·u = 0
(15)
12 Module 3 - Visualization and functions.nb
∇ ·u = 0
∇ ×u = 0
∇ ·w = 0
4
∇ ×w = 2 k
Sol (b): In Mathematica, we will do this by invoking VectorPlot, where a vector field is represented by a 2-tuple or 3-tuple as given below:
v = {x, y}
u = {y, x} (16)
w = {-y, x}
-2
-4
-4 -2 0 2 4
(15)
Module 3 - Visualization and functions.nb 13
-2
-4
-4 -2 0 2 4
14 Module 3 - Visualization and functions.nb
-2
-4
-4 -2 0 2 4
Sol (c): Streamline Plots are very similar to vector plots but they represent flow of a fluid or field lines, as in electric field lines and magnetic field lines. It only shows the direction
of the flow at each point. They can be made by StreamPlot function:
Module 3 - Visualization and functions.nb 15
-2
-4
-4 -2 0 2 4
To avoid the funny business at origin where the flow direction is “confusing”, we can avoid the region by using the option known as RegionFunction, which puts a suitable
constraint on the coordinates x and y, vector field components vx , vy and norm of the vector field n = )v*. In this case we subject the plot to constraint that x2 + y2 > 0.05:
16 Module 3 - Visualization and functions.nb
StreamPlot{x, y}, {x, - 4, 4}, {y, - 4, 4}, RegionFunction → Function{x, y, vx, vy, n}, x2 + y2 > 0.05
-2
-4
-4 -2 0 2 4
Using StreamDensityPlot, you can also get the idea about the norm of the vector field as well. Lighter the background implies bigger is the vector field. StreamDensityPlot is an
alternate to VectorPlot
Module 3 - Visualization and functions.nb 17
StreamDensityPlot{x, y}, {x, - 4, 4}, {y, - 4, 4}, RegionFunction → Function{x, y, vx, vy, n}, x2 + y2 > 0.05
Example-2
Lets take a look at a 3-dimensional example:
4 4 4
v=xi+y j+z j
4 4 4 (17)
w = -y i + x j + z k
18 Module 3 - Visualization and functions.nb
VectorPlot3D[{x, y, z}, {x, - 4, 4}, {y, - 4, 4}, {z, - 4, 4}, VectorScale → 0.06]
-2
-4 2
0
-4
-2
-2
0
2
-4
4
Module 3 - Visualization and functions.nb 19
q 1
V (r) = (19)
4 π ϵ0 r - rq
Example: Dipole
Consider an electric dipole made by two charges +q and -q placed at origin and (a, 0). The electric field for this set-up is given by
4
q r q r-ai
E= - (20)
4 π ϵ0 r 3 4 π ϵ0 r - a 4i3
where in the second line we have written the result in terms of dimensionless X = x / a and Y = y / a.
20 Module 3 - Visualization and functions.nb
x x-1 y y
In[" ]:= fieldLines = StreamPlot - , - /. r → x2 + y2 /. r1 → (x - 1)2 + y2 ,
3 3 3 3
r r1 r r1
{x, -1, 2}, {y, -2, 2},
RegionFunction → Function{x, y, vx, vy, n}, x2 + y2 > 0.01 && (x - 1)2 + y2 > 0.01
0
Out[" ]=
-1
-2
For potential also we will non-dimensionalize and use the ContourPlot to create contour plots
q 1 q 1
V (r) = - 4
4 π ϵ0 r
4 π ϵ0 r - a i
(22)
Module 3 - Visualization and functions.nb 21
V 1 1 1 1
= -
= - ,
q
(r / a) r 4
4 π ϵ0 a - i 2
X +Y 2 2
( X - 1) + Y 2
a
1 1
In[" ]:= equiPotential = ContourPlot - /. r → x2 + y2 /. r1 → (x - 1)2 + y2 , {x, -1, 2}, {y, -2, 2}
r r1
Out[" ]=
(22)
22 Module 3 - Visualization and functions.nb
Out[" ]=
Module 3 - Visualization and functions.nb 23
Homework
1. Sketch the following functions, first on a piece of paper analyzing them for their zeros, divergences, extrema and asymptotes. Next cross-check your sketch by plotting
the function on Mathematica.
Hyperbolic functions:
1- x 1 1- x
7. ln x 8. ln(ln(x)) 9. ln(x) / x 10. ln(ex - 1) 11. ln 1+x 12. x
ln 1+x
2
13. e-x cos( x) 14. e-x sin(x) 15. e- x cos(x) 16. e- x sin(x) 17. x e-x 18. x - 1 + e-x
) x*12 ) x* 2
19. xx 20. x1/x 21. x)x* 22. )x* x 23. 24.
1+)x*12 e x +1
1 -1
1
25. e x 26. e x2 27. x-12 - x-6 28. cosh-1 (x) 29. coth-1 (x) 30. coth (x) -
x
2. Electric field lines of a quadrupole: Plot the electric field lines and equipotential surfaces for the quadrupolar configuration: four charges of same magnitude and alternating
sign on the corners of a square of side a, that is, +q at (0, 0) and (a, a) while -q at (a, 0) and (0, a). Use combination of StreamPlot and ContourPlot as shown in this lecture inside a
Show function.