Professional Documents
Culture Documents
EE361 Lab 1
Vector analysis with MATLAB
1. Exercise 1: Get used to MATLAB
Please read description below and input the codes into your MATLAB con-sole to confirm the
results.
1.1 Declaring three dimensional Cartesian vectors
A vector A= A x ^x + A y ^y + A z ^z is specified in MATLAB by giving the x,
1.2 Addition
Addition of two or more vectors are given by:
1.3 Subtraction
Subtraction of two vectors is given by:
1.4 Magnitude
Magnitude of a vector is given by the norm function
Result:
→This line creates a 2-D mesh of (x, y) with x = -2, -1.75, …, -0.25, 0, 0.25, …, 1.75, 2 and y =
-2, -1.75, …, -0.25, 0, 0.25, …, 1.75, 2.
→ These two lines calculate value of the x-component A x and the y-component A y of the vector
field A.
(The only new command is clear all; which help to delete all old data to prevent possible errors
in the calculations)
The plot:
Answer:
- They are the same.
6. Exercise 6: Calculate Rotation (curl)
Rotation or curl of a vector field (∇ × A ) can be calculated by using curl function. The following
program calculate rotation of the vector field A by the command
curlA = curl(x,y,Ax, Ay);
and plot the rotation by the command
pcolor(x , y , curlA);
Input the following commands into a new m-file the file, save with name curlA . m and run.
MATLAB code:
The plot:
Answer:
- We see that the vectors converge in the yellow areas, and spread out in the blue area
- If a fluid flows in three-dimensional space along a vector field, the rotation of that fluid around
each point, represented as a vector, is given by the curl of the original vector field evaluated at
that point. The curl vector field should be scaled by a half if you want the magnitude of curl
vectors to equal the rotational speed of the fluid.
7. Exercise 7: Calculate Divergence
Divergence of a vector field (∇. A) can be calculated by using divergence function. Create a new
m-file ex6.m and copy all the program in Exercise 6 into this new file. After that, use the
divergence function and change two lines in the program to calculate and plot the divergence of
the vector field A.
MATLAB code:
The plot:
Answer:
- The vectors spread out in the yellow areas, and converge in the blue area
- The divergence represents the volume density of the outward flux of a vector field from an
infinitesimal volume around a given point.