Error in T12 (line 35) surf(X, Y, fplot) and I have no idea what I was wrong
1 次查看(过去 30 天)
显示 更早的评论
clc
clear
close all
syms x y
f = @(x,y)(x.^2+y.^2+x.*y-12*log(x)-10*log(y));
fx = diff(f,x);
fy = diff(f,y);
[xc,yc] = solve(fx,fy,x,y,'real',true);
[m,n] = size([xc,yc]);
fxx = diff(fx,x);
fyy = diff(fy,y);
fxy = diff(fx,y);
D = fxx*fyy - fxy^2;
%print
for i = 1:m
if subs(D,{x,y},{xc(i),yc(i)}) > 0
if subs(fxx,{x,y},{xc(i),yc(i)}) > 0
fprintf('(%f,%f,%f) is local minimum\n',xc(i),yc(i),f(xc(i),yc(i)));
else
fprintf('(%f,%f,%f) is local maximum\n',xc(i),yc(i),f(xc(i),yc(i)));
end
elseif subs(D,{x,y},{xc(1),yc(1)}) < 0
fprintf('(%f,%f,%f) is saddle point\n',xc(i),yc(i),f(xc(i),yc(i)));
else
fprintf('(%f,%f,%f) is unknown\n',xc(i),yc(i),f(xc(i),yc(i)));
end
end
%Sketch
xx = linspace(-1.2, 1.2, 100);
yy = linspace(-1.2, 1.2, 100);
[X,Y] = meshgrid(xx, yy);
fplot = X^2+Y^2-12*log(X)-10*log(Y)+X*Y;
figure
surf(X, Y, fplot)
hold on
for i = 1:m
plot3(xc(i),yc(i),f(xc(i),yc(i)),'r*')
end
0 个评论
采纳的回答
KSSV
2022-5-17
clc
clear
close all
syms x y
f = @(x,y)(x.^2+y.^2+x.*y-12*log(x)-10*log(y));
fx = diff(f,x);
fy = diff(f,y);
[xc,yc] = solve(fx,fy,x,y,'real',true);
[m,n] = size([xc,yc]);
fxx = diff(fx,x);
fyy = diff(fy,y);
fxy = diff(fx,y);
D = fxx*fyy - fxy^2;
%print
for i = 1:m
if subs(D,{x,y},{xc(i),yc(i)}) > 0
if subs(fxx,{x,y},{xc(i),yc(i)}) > 0
fprintf('(%f,%f,%f) is local minimum\n',xc(i),yc(i),f(xc(i),yc(i)));
else
fprintf('(%f,%f,%f) is local maximum\n',xc(i),yc(i),f(xc(i),yc(i)));
end
elseif subs(D,{x,y},{xc(1),yc(1)}) < 0
fprintf('(%f,%f,%f) is saddle point\n',xc(i),yc(i),f(xc(i),yc(i)));
else
fprintf('(%f,%f,%f) is unknown\n',xc(i),yc(i),f(xc(i),yc(i)));
end
end
%Sketch
xx = linspace(-1.2, 1.2, 100);
yy = linspace(-1.2, 1.2, 100);
[X,Y] = meshgrid(xx, yy);
Z = X.^2+Y.^2-12*log(X)-10*log(Y)+X.*Y; %<---- element by element operations
figure
surf(X, Y, abs(Z))
hold on
for i = 1:m
plot3(xc(i),yc(i),f(xc(i),yc(i)),'r*')
end
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Number Theory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!