identifying the critical points of a bivariate function

조회 수: 6 (최근 30일)
ektor
ektor 2020년 3월 9일
답변: Vedant Shah 2025년 6월 27일
Dear all,
I have this function below and I plotted it in a 3D space. Is it possible to mark the critical points on the graph so as to be visible to the reader? Similarly for the max or min value of the function?
Best
syms x y
f = 4*x.^2+3*y.^2 ;
fx = diff(f,x);
fy = diff(f,y);
[xc,yc] = solve(fx,fy,x,y); [xc,yc];
fxx = diff(fx,x); fxy = diff(fx,y); fyy = diff(fy,y);
D = fxx*fyy - fxy^2;
subs(D,{x,y},{xc(1),yc(1)});
subs(fxx,{x,y},{xc(1),yc(1)});
figure(1); ezsurf(f,[-10,50,-10,50]);

답변 (1개)

Vedant Shah
Vedant Shah 2025년 6월 27일
Hi @ektor,
To mark the critical points on the 3D surface plot and classify whether each is a maximum, minimum, or saddle point, the following approach can be adopted:
Remove the following lines, as they are no longer necessary for evaluating the critical points individually:
subs(D,{x,y},{xc(1),yc(1)});
subs(fxx,{x,y},{xc(1),yc(1)});
Add the following block of code after plotting the surface using ezsurf. This section loops through each critical point, evaluates the second derivative test, classifies the point, and plots it with a label using ‘plot3’ function:
hold on
for k = 1:length(xc)
% Evaluate at each critical point
Dval = double(subs(D, {x, y}, {xc(k), yc(k)}));
fxxval = double(subs(fxx, {x, y}, {xc(k), yc(k)}));
zc = double(subs(f, {x, y}, {xc(k), yc(k)}));
xc_num = double(xc(k));
yc_num = double(yc(k));
% Classify the critical point
if Dval > 0
if fxxval > 0
label = 'Minimum';
color = 'r';
else
label = 'Maximum';
color = 'b';
end
elseif Dval < 0
label = 'Saddle';
color = 'g';
else
label = 'Inconclusive';
color = 'k';
end
% Plot the critical point
plot3(xc_num, yc_num, zc, 'o', 'MarkerSize', 10, 'MarkerFaceColor', color)
text(xc_num, yc_num, zc, [' ', label], 'Color', color, 'FontSize', 12)
end
hold off
This enhancement ensures that each critical point is clearly marked on the graph, with its classification visibly labelled.
For more information, refer to the following documentation:

카테고리

Help CenterFile Exchange에서 Labels and Styling에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by