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

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!