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

Matlab 7

Uploaded by

Babzch Kan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Matlab 7

Uploaded by

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

Name: Fawaz Khan

Reg.no:24BLC1355

MATLAB ASSIGNMENT-7

AIM:

1.) Consider any pair of 2-D functions of your choice. Visualize their
vector fields. Compute the cross product of the chosen vectors. Plot them
in the same figure and draw inferences from it.

2.) Choose any three-variable functions. Visualize its contour plot.


Compute its gradient and plot the vector field in the same figure as the
contour plot. Draw your inferences from it.

PROGRAM:

1.) clc
clear all
close all
syms x y z
F1 = [2*x,10*y,0*z];
F2 = [7*x,4*y,0*z];
P = inline(vectorize(F1(1)), 'x', 'y');
Q = inline(vectorize(F1(2)), 'x', 'y');
x = linspace(-1, 1, 10);
y = x;
[X,Y] = meshgrid(x,y);
z = zeros(size(X));
U = P(X,Y);
V = Q(X,Y);
W = zeros(size(X));
quiver3(X,Y,z,U,V,W,1.5)
hold on
axis on

J = inline(vectorize(F2(1)), 'x', 'y');


K = inline(vectorize(F2(2)), 'x', 'y');
[X,Y] = meshgrid(x,y);
z = zeros(size(X));
M = J(X,Y);
N = K(X,Y);
O = zeros(size(X));
quiver3(X,Y,z,M,N,O,1.5)
hold on
axis on

cro = cross(F1,F2)
D = inline(vectorize(cro(3)),'x','y')';
UU = zeros(size(X));
VV = zeros(size(X));
WW = D(X,Y);
quiver3(X,Y,z,UU,VV,WW,1.5)
xlabel('x')
ylabel('y')
zlabel('z')
2.) clc
clear all
close all
syms x y z
f = 3*x.^3-4*y.^2+8*z.^2;
G = gradient(f)
x = linspace(-100,100,100);
y=x;
z=x;
[X,Y] = meshgrid(x,y);
Z = (-3*X.^3+4*Y.^2)/8;
contour3(Z,200)
axis on
hold on
P = inline(vectorize(G(1)),'x','y','z')
Q = inline(vectorize(G(2)),'x','y','z')
R = inline(vectorize(G(3)),'x','y','z')
x = linspace(-100,100,10);
y=x;
z=x;
[X,Y,Z] = meshgrid(x,y,z);
U = P(X,Y,Z);
V = Q(X,Y,Z);
W = R(X,Y,Z);
quiver3(X,Y,Z,U,V,W,1.5)
axis on
xlabel('x')
ylabel('y')
zlabel('z')
title('f(x,y,z)=3x^2-4y^2+8z^2')
OUTPUT:

1.) Cross product:


2.) Gradient:
CONCLUSION:

In this assignment, we explored vector field visualization, cross products


in 2D, and gradient vector fields for a 3-variable function using MATLAB.

For question 1, we visualized two arbitrary 2D vector fields and


computed their cross product. The resulting plot provided a clear
depiction of the two fields and their interaction. The analysis showed that
the magnitude of the cross product was highest where the vectors were
most orthogonal, indicating strong rotational influence at those points.
Conversely, when the vectors were parallel, the cross product was zero,
indicating no rotational component.

For question 2, we chose a three-variable function and plotted its contour


plot alongside its gradient vector field. The contour plot displayed the
levels of the function, while the gradient field indicated the direction of
the steepest ascent at each point. The superimposed plot revealed that
the gradient vectors were perpendicular to the contour lines, confirming
the property that the gradient is normal to level surfaces. The magnitude
of the gradient vectors was larger in regions where the contour lines
were closer together, indicating a steep slope.

Overall, this assignment provided a deeper understanding of vector


fields, cross products, and gradients. The visualizations effectively
demonstrated key properties like orthogonality in cross products and the
relationship between gradient vectors and contour lines. This practical
application reinforced the concepts learned in vector calculus,
highlighting the power of MATLAB for visual analysis of mathematical
functions and vector operations.

You might also like