0% found this document useful (0 votes)
8 views2 pages

MATLAB Calculus Lab: Gradients & Plots

Uploaded by

muppalaraghu552
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

MATLAB Calculus Lab: Gradients & Plots

Uploaded by

muppalaraghu552
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Amrita School of Engineering, Bengluru-35

23MAT107
Calculus
Lab Practice Sheet-8
(Gradient, Hessian, Jacobian, Divergence and Curl, contour and
vector/quiver plot using MATLAB)
• Gradient, Hessian, Jacobian, Divergence and Curl
syms x y z;

X = [x y z];
F = x^2 + 3*y^2-5*z;
V = [x^3+y, y^3+z, z^3+x];

Grad = gradient(F, X)
H = det(hessian(F, X))
Div = divergence(V, X)
Curl = curl(V, X)
J = det(jacobian(V, X))

• Contour curves/ level curves


x = linspace(-2*pi,2*pi);
y = linspace(0,4*pi);
[X, Y] = meshgrid(x, y);
Z = sin(X)+cos(Y);
contour(X, Y, Z) % contour curves for the function f(x, y)=sin(x)+cos(y)

NOTE
➢ contour(X, Y, Z, 50) can be used to get fixed number of contour curves/ level
curves.
➢ contour(X, Y, Z,'--') can be used to get contour curves in – style.
➢ contour(X, Y, Z, 'ShowText','on') can be used to write the values of the function
on the curves.

• Vector/Quiver plot

x = -2:.2:2;
y = -2:.2:2;
[x, y] = meshgrid(x, y);
z = x.^2 + y.^2;
figure
[px, py] = gradient(z);
contour(x, y, z,'ShowText','on'), hold on
quiver(x, y, px, py), axis image
Practice Questions
1. Find the gradient and Hessian of the following scalar function using MATLAB
command
a. 𝑓(𝑥, 𝑦, 𝑧) = 4𝑥 3 𝑒 𝑥𝑦 − 𝑦 3 𝑧
b. 𝑔(𝑥, 𝑦, 𝑧) = 𝑒 𝑥𝑦 (𝑥 + 𝑦) at 𝑃: (−1, 1)
c. ℎ(𝑥, 𝑦, 𝑧) = (𝑥 2 + 𝑦 2 )/(𝑥 2 − 𝑦 2 )
2. Find the divergence, curl and Jacobian of the following vector functions using
MATLAB command
a. 𝑈(𝑥, 𝑦, 𝑧) = 𝑥 2 𝑦𝑖̂ + 𝑥𝑗̂ + 2𝑦𝑧𝑘̂ at 𝑃: (2, −3, 5)
b. 𝑉(𝑥, 𝑦, 𝑧) = log⁡(𝑥𝑦𝑧)[𝑥, 𝑦, 𝑧]
3. Find the Laplacian of the function 𝑓(𝑥, 𝑦, 𝑧) = (𝑥 2 + 𝑦 2 + 𝑧 2 )−1 at 𝑃: (1, 1, 1) using
MATLAB command.
4. Plot the level curves for the function: 𝑓(𝑥, 𝑦) = 4𝑥 2 + 9𝑦 2 − 72 with function values
written in each curve in −10 ≤ 𝑥, 𝑦 ≤ 10.
5. Sketch the quiver plot for the function: 𝑓(𝑥, 𝑦) = 9𝑥 2 − 16𝑦 2 with function values
written in each curve in −10 ≤ 𝑥, 𝑦 ≤ 10.

You might also like