You are on page 1of 9

The University of Da Nang

Da Nang University of Technology

EE361 LAB REPORT


APPLIES ELECTROMAGNETICS

Instructor: Thai Vu Hien


Team member: Hoang Thi Hanh Phuc
Nguyen Thi Quynh Anh

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,

y, and z components in between square brackets: [ A x , A y, A z]


Example: Suppose we have three vectors
A=2 ^x +3 ^y -1 ^z , B=1 ^x +0 ^y +3 ^z , C =0 ^x -1 ^y +0 ^z
MATLAB code:

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

1.5 Dot product


Dot product of two vectors is calculated by using the dot function
1.6 Cross product
Cross product of two vectors is calculated by using the dot function

2. Exercise 2: Use MATLAB for analysis


MATLAB code:

Result:

3. Exercise 3: Learn to plot a vector field


MATLAB code:
Figure 1: A plot of vector filed A(x, y) = cos(x+2y) ^x +sin(x-2y) ^y

Meanings of each line are as follows:

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

→ These two lines plot the vector field A.

→ This line adds title for the figure


4. Exercise 4: Plot a vector field by yourself
Referee to process in exercise 3 and plot the vector field B=( x+2y) ^x +(3x+y) ^y on a 2-D mesh of
(x, y) with x = 0, 0.5, …, 4 and y = 0, 0.5, …,4.
MATLAB code:
The plot:

5. Exercise 5: Using .m file


An m-file or script file is a simple text file where you can place MATLAB commands. When the
m-file is run, MATLAB reads the commands and executes them exactly as it would if you had
typed each command sequentially at the MATLAB prompt. Now, go to EDITOR>New to create
a new m-file. Input the following commands into the file to plot again the vector field A in
Exercise 3.
MATLAB code:

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

You might also like