%% MATLAB 2 (NAME)

%% Example 
% This is to illustrate how you shoud present your answer. DELETE this part
% before uploading your work!
% Find the area above the graph of $$m(x)=6-5x+x^2$$
clear all;
syms x;
m=6-5*x+x^2;  %use ";" when you don't want that in your output"
bounds=solve(m==0)
area=-int(m,x,bounds)
%% Problem 1: 
% Plot the function $$f(x, y) = \sqrt{x^2 + 4y^2}$$ View: (10, 10, 10)

[x, y] = meshgrid(-10:0.5:10, -10:0.5:10);

% Define the function
f = sqrt(x.^2 + 4*y.^2);

% Plot the surface
figure;
surf(x, y, f);
xlabel('x');
ylabel('y');
zlabel('f(x, y)');

% Set the title with LaTeX interpreter for square root symbol
title({'Plot of $$f(x, y) = \sqrt{x^2 + 4y^2}$$'}, 'Interpreter', 'latex');

% Set the viewing angle
view(10, 10);

%% Problem 2: 
% Plot the level curves of $$f(x, y) = \sqrt{4 - 2x^2 - y}$$ with the View: (10, 10, 10)
clear all;

%% Problem 3: 
% Plot the surface $$y = 9 - 2x^2$$ with the View: (10, 10, 10)
clear all;

%% Problem 4: 
% Let $$f(x, y) = y  \sin(x^3  y^4)  \exp(x^2  y)$$, compute $$\frac{\partial f}{\partial y}$$ and $$\frac{\partial^2f}{\partial x\partial y}$$ 
clear all;

%% Problem 5: 
% Let $$f(x, y) = x^2  \ln(xy) + x^2  y^2$$, find ∇f(x, y) 
clear all;

%% Problem 6: 
% Let $$f(x, y) = \frac{y}{x^2} + \sin(\pi  x y)$$, find ∇f(1, 1)
clear all;

%% Problem 7: 
% Find the directional derivative of $$f(x, y) = x^4 - y^3$$ at $$(1, 1)$$ in the direction of $$a = 2i + 3j$$
clear all;

%% Problem 8: 
% Find all the critical points for $$f(x, y) = (y - 2)  \ln(xy)$$
clear all;

%% Problem 9: 
% Use Lagrange multipliers to find the maximum and minimum values of $$f(x, y) = xy^2 $$ subject to the constraint $$x^2 + y^2 = 16$$
clear all;

