How to find max and min of fuction of 2 independent variables?
Show older comments
My question is how can I find minimum and maximum of this function, and then tag them with 'o' in function graph?

This is my code so far:
function funkcija(intervalpox,intervalpoy,korak,crtanje)
x=0:korak:intervalpox;
y=0:korak:intervalpoy;
[X,Y] = meshgrid(x,y);
Z = (sin(sqrt(X.^2 + Y.^2)) ./ (sqrt(X.^2 + Y.^2)));
mesh(X,Y,Z)
grid on
xlabel('.x.')
ylabel('.y.')
zlabel('.z.')
title('mesh')
8 Comments
Walter Roberson
on 20 Feb 2019
max() and min() can have two outputs instead of 1...
Faris Hajdarpasic
on 20 Feb 2019
Walter Roberson
on 20 Feb 2019
[~, location_of_max] = max(Z(:));
[~, location_of_min] = min(Z(:));
x_at_max = X(location_of_max);
y_at_max = Y(location_of_max);
x_at_min = X(location_of_min);
y_at_min = Y(location_of_min);
plot(x_at_max, y_at_max, 'go', x_at_min, y_at_min, 'r+');
Faris Hajdarpasic
on 20 Feb 2019
Walter Roberson
on 20 Feb 2019
[ThisOutputWillNeverBeUsed, location_of_max] = max(Z(:));
clear ThisOutputWillNeverBeUsed
[ThisOutputWillNeverBeUsedEither, location_of_min] = min(Z(:));
clear ThisOutputWillNeverBeUsedEither
x_at_max = ... and so on
Faris Hajdarpasic
on 20 Feb 2019
Faris Hajdarpasic
on 20 Feb 2019
Edited: Faris Hajdarpasic
on 20 Feb 2019
Walter Roberson
on 21 Feb 2019
[~, location_of_max] = max(Z(:));
[~, location_of_min] = min(Z(:));
x_at_max = X(location_of_max);
y_at_max = Y(location_of_max);
z_at_max = Z(location_of_max);
x_at_min = X(location_of_min);
y_at_min = Y(location_of_min);
z_at_min = Z(location_of_min)
plot3(x_at_max, y_at_max, z_at_max, 'go', x_at_min, y_at_min, z_at_min,'r+');
Accepted Answer
More Answers (0)
Categories
Find more on Point Cloud Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!