How to find all coordinates of extremes of two variable function?
4 次查看(过去 30 天)
显示 更早的评论
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

1 个评论
dpb
2019-5-21
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)...
回答(1 个)
Walter Roberson
2019-5-21
https://www.mathworks.com/help/matlab/ref/polyder.html and roots()
2 个评论
Walter Roberson
2019-5-22
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Splines 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!