How to find all coordinates of extremes of two variable function?

4 visualizaciones (últimos 30 días)
pragiedruliai
pragiedruliai el 21 de Mayo de 2019
Comentada: Walter Roberson el 22 de Mayo de 2019
Hello,
I can't figure out how to find all coordinates of extremes of two variable function.
x=1:12;
y=[-0.1 0.01 0.05 -0.2 0.13 -0.19 0.2 -0.11 0.02 0 -0.1 -0.02];
p=polyfit(x, y, 6);
pol = @(x) p(1)*x.^6+p(2)*x.^5+p(3)*x.^4+p(4)*x.^3+p(5)*x.^2+p(6)*x+p(7);
x=1:0.25:12;
y=1:0.25:12;
[X,Y]=meshgrid(x,y);
k=0.55;
sk = numel(X);
matrix(X,sk);
P = k.*pol(X)-(1-k).*pol(Y);
subplot(1,2,2);
surf(X, Y, P)
xlabel('x'); ylabel('y'); zlabel('z')
function ma = matrix(X, sk)
num=floor(sk/2);
M=X;
while num > 0
x_temp=M(num);
M(num)=M(sk-num+1);
M(sk-num+1)=x_temp;
num=num-1;
end
X=M;
end
untitled1.png
  1 comentario
dpb
dpb el 21 de Mayo de 2019
What's the purpose of function matrix? As is now, it's doing nothing as you don't return the result so might as well not exist. But, it isn't clear what it is trying to compute???
As to the Q? posed,
[mx1,imx1]=max(P);
will return index of largest row by column as well as maximum in first dimension;
[mx2,imx2]=max(P,[],2);
the same info by row.
Finding other local maxima is a slightly different if this isn't the actual objective (is isn't quite clear)...

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 21 de Mayo de 2019
https://www.mathworks.com/help/matlab/ref/polyder.html and roots()
  2 comentarios
pragiedruliai
pragiedruliai el 22 de Mayo de 2019
Thank you.
I've tried, but it doesn't work with two variables.
Walter Roberson
Walter Roberson el 22 de Mayo de 2019
You have no cross-products between X and Y. You can fully separate it out to the sum of two independent polynomials, each of which can be solved by the above process.
In fact, because it is the same polynomial each time (just with different constant coefficients multiplied by each part) the extrema are the same for X and Y, so you only need to solve one part.

Iniciar sesión para comentar.

Categorías

Más información sobre Splines en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by