Cody

Problem 44725. Find argmax of a function

Solution 2604859

Submitted on 24 Jun 2020
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Fail
x = 0:0.01:pi; y = sin(x); y_correct = 1.57; assert(abs(argmax(x,y) - y_correct) < 0.01 )

Array indices must be positive integers or logical values. Error in argmax (line 2) [~,xx] = max(y(x)); Error in Test1 (line 4) assert(abs(argmax(x,y) - y_correct) < 0.01 )

2   Fail
x = 0:0.01:pi; y = x.^2; y_correct = 3.14; assert(abs(argmax(x,y) - y_correct) < 0.01 )

Array indices must be positive integers or logical values. Error in argmax (line 2) [~,xx] = max(y(x)); Error in Test2 (line 4) assert(abs(argmax(x,y) - y_correct) < 0.01 )

3   Fail
x = 0:0.01:pi; y = -(x-.42).^2; y_correct = .42; assert(abs(argmax(x,y) - y_correct) < 0.01 )

Array indices must be positive integers or logical values. Error in argmax (line 2) [~,xx] = max(y(x)); Error in Test3 (line 4) assert(abs(argmax(x,y) - y_correct) < 0.01 )

4   Fail
x = -100:0; y = -cosh(x+3); y_correct = -3; assert(abs(argmax(x,y) - y_correct) < 0.01 )

Array indices must be positive integers or logical values. Error in argmax (line 2) [~,xx] = max(y(x)); Error in Test4 (line 4) assert(abs(argmax(x,y) - y_correct) < 0.01 )

Community Treasure Hunt

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

Start Hunting!