Not sure what kind of output you want, but one way would be to get the derivative of your y(x) function. When it's "zero", it's at a maximum or minimum. I added quotes to "zero" because it's not going to be zero due to the time step of the solver. In the above example I'm getting the absolute of the derivative and when it's <= 0.01, I get the x value.
4 Comments
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/581058-how-to-find-value-of-x-when-y-reaches-maximum-value#comment_976887
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/581058-how-to-find-value-of-x-when-y-reaches-maximum-value#comment_976887
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/581058-how-to-find-value-of-x-when-y-reaches-maximum-value#comment_976893
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/581058-how-to-find-value-of-x-when-y-reaches-maximum-value#comment_976893
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/581058-how-to-find-value-of-x-when-y-reaches-maximum-value#comment_976923
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/581058-how-to-find-value-of-x-when-y-reaches-maximum-value#comment_976923
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/581058-how-to-find-value-of-x-when-y-reaches-maximum-value#comment_978095
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/581058-how-to-find-value-of-x-when-y-reaches-maximum-value#comment_978095
Sign in to comment.