LABORATORY MODULE EKT 241/4 ELECTROMAGNETIC THEORY Semester 2 (2009/2010) EXPERIMENT # 2 Vector Analysis: Gradient And Divergence Of A Scalar And Vector Field NAME MATRIK # signature DATE PROGRAMME GROUP School of Computer & Communication Engineering University of Malaysia Perlis - 1 -
EXPERIMENT 2 Vector Analysis: Gradient And Divergence Of A Scalar And Vector Field 1. OBJECTIVE: 1.1 To provide you with an introduction to solve the problem manually and applying divergence in SCILAB simulation. In this experiment you will generate 2D space varying, gradient of a scalar field and divergence of a vector field. 2. LECTURE REVIEW We first consider the posit ion vector, r : r = x a + y a + z a x y z where a, a, and a are rectangular unit vectors. Since the unit vectors for x y z rectangular coordinate are constants, the differential distances d x, d y and d z are the components of the differential distance vector d r: dr = dx a + dy a + dz a. x y z The operator, del: is defined to be (in rectangular coordinates) as: This operator operates as a vector. = / x a + / y a + / z a, x y z - 2 -
2.1 Gradient: If the del operator, operates on a scalar function, f(x,y,z), we get the gradient : f= ( f/ x) a + ( f/ y) a + ( f/ z) a x y z Gradient is a vector with the magnitude and direction of t he maximum change of the function in space. We can relate the gradient to t he differential change in the function: df = ( f/ x) d x + ( f/ y) d y + ( f/ z) d z = f dr 2.2 Divergence: The divergence of a vector is defined to be: A= [ / x a + / y a + / z a ] [A a + A a + A a ] x y z x x y y z z A= ( A / x) + ( A / y) + ( A / z) x y z Gauss theorem or divergence theorem states that t he total outward flux of a vector field A the closed surface S is the same as the volume integral of the divergence of A: c l o se d su r f ac e A ds = AdV where the vector S is the surface area vector and Ais called divergence of A(div A). - 3 -
3. EXAMPLE 3.1 Gradient of a Scalar Field Using SCILAB simulation to plot a 3-D space varying and gradient of a scalar field for S=x 2 +3(x+y-1) 2 +(x+1) 2 for -2 < x < 2 and -2 < y < 2 3.2 Divergence of a Vector Field Using SCILAB simulation to plot a 2-D vector and divergence of a vector field for P= cos xy a - cos y a x y for -2 < x < 2 and -2< y < 2-4 -
4. SOLUTION FOR EXAMPLE 4.1 Gradient of a Scalar Field % Gradient of scalar field x=-2:0.2:2; y=-2:0.2:2; [xx,yy]=meshgrid (x,y); //For 3-D space varying S1=xx.^2; S2= 3*(xx+yy-1).^2; S3= (xx+1).^2; S=S1+S2-S3; surf(x,y,s, facecolor, interp )//3D surface plot xlabel('x');ylabel('y');zlabel('s'); title( 3-D space varying scalar field'); // For gradient, first of all, calculate the gradient for the above equation G1=((2*xx)+(6*(xx+yy-1))+(2*(xx+1)));//Enter the equation of the calculated gradient G2=6*(xx+yy-1); scf; champ(x,y,g1,g2,rect=[-0.5,-0.5,2,2]) xlabel('x'); ylabel('y'); title('gradient of the Scalar Field'); Figure 2.1 3-D space varying of scalar field - 5 -
Figure 2.2 Gradient of the scalar field 4.2 Divergence of a Vector Field % Divergence of a vector field x=-2:0.2:2; y=-2:0.2:2; [xx,yy]=meshgrid (x,y); m=size(xx); Px=cos(xx.*yy); Py=cos(yy.^2); P=Px-Py; scf; champ(x,y,px,py,rect=[-0.5,-0.5,2,2]) xlabel('x'); ylabel('y'); title('2-d vector field'); //For divergence, first of all, calculate the divergence for the above equation D1=(-yy.*(sin(xx.*yy)));//Enter the equation of the calculated divergence D2=sin(yy); scf; D=D1+D2; plot3d(x,y,d)//3d plot of a surface xlabel('x'); ylabel('y'); - 6 - zlabel('d'); title('divergence of vector field');
Figure 2.3 2-D vector field Figure 2.4 Divergence of vector field - 7 -
5. EXERCISE 5.1 Plot a 3-D space varying and gradient of a scalar field using SCILAB for: 5.1.1 A=cos (xy) + 2x + sin (xy) for 0 < x < 3.5 and 0 <y < 3.5 SCILAB result and source code: - 8 -
5.2 Plot a 2-D vector and divergence of a vector field using SCILAB for: 5.2.1 B= e -2 y (sin 2 x a - cos 2 x a ) for -2 < x < 2 and -2 < y < 2 SCILAB result and source code: x y - 9 -
5.3 Find the gradient of a scalar field 2 5.3.2 U= ρ z cos 2ø Calculation: 5.3.3 S = x 2 y + xyz Calculation: - 10 -
5.4 Find the divergence f these vector fields. 5.4.1 Q= x 2 yz a + xz a x z Calculation : 2 5.4.2 P = ρ sin ø aρ + ρ z aø + z cos ø az Calculation : - 11 -
6. DISCUSSION 7. CONCLUSION - 12 -