




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Review for the matlab homework assignment in Calculus III.
Typology: Study Guides, Projects, Research
1 / 8
This page cannot be seen from the preview
Don't miss anything!





Problem 1a ......................................................................................................................................... 1 Problem 1b ........................................................................................................................................ 2 Problem 1c ......................................................................................................................................... 3 Problem 1d ........................................................................................................................................ 3 Problem 2a ......................................................................................................................................... 4 Problem 2b ........................................................................................................................................ 5 Problem 2c ......................................................................................................................................... 5 Problem 3a ......................................................................................................................................... 6 Problem 3b ........................................................................................................................................ 6 Problem 3c ......................................................................................................................................... 7 Problem 4 .......................................................................................................................................... 7
Problem 1a
x = linspace(-1, 1, 100); y = linspace(-1, 1, 100); [X, Y] = meshgrid(x, y); Z = (Y.^3 + X.^2) .* exp(1 - X.^2 - Y.^2); surf(X, Y, Z); colorbar; xlabel('x'); ylabel('y'); zlabel('f(x, y)'); title('Plot of f(x, y) = (y^3 + x^2) \cdot e^{1 - x^2 - y^2}');
Problem 1b
x = linspace(-1, 1, 100); y = linspace(-1, 1, 100); [X, Y] = meshgrid(x, y); Z = (Y.^3 + X.^2) .* exp(1 - X.^2 - Y.^2); levels = [0, 0.5, 1]; contour(X, Y, Z, levels); colorbar; xlabel('x'); ylabel('y'); title('Level Curves of f(x, y) = (y^3 + x^2) \cdot e^{1 - x^2 - y^2}');
Problem 2a
x = linspace(-2, 2, 100); y = linspace(-2, 2, 100); [X, Y] = meshgrid(x, y); Z = X .* sin(2 * Y) - Y .* sin(Y .* X); surf(X, Y, Z); colorbar; xlabel('x'); ylabel('y'); zlabel('f(x, y)'); title('Plot of f(x, y) = x sin(2y) - y sin(yx)');
Problem 2b
syms x y
f = xsin(2y) - ysin(yx);
grad = jacobian(f, [x, y]);
Problem 2c
syms x y
f = xsin(2y) - ysin(yx); grad = jacobian(f, [x, y]);
grad_value = subs(grad, [x, y], [1, 1]);
grad_normalized = grad_value / norm(grad_value); direction_x = double(grad_normalized(1)); direction_y = double(grad_normalized(2));
Problem 3c
syms x y
f = x^2y - y^3 + xy;
fxx = simplify(diff(diff(f, x), x)); fxy = simplify(diff(diff(f, x), y)); fyy = simplify(diff(diff(f, y), y)); critical_points = solve([diff(f, x) == 0, diff(f, y) == 0], [x, y]);
for i = 1:length(critical_points) point = [critical_points.x(i), critical_points.y(i)]; Hessian = [subs(fxx, [x, y], point), subs(fxy, [x, y], point); subs(fxy, [x, y], point), subs(fyy, [x, y], point)]; eigenvalues = eig(Hessian);
if all(eigenvalues > 0) disp(['Relative Minimum at point (', char(point(1)), ', ', char(point(2)), ')']); elseif all(eigenvalues < 0) disp(['Relative Maximum at point (', char(point(1)), ', ', char(point(2)), ')']); elseif any(eigenvalues > 0) && any(eigenvalues < 0) disp(['Saddle Point at point (', char(point(1)), ', ', char(point(2)), ')']); else disp(['Inconclusive at point (', char(point(1)), ', ', char(point(2)), ')']); end end
Saddle Point at point (0, 0)
Problem 4
syms x y z lambda
M = xz - x^2 - 2y + 5; constraint = x^2 + y^2 + z^2 - 25;
L = M - lambda*constraint;
dL_dx = diff(L, x); dL_dy = diff(L, y); dL_dz = diff(L, z);
sol = solve(dL_dx == 0, dL_dy == 0, dL_dz == 0, constraint);
disp('The point(s) on the surface where M is minimal:'); for i = 1:length(sol.x) point = [sol.x(i), sol.y(i), sol.z(i)];
disp(point); end
The point(s) on the surface where M is minimal: [0, -5, 0]
[0, 5, 0]
[(4(5/2 - (32^(1/2))/4)^(3/2))/3 - (7(5/2 - (32^(1/2))/4)^(1/2))/3, - 22^(1/2) - 2, -(5/2 - (32^(1/2))/4)^(1/2)]
[(4((32^(1/2))/4 + 5/2)^(3/2))/3 - (7((32^(1/2))/4 + 5/2)^(1/2))/3, 22^(1/2) - 2, -((32^(1/2))/4 + 5/2)^(1/2)]
[(7(5/2 - (32^(1/2))/4)^(1/2))/3 - (4(5/2 - (32^(1/2))/4)^(3/2))/3, - 22^(1/2) - 2, (5/2 - (32^(1/2))/4)^(1/2)]
[(7((32^(1/2))/4 + 5/2)^(1/2))/3 - (4((32^(1/2))/4 + 5/2)^(3/2))/3, 22^(1/2) - 2, ((32^(1/2))/4 + 5/2)^(1/2)]
Published with MATLAB® R2022a