Find the local and global maxima and minima

189 visualizaciones (últimos 30 días)
Priyadarshini Nair
Priyadarshini Nair el 27 de Oct. de 2021
Respondida: Alamanda Ponappa Poovaya el 1 de Nov. de 2021
Find the local and global maxima and minima for the function f(x)=sin|x|, in an interval I = (−2π, 2π)
  1 comentario
Jaya
Jaya el 27 de Oct. de 2021
You might consider reading this page. It has got examples. You will be able to do for your function then. https://www.mathworks.com/help/symbolic/maxima-minima-and-inflection-points.html
As anyway you have tagged this question under the tag homework with no sample code, I have tried providing a resource for you to read rather than soving it by myself!

Iniciar sesión para comentar.

Respuestas (1)

Alamanda Ponappa Poovaya
Alamanda Ponappa Poovaya el 1 de Nov. de 2021
One option is to use ‘findpeaks’ in the Signal Processing Toolbox. It will give you the maximum (and indirectly the minimum) values and their index locations. If ‘y’ is the vector that produced the plot, to find the maxima and minima:
n = -2*pi:0.01:2*pi;
y = sin(abs(n));
plot(n,y);
[Maxima,MaxIdx] = findpeaks(y);
%plot maxima
hold on;
plot(n(MaxIdx),Maxima,'r*');
[Minima,MinIdx] = findpeaks(-y);
%plot minima
plot(n(MinIdx),-Minima,'g*');
hold off;
This will plot the maxima in red and the minima in green. You can refer to the Maxima and Minima arrays to get the maximum and minimum values respectively
Refer to the documentation for findpeaks below:

Categorías

Más información sobre Parametric Spectral Estimation en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by