how to fined both the coordiante

2 次查看(过去 30 天)
Hi, how can I find the coordinate on the x-axis associated with the highest (maximunm) value of y of the function?
x=[-10:0.02:10]
y=exp(-(x-1).^2./2)+3.*exp(-(x-2).^2./2)
plot(x,y)
Can someone help me to fine the point of x associated with the max of y?
Thank you!

采纳的回答

Image Analyst
Image Analyst 2019-12-28
Use max():
x=[-10:0.02:10]
y=exp(-(x-1).^2./2)+3.*exp(-(x-2).^2./2)
plot(x,y, 'b-', 'LineWidth', 2)
grid on;
% Find the max
[yMax, indexAtMax] = max(y)
% Put a circle around the max.
hold on;
plot(x(indexAtMax), yMax, 'ro', 'MarkerSize', 12, 'LineWidth', 2);
% Draw a line from the x-axis up to the max.
line([x(indexAtMax), x(indexAtMax)], [0, yMax], 'Color', 'r', 'LineWidth', 2);
0000 Screenshot.png

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Legend 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by