How do i determine the highest values of my for loop?

1 view (last 30 days)
for x = 3:0.2:9
y=(cos(x+1)/(pi*x-1));
disp(['x = ',num2str(x)])
disp(['y = ',num2str(y)])
end
I need to find the highest values (x and y) of the results of this for loop, which i know are "x = 9" and "y = 0.065282" by looking into the results.
But i can't think of a command that'll do it without the need of eye analysis...
Thanks in advance.

Accepted Answer

KSSV
KSSV on 5 Oct 2022
x = 3:0.2:9 ;
y=(cos(x+1)./(pi*x-1));
[val,idx] = max(y) ;
[x(idx) y(idx)]
ans = 1×2
5.0000 0.0653
  1 Comment
Breno
Breno on 5 Oct 2022
Ohhh, much simpler than i thought it was. Thank you!!

Sign in to comment.

More Answers (0)

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!