% Problem 14.8.16: Max/min with two constraints % o = [0,0,0]; % origin will be shifted otherwise we won't see the arrows inside our ellipsoid arrow3(o, [1,0,0],'yellow'); arrow3(o, [0,1,0],'yellow'); arrow3(o, [0,0,1],'magenta'); % this plots the i,j,k, vectors ymin = 0; ymax = 4; % plotting window %% Example 1. Elliptic paraboloid % % its equation is z = x^2 + y^2 % in fact, even to plot the cylinder, we need to use these dtheta = pi/48; r = 1; [theta,Y] = meshgrid(0:dtheta:2*pi, ymin:0.2:ymax); X = r*cos(theta); Z = r*sin(theta)/sqrt(2); surf(X,Y,Z,'FaceColor',[1 1 0.8]); % surface plotting % now plot x + y -z = 0 plane dy= 0.2; [Y,Z ] = meshgrid(-1:dy:ymax, -1:dy:1); X = Z - Y; surf(X,Y,Z,'FaceColor',[1 0.8 0.8]); %% plot their intersection t = 0:dtheta:2*pi; x = cos(t); z = sin(t)/sqrt(2); y = z - x; plot3(x,y,z,'r','LineWidth',3) %% now plot the level set for the f(x,y,z) = 3x - y - 3z = - 12/sqrt(6) X2 = (Y + 3*Z - 12/sqrt(6))/3; surf(X2,Y,Z,'FaceColor',[0.8 0.8 1]); t = 0:0.2:8; theta = t; x = r*cos(theta); y = r*sin(theta); z = t/2; hold on plot3(x,y,z,... 'LineWidth',2); hold off