Calculate absolute maxima and minima of a two variable function

I have a function
% f(x,y) = x^4 + y^4 - x^2 - y^2 + 1
but i am not able to understand how to start solving this. Can someone help me with the code?

 채택된 답변

Image Analyst
Image Analyst 2020년 12월 17일
OK, here is the function, but exactly what does "solve" mean to you???
xMin = -2;
xMax = 2;
yMin = -2;
yMax = 2;
numPoints = 200;
xv = linspace(xMin, xMax, numPoints);
yv = linspace(yMin, yMax, numPoints);
[x, y] = meshgrid(xv, yv);
% f(x,y) = x^4 + y^4 - x^2 - y^2 + 1
fprintf('Creating function.\n');
f = x.^4 + y.^4 - x.^2 - y.^2 + 1;
fprintf('Creating surface plot.\n');
surf(x, y, f, 'LineStyle', 'none');
xlabel('x', 'FontSize', 20);
ylabel('y', 'FontSize', 20);
zlabel('f', 'FontSize', 20);
title('f(x,y) = x^4 + y^4 - x^2 - y^2 + 1', 'FontSize', 20);
colorbar;
Do you want to use contour() or contour3() to find out where it equals some value?

댓글 수: 3

For me, solve means to display the values of absolute maxima and minima, but i am understanding your solution a little bit, thanks for your help
maxValue = max(abs(f(:)))
minValue = min(abs(f(:)))
fprintf('The max of f = %f.\nThe min of f = %f.\n', maxValue, minValue);
If this does what you wanted, then please "Accept this answer".
Image Analyst
Image Analyst 2020년 12월 18일
편집: Image Analyst 2020년 12월 18일
Note: that max is for the plotted region. If you plotted more, the max would be higher. For x and y of infinity, the max is infinity.
The min though is always at (x,y) = (0,0) and is 1.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Billuri
Billuri 2022년 12월 9일

0 개 추천

f1 = x^2 + y^2

댓글 수: 1

Image Analyst
Image Analyst 2022년 12월 9일
편집: Image Analyst 2022년 12월 9일
Can you please elaborate on how this solves his question on the 4th order polynomial? He says "solve means to display the values of absolute maxima and minima".

댓글을 달려면 로그인하십시오.

카테고리

제품

릴리스

R2020b

질문:

2020년 12월 16일

편집:

2022년 12월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by