
identifying the critical points of a bivariate function
35 ビュー (過去 30 日間)
古いコメントを表示
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]);
0 件のコメント
回答 (1 件)
Vedant Shah
2025 年 6 月 27 日 6:18
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:
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Labels and Styling についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!