Cody

Problem 10. Determine whether a vector is monotonically increasing

Solution 2268958

Submitted on 10 May 2020 by Gautam Rawat
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   Pass
x = [0 1 2 3 4]; assert(isequal(mono_increase(x),true));

ans = 1 1 1 1 tf = logical 1

2   Pass
x = [0 1 2 3 -4]; assert(isequal(mono_increase(x),false));

ans = 1 1 1 -7 tf = logical 0

3   Pass
x = [-3 -4 2 3 4]; assert(isequal(mono_increase(x),false));

ans = -1 6 1 1 tf = logical 0

4   Pass
x = 1:.1:10; assert(isequal(mono_increase(x),true));

ans = Columns 1 through 18 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 Columns 19 through 36 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 Columns 37 through 54 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 Columns 55 through 72 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 Columns 73 through 90 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 tf = logical 1

5   Pass
x = cumsum(rand(1,100)); x(5) = -1; assert(isequal(mono_increase(x),false));

ans = Columns 1 through 18 0.8924 0.9749 0.2741 -3.9752 5.0169 0.2985 0.0073 0.6139 0.4422 0.3820 0.7037 0.4209 0.3829 0.2485 0.6983 0.6595 0.0400 0.9188 Columns 19 through 36 0.1548 0.2804 0.0843 0.0018 0.3232 0.1362 0.9827 0.0706 0.2896 0.4632 0.6865 0.8270 0.6928 0.5392 0.5897 0.5148 0.1242 0.5590 Columns 37 through 54 0.6759 0.4943 0.5690 0.1905 0.4560 0.4587 0.8312 0.7574 0.7211 0.5829 0.3177 0.4132 0.2526 0.7184 0.2173 0.6148 0.8491 0.2045 Columns 55 through 72 0.1657 0.3208 0.1001 0.2535 0.3094 0.6547 0.9735 0.7827 0.4825 0.1614 0.5897 0.4165 0.6271 0.3583 0.9738 0.5191 0.8570 0.3650 Columns 73 through 90 0.4602 0.0230 0.5554 0.5937 0.1009 0.0258 0.8825 0.1713 0.0100 0.4549 0.9785 0.9376 0.6530 0.5993 0.6063 0.6665 0.9240 0.5616 Columns 91 through 99 0.9353 0.7446 0.3061 0.1157 0.3155 0.0325 0.7704 0.3771 0.8561 tf = logical 0

6   Pass
x = cumsum(rand(1,50)); assert(isequal(mono_increase(x),true));

ans = Columns 1 through 18 0.6335 0.7812 0.4748 0.2343 0.5666 0.1032 0.7228 0.2966 0.4971 0.3680 0.4959 0.7400 0.1309 0.0887 0.8701 0.6013 0.2018 0.2162 Columns 19 through 36 0.9836 0.9227 0.8505 0.4235 0.5987 0.3161 0.8323 0.1486 0.5401 0.8186 0.7676 0.7469 0.6091 0.6693 0.2943 0.6843 0.1512 0.2768 Columns 37 through 49 0.3197 0.1106 0.9232 0.2096 0.6543 0.2738 0.7928 0.8021 0.3868 0.7436 0.1796 0.5766 0.6714 tf = logical 1

Suggested Problems

More from this Author95

Community Treasure Hunt

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

Start Hunting!