finding local maximum/minimum for a function

조회 수: 9 (최근 30일)
Adonia Chalcedony Indian
Adonia Chalcedony Indian 2021년 1월 17일
답변: sanidhyak 2025년 1월 30일
how to find the local extreme values of the function xy-x^2-y^2-2x-2y+4

답변 (1개)

sanidhyak
sanidhyak 2025년 1월 30일
Hi Adonia,
I understand that you want to find the local maximum and local minimum of this function: xy-x^2-y^2-2x-2y+4
You can follow the following steps:
  • Define the function and compute first-order partial derivatives using diff.
  • Solve for critical points using solve and compute second-order partial derivatives.
  • Calculate the Hessian determinant and use it to classify the critical points (min, max, or saddle) based on its value and the second derivative.
Use the "plot" function in MATLAB to visualize the function's surface and identify the critical points on it. This will help you to verify their nature based on the graphical representation.
% Plot the function
fsurf(f, [-5 5 -5 5]) % Plot the surface
hold on
% Plot critical points in red
plot3(double(crit.x), double(crit.y), double(subs(f, [x, y], [crit.x, crit.y])), 'ro', 'MarkerSize', 8, 'LineWidth', 2)
xlabel('x'), ylabel('y'), zlabel('f(x, y)')
title('Function Plot with Critical Points')
grid on
hold off
Kindly refer to the following MATLAB documentation for detailed information on all the related functions

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by