Error in T12 (line 35) surf(X, Y, fplot) and I have no idea what I was wrong
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
KSSV
on 17 May 2022
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 Comments
More Answers (0)
See Also
Categories
Find more on Number Theory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!