Mtalab 练习题(数学实验作业)
第四周数学实验作业
1、已知 z = log(x^2 +1) * y^2 +sin(x^3 y)+xy
(1)求Zx,Zxy,Zyy
syms x y z = log(x^2+1)*y^2+sin(x^3*y)+x*y; zx = diff(z,x) zxy = diff(zx,y) zyy = diff(z,y,2)
(2)(2)当x = 1,y = 2,dx = 0.02,dy = 0.03时,求dz
syms x y z = log(x^2+1)*y^2+sin(x^3*y)+x*y; zx = diff(z,x); zy = diff(z,y); x = 1;y = 2; zx = eval(zx); zy = eval(zy); dx = 0.02;dy = 0.03; dz = zx*dx+zy*dy
2、求曲面x^2 + 2y^2 + 3z^2 = 6在点(1,-1,-1)处的切平面和法线方程,并将曲面和切平面及其法线画在同一坐标窗口中。
syms x y z t F = x^2+2*y^2+3*z^2-6; %F = z-4/(x^2+y^2+1); Fx=diff(F,x);Fy=diff(F,y);Fz=diff(F,z); M = [x y z];M0=[1 -1 -1]; %M = [x y z];M0=[1/4 1/2 64/21] Fx0=subs(Fx,M,M0);Fy0=subs(Fy,M,M0);Fz0=subs(Fz,M,M0); N0 = [Fx0,Fy0,Fz0]; %计算法向量 eqTplane = dot(N0,M-M0) %计算切平面 eqNcurvex = M0(1)+Fx0*t %法线方程 eqNcurvey = M0(2)+Fy0*t eqNcurvez = M0(3)+Fz0*t [x, y, z] = ellipsoid(0,0,0,sqrt(6),sqrt(3),sqrt(2),50); surfl(x, y, z); colormap copper; axis equal; hold on syms z z = solve(eqTplane,z); %求出切平面方程 ezsurf(z) %绘制切平面 axis([-4 4 -2 2 -2 2]); hold on t = 0:0.2:10; x = eval(eqNcurvex);y = eval(eqNcurvey);z = eval(eqNcurvez); plot3(x,y,z) %绘制法线 view(30,5)
我也不知道怎么做到这么丑的
3、对于二元函数z = 2xy - 3x^2 - 2y^2 + 10
(1)利用导数求其极值
syms x y z = 2*x*y - 3*x^2 - 2*y^2 + 10; zx = diff(z,x);zy = diff(z,y); [x0,y0]=solve(zx,zy,x,y); %驻点[x0 y0]=[0,0] zxx=diff(zx,x);zxy=diff(zx,y);zyy=diff(zy,y); xmax=[];xmin=[]; for k=1:length(x0) A=subs(zxx,[x,y],[x0(k),y0(k)]); B=subs(zxy,[x,y],[x0(k),y0(k)]); C=subs(zyy,[x,y],[x0(k),y0(k)]); delta=double(A*C-B^2); if delta>0 if double(A)<0 xmax=[xmax;[x0(k),y0(k)]]; else xmin=[xmin;[x0(k),y0(k)]]; end end if ~isempty(xmax) zmax=subs(z,[x y],[xmax(:,1),xmax(:,2)]); else zmax=[]; end if ~isempty(xmin) zmin=subs(z,[x y],[xmin(:,1),xmax(:,2)]) else zmin=[]; end end disp('极大值点和极大值是:') [xmax zmax] disp('极小值点和极小值是:') [xmin zmin]
(2)画出等高线图和梯度向量场观察其极大值
x = -4:0.2:3;y=-3:0.2:3; [x,y]=meshgrid(x,y); z = 2.*x.*y - 3.*x.^2 - 2.*y.^2 + 10; figure mesh(x,y,z) figure contour(x,y,z,50) hold on grid on [px,py]=gradient(z,0.2,0.2); quiver(x,y,px,py)
高线图和梯度向量场可以看出,函数的极大值点为(0,0)
(3)利用 fminsearch 求其极大值。
z = @(x)2*x(1).*x(2) - 3*x(1).^2 - 2*x(2).^2 + 10; [xmin,zmin]=fminsearch(z,rand(1,2)); z = @(x)-(2.*x(1).*x(2) - 3.*x(1).^2 - 2.*x(2).^2 + 10); [xmax,z1]=fminsearch(z,rand(1,2)); zmax=-z1