0% found this document useful (0 votes)
83 views

Workshop 1 - Vector Fields: 1 Coordinate Systems and Vectors

The document describes coordinate systems and vector representations in MATLAB. It discusses rectangular, cylindrical, and spherical coordinate systems. It then demonstrates how to visualize vector fields and surfaces in MATLAB, including: 1) Plotting the surface z=x^2+2y^2, which is an ellipsoid, and its contours. 2) Computing and plotting the gradient vector field of this surface, which is parallel to the contours. 3) Deriving the tangent vector field to the contours from implicit differentiation.

Uploaded by

Pruthvi Ninganur
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views

Workshop 1 - Vector Fields: 1 Coordinate Systems and Vectors

The document describes coordinate systems and vector representations in MATLAB. It discusses rectangular, cylindrical, and spherical coordinate systems. It then demonstrates how to visualize vector fields and surfaces in MATLAB, including: 1) Plotting the surface z=x^2+2y^2, which is an ellipsoid, and its contours. 2) Computing and plotting the gradient vector field of this surface, which is parallel to the contours. 3) Deriving the tangent vector field to the contours from implicit differentiation.

Uploaded by

Pruthvi Ninganur
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

ELEN30011 Electrical Device Modelling

Workshop 1 - Vector fields

1 Coordinate systems and vectors


In representing vectors in three dimensional Euclidean space R, three common coordinate
systems are used, namely, rectangular, cylindrical, and spherical coordinate systems. Each
of these coordinate systems is defined in terms of three unit vectors and three corresponding
coordinates. Figures 1, 2 and 3 illustrate respectively these three systems.
• Coordinate systems.
• Rectangular (Euclidean).
−−→ −−→
Vector v = OQ − OP = vx x̂ + vy ŷ + vz ẑ

Q

v
x̂ P ŷ

Components
O
vx = v · x̂
vy = v · ŷ
vz = v · ẑ

Figure 1: Rectangular coordinate system.

ELEN30011 EDM - Topic 04

Tasks
1. Rewrite the following spherical coordinates (r, φ, θ) in rectangular coordinates:

(a) (1, 0, 0).


(b) (1, π, 0).
(c) (1, 0, π/2).

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 · ẑ

Figure 2: Cylindrical coordinate system.

ELEN30011 EDM - Topic 04

(d) (0, −π, π).


(e) (−1, 0, 0).

2. Rewrite the following rectangular coordinates (x, y, z) in spherical coordinates.

(a) (1, 0, 0).


(b) (0, 1, 0).
(c) (0, 0, 1).
(d) (0, 1, 1).

3. In general, a vector v in three dimensional space may be expressed in rectangular and


cylindrical coordinates respectively by

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).

(a) Show that


     
vx vr cos φ − sin φ 0
 vy  = T (φ)  vφ  , .
where T (φ) =  sin φ cos φ 0 
vz vz 0 0 1

(b) Show that det T (φ) = 1.

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 · θ̂

Figure 3: Spherical coordinate system.


ELEN30011 EDM - Topic 04

(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, φ, θ).

(a) Determine the magnitude of the electric field at P .


(b) Derive an expression for r̂ in terms of the rectangular unit vectors x̂, ŷ, and ẑ.
(c) Determine the electric field in the ẑ direction at P .
(d) Sketch the vector field surrounding O.

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

Figure 4: Contours and vector field T.

(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
!

"$%

"

#$%

!#$%

!"

!"$%

!!
!

" !
"
#
#
!"
!"
!! !!

Figure 5: Vector field ∇F (x, y, z) and ellipsoidal contour η = 1.

(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

Figure 6: Vector field ∇F (x, y, z).

You might also like