Workshop 1 - Vector Fields: 1 Coordinate Systems and Vectors
Workshop 1 - Vector Fields: 1 Coordinate Systems and Vectors
Q
ẑ
v
x̂ P ŷ
Components
O
vx = v · x̂
vy = v · ŷ
vz = v · ẑ
Tasks
1. Rewrite the following spherical coordinates (r, φ, θ) in rectangular coordinates:
1
• Coordinate systems.
• Cylindrical.
−−→ −−→
Vector v = OQ − OP = vr r̂ + vφ φ̂ + vz ẑ
Q ẑ
v φ̂
P r̂
Radius
r Components
O r
vr = v · r̂
φ
vφ = v · φ̂
vz = v · ẑ
v = vx x̂ + vy ŷ + vz ẑ
v = vr r̂ + vφ φ̂ + vz ẑ
where (x̂, ŷ, ẑ) and (r̂, φ̂, ẑ) denote the unit vectors in each coordinate system (again respec-
tively).
2
• Coordinate systems.
• Spherical.
−−→ −−→
Vector v = OQ − OP = vr r̂ + vφ φ̂ + vθ θ̂
θ
Q r̂
v φ̂
P
θ̂
r
Components
O
vr = v · r̂
φ
vφ = v · φ̂
vθ = v · θ̂
(c) Write down expressions for r, cos φ, and sin φ in terms of x and y.
(d) By computing the inverse of matrix T (φ), derive an expression for vr and vφ in terms of
vx and vy . In particular, find an appropriately defined 3 × 3 matrix valued function T
of x and y such that
vr vx
vφ = T (x, y) vy .
vz vz
4. The electric field E associated with a point charge Q is located at the origin O of a three
dimensional space. In spherical coordinates, this electric field at a distance r from O is given
by
Q
E(r) = r̂ , (1)
4 π r2
where r̂ denotes the unit radial vector. A point P of interest is located at the spherical
coordinates (r, φ, θ).
3
2 Visualization of vector fields using MATLAB
MATLAB is a useful tool for visualization of surfaces, contours, vector fields, etc. The objective
in this section is to reproduce the figures of the type included in the lecture notes, using
MATLAB.
Tasks
.
1. A two dimensional surface is given by z = f (x, y), where f (x, y) = x2 + 2 y 2 .
(a) Start MATLAB. At the prompt, enter the x and y axis grids by typing the following:
x = -2:.05:2;
y = -2:.05:2;
[xx,yy] = meshgrid(x,y);
Determine the size of the xx matrix by typing
size(xx)
Do the same for yy.
(b) Using the following commands, compute and plot the function f over the aforementioned
grid, annotate with axis labels, and add a grid.
zz = xx.^2 + 2*yy.^2;
figure(1);
surfl(xx,yy,zz);
xlabel(’x’);
ylabel(’y’);
zlabel(’Function f(x,y)’);
grid on;
Describe the plotted surface, and nominate whether it is a paraboloid or ellipsoid.
(c) A contour c of the function f is the set of all points in (x, y) ∈ R2 such that f (x, y) = c.
By selecting c = 1 (for example), what shape do you expect the contours of f to take?
(d) Plot the contours of f in a separate figure.
figure(2);
contour(xx,yy,zz,20);
xlabel(’x’);
ylabel(’y’);
grid on;
What is the purpose of the last argument “20” in the contour command above?
(e) Show that the gradient of function f is
∇f = 2 x x̂ + 4 y ŷ
This gradient defines a vector field in R2 . In order to plot this vector field, the compo-
nents of ∇f must first computed across the entire grid. To do this, use the commands
4
fxx = 2*xx; fyy = 4*yy;
To see what this vector field looks like, plot it via
figure(3); quiver(xx,yy,fxx,fyy);
What is the problem with this plot?
(f) To fix the aforementioned problem, try the following commands:
xnew = -2:.25:2;
ynew = xnew;
[xxnew, yynew] = meshgrid(xnew,ynew);
fxxnew = 2*xxnew;
fyynew = 4*yynew;
figure(3);
quiver(xxnew,yynew,fxxnew,fyynew);
Does this help the problem seen in the previous part?
(g) Now overlay this vector field plot on top of the earlier contour plot.
figure(2);
hold on;
quiver(xxnew,yynew,fxxnew,fyynew);
By inspection of the overlaid plot obtained, what is the relationship between the gradient
vector field and the contours?
(h) A tangent vector to any contour may be obtained via implicit differentiation. Consider
the contour c defined by c = f (x, y), c constant, so that
c = x2 + 2 y 2 . (2)
Differentiate both sides with respect to x to obtain
dy
0 = 2x + 4y ,
dx
where the second term on the RHS is obtained via the chain rule. For y 6= 0, then define
. dy
T = 2 y x̂ + ŷ = 2 y x̂ − x ŷ , y 6= 0 .
dx
Following similar steps to that of (d) and (g), reproduce the Figure 4 below illustrating
the contours of function f and the vector field defined by T on the same axes.
Summarize the relationship between the vector field T and the contours of function f .
(i) Show explicitly that the tangent vector T is perpendicular to the gradient ∇f .
2. A three dimensional surface in R4 is given by η = F (x, y, z), where
1 2
F (x, y, z) = x2 + y 2 + z . (3)
4
The contour of this surface corresponding to η = 1 is a two dimensional surface in R3 . In
fact, the contour is an ellipsoid, as illustrated in Figure 5. The objective here will be to
reproduce this figure, including the vector field representing the gradient of F .
5
2.5
1.5
0.5
y
−0.5
−1
−1.5
−2
−2.5
−2.5 −2 −1.5 −1 −0.5 0 0.5 1 1.5 2 2.5
x
(a) Observe that the function F is non-negative everywhere. Show that the contour c2 of
surface F is in general given by
x 2 y 2 z 2
+ + = 1. (4)
c c 2c
Note that (4) is the general form for an ellipsoid (in R3 ) with radius c in the x and y
directions, and radius 2 c in the z direction.
(b) In order to plot this ellipsoid, the MATLAB command ellipsoid can be used. To see
how this command works, type
help ellipsoid
By inspection of (4) for c = 1, and on the help provided by the above command,
determine numerical values for the required arguments XC, YC, ZC, XR, YR, ZR, N
for the function ellipsoid. Plot the ellipsoid by typing
[xx,yy,zz] = ellipsoid(XC,YC,ZC,XR,YR,ZR,N);
figure(10);
surfl(xx,yy,zz);
xlabel(’x’); ylabel(’y’); zlabel(’z’)
grid on;
To reproduce the axes of Figure 5, type
axis([-2 2 -2 2 -2 2]);
(c) The gradient of function F is in general given by
∂F ∂F ∂F
∇F (x, y, z) = x̂ + ŷ + ẑ (5)
∂x ∂y ∂z
Explicitly compute the gradient of the function F given by (3).
6
!
"$%
"
#$%
!#$%
!"
!"$%
!!
!
" !
"
#
#
!"
!"
!! !!
(d) The vector field defined by (5) is defined everywhere in R3 . Plot the vector field using
the following commands:
x = -2:.5:2;
y = x; z = x;
[xx,yy,zz] = meshgrid(x,y,z);
Fxx = < insert your x̂ component of the gradient here, e.g. 3*xx - yy.*zz >;
Fyy = < insert your ŷ component of the gradient here >;
Fzz = < insert your ẑ component of the gradient here >;
figure(11);
quiver3(xx,yy,zz,Fxx,Fyy,Fzz);
You should obtain a plot similar to that shown in Figure 6.
(e) Replot the vector field defined by (5) using the following commands:
[xx,yy,zz] = ellipsoid(XC,YC,ZC,XR,YR,ZR,N);
Fxx = < insert your x̂ component of the gradient here, e.g. 3*xx - yy.*zz >;
Fyy = < insert your ŷ component of the gradient here >;
Fzz = < insert your ẑ component of the gradient here >;
figure(11);
quiver3(xx,yy,zz,Fxx,Fyy,Fzz); axis([-2 2 -2 2 -2 2]);
where XC, YC, ZC, XR, YR, ZR, N are as per (b). What is the key difference between
this plot and the one obtained in (d)?
(f) Using the various commands above, reproduce Figure 5.
7
2.5
1.5
0.5
0
z
−0.5
−1
−1.5
−2
−2.5
4
2
0
3
2
−2 1
0
−1
−4 −2
y −3
x