10.Gradient divergence curl
10.Gradient divergence curl
Mathematical form:
F =⃗
Draw the two dimensional vector field for the vector ⃗ f 1(x, y) + ⃗
f 2(x,y)
MATLAB Code:
clc
clear all;
syms x y
x = linspace(-10, 10, 10);
y = linspace(-10, 10, 10);
[x,y] = meshgrid(x,y);
U = input('enter the vector as i component:');
V = input('enter the vector as j component:');
quiver(X,Y,U,V)
axis on
xlabel('x')
ylabel('y')
Output:
In the Command window:
1.2
0.8
0.6
0.4
y
0.2
-0.2
-0.2 0 0.2 0.4 0.6 0.8 1 1.2
x
Example 2:
Draw the three dimensional vector field for the vector x i⃗ - y ⃗j + z ⃗k
MATLAB Code:
clear all;
clc;
syms x y z
x = linspace(-10, 10, 10);
y = linspace(-10, 10, 10);
z = linspace(-10, 10, 10);
[X,Y,Z] = meshgrid(x,y,z);
U = input('enter the vector as i component:');
V = input('enter the vector as j component:');
W = input('enter the vector as k component:');
quiver3(X,Y,Z,U,V,W)
axis on
xlabel('x')
ylabel('y')
zlabel('z')
Output:
In the Command Window:
1.
0.
z 0
-0.5
-1
-1.5
1
0. 2
0 1
0
-0.5 -1
Example 3: y -1 -2
x
Find the gradient vector field of f ( x , y )=x 2 y − y 3 . Plot the gradient vector field together with a
contour map of f. How are they related?
MATLAB Code:
clc
clear all
syms x y
f=input('enter the function f(x,y):');
F=gradient(f)
P = inline(vectorize(F(1)), 'x', 'y');
Q = inline(vectorize(F(2)), 'x','y');
x = linspace(-2, 2, 10);
y = linspace(-2, 2, 10);
[X,Y] = meshgrid(x,y);
U = P(X,Y);
V = Q(X,Y);
quiver(X,Y,U,V,1)
axis on
xlabel('x')
ylabel('y')
hold on
ezcontour(f,[-2 2])
Output:
Command Window:
x^2*y-y^3
Inference:
The gradient vectors are orthogonal to the contours.
Example 4
Find (a) the curl and (b) the divergence of the vector field.
Matlab code
clc
clear all
syms x y z real
F=input('enter the vector as i, j and k order in vector form:')
curl_F = curl(F, [x y z])
div_F = divergence(F, [x y z])
Output:
x*z^2 - x*y^2
y*x^2 - y*z^2
- z*x^2 + z*y^2
div_F =
6*x*y*z
Example 5
Matlab code
clc
clear all
syms x y z real
F=input('enter the vector as i,j and k order in vector form:')
curl_F = curl(F, [x y z])
if(curl_F ==[0 0 0])
f = potential(F, [x y z])
else
sprintf('curl_F is not equal to zero')
end
Output:
the vector as i,j and k order in vector form:
[y^2*z^3 2*x*y*z^3 3*x*y^2*z^2]
curl_F =
0
0
0
f =
x*y^2*z^3
Exercise
1. Plot the gradient vector field of f together with a contour map of f . Explain how they are
related to each other
(a) f =sin( x)+sin( y) (b) f =sin( x+ y) (c) f =x 2+ y 2
2.
Determine whether or not the vector field is conservative.
If it is conservative, find a function f such that .