Cody

# Problem 10. Determine whether a vector is monotonically increasing

Solution 1927732

Submitted on 9 Sep 2019 by Aleksandr Montelli
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));

n = 5 z = 1 2 3 4 z = 1 2 3 4 0 ans = 1×5 logical array 1 1 1 1 0 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1

2   Pass
x = [0]; assert(isequal(mono_increase(x),true));

n = 1 tf = logical 1

3   Pass
x = [0 0 0 0 0]; assert(isequal(mono_increase(x),false));

n = 5 z = 0 0 0 0 z = 0 0 0 0 0 ans = 1×5 logical array 0 0 0 0 0 tf = logical 0

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

n = 5 z = 1 2 3 -4 z = 1 2 3 -4 0 ans = 1×5 logical array 1 1 1 0 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 0

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

n = 5 z = -4 2 3 4 z = -4 2 3 4 0 ans = 1×5 logical array 0 1 1 1 0 tf = logical 0

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

n = 91 z = Columns 1 through 18 1.1000 1.2000 1.3000 1.4000 1.5000 1.6000 1.7000 1.8000 1.9000 2.0000 2.1000 2.2000 2.3000 2.4000 2.5000 2.6000 2.7000 2.8000 Columns 19 through 36 2.9000 3.0000 3.1000 3.2000 3.3000 3.4000 3.5000 3.6000 3.7000 3.8000 3.9000 4.0000 4.1000 4.2000 4.3000 4.4000 4.5000 4.6000 Columns 37 through 54 4.7000 4.8000 4.9000 5.0000 5.1000 5.2000 5.3000 5.4000 5.5000 5.6000 5.7000 5.8000 5.9000 6.0000 6.1000 6.2000 6.3000 6.4000 Columns 55 through 72 6.5000 6.6000 6.7000 6.8000 6.9000 7.0000 7.1000 7.2000 7.3000 7.4000 7.5000 7.6000 7.7000 7.8000 7.9000 8.0000 8.1000 8.2000 Columns 73 through 90 8.3000 8.4000 8.5000 8.6000 8.7000 8.8000 8.9000 9.0000 9.1000 9.2000 9.3000 9.4000 9.5000 9.6000 9.7000 9.8000 9.9000 10.0000 z = Columns 1 through 18 1.1000 1.2000 1.3000 1.4000 1.5000 1.6000 1.7000 1.8000 1.9000 2.0000 2.1000 2.2000 2.3000 2.4000 2.5000 2.6000 2.7000 2.8000 Columns 19 through 36 2.9000 3.0000 3.1000 3.2000 3.3000 3.4000 3.5000 3.6000 3.7000 3.8000 3.9000 4.0000 4.1000 4.2000 4.3000 4.4000 4.5000 4.6000 Columns 37 through 54 4.7000 4.8000 4.9000 5.0000 5.1000 5.2000 5.3000 5.4000 5.5000 5.6000 5.7000 5.8000 5.9000 6.0000 6.1000 6.2000 6.3000 6.4000 Columns 55 through 72 6.5000 6.6000 6.7000 6.8000 6.9000 7.0000 7.1000 7.2000 7.3000 7.4000 7.5000 7.6000 7.7000 7.8000 7.9000 8.0000 8.1000 8.2000 Columns 73 through 90 8.3000 8.4000 8.5000 8.6000 8.7000 8.8000 8.9000 9.0000 9.1000 9.2000 9.3000 9.4000 9.5000 9.6000 9.7000 9.8000 9.9000 10.0000 Column 91 0 ans = 1×91 logical array Columns 1 through 45 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 46 through 90 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Column 91 0 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1

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

n = 100 z = Columns 1 through 18 1.3882 1.6199 1.9585 -1.0000 2.9728 3.6509 3.9193 3.9456 4.2073 4.8825 5.5714 5.9211 6.3392 6.7442 7.3301 7.8070 7.9483 8.6523 Columns 19 through 36 8.7846 9.1247 9.2963 10.2521 11.0480 11.6427 12.5343 13.0386 13.5875 13.7701 14.1791 14.8068 15.5990 15.9120 16.2807 16.8052 17.0872 17.2014 Columns 37 through 54 17.8124 18.6947 19.0512 19.8270 20.1616 20.5396 20.5921 20.7255 21.4776 22.1371 22.3104 22.3289 22.5334 23.2822 23.6613 24.5150 24.6778 24.8921 Columns 55 through 72 25.8362 26.2502 27.1333 27.7510 28.1177 28.2768 28.6287 29.4191 30.0639 30.5012 31.2843 31.9838 32.0684 32.8823 33.3089 33.4137 34.3996 35.3727 Columns 73 through 90 35.6455 36.1161 36.1176 36.9620 37.9463 38.3202 38.4168 38.4364 38.9077 39.7840 40.4438 40.9849 41.2182 41.2293 41.8259 42.7953 43.1664 43.7214 Columns 91 through 99 44.2298 44.8806 45.6269 46.4621 46.8687 46.8965 47.5213 48.0524 48.8224 z = Columns 1 through 18 1.3882 1.6199 1.9585 -1.0000 2.9728 3.6509 3.9193 3.9456 4.2073 4.8825 5.5714 5.9211 6.3392 6.7442 7.3301 7.8070 7.9483 8.6523 Columns 19 through 36 8.7846 9.1247 9.2963 10.2521 11.0480 11.6427 12.5343 13.0386 13.5875 13.7701 14.1791 14.8068 15.5990 15.9120 16.2807 16.8052 17.0872 17.2014 Columns 37 through 54 17.8124 18.6947 19.0512 19.8270 20.1616 20.5396 20.5921 20.7255 21.4776 22.1371 22.3104 22.3289 22.5334 23.2822 23.6613 24.5150 24.6778 24.8921 Columns 55 through 72 25.8362 26.2502 27.1333 27.7510 28.1177 28.2768 28.6287 29.4191 30.0639 30.5012 31.2843 31.9838 32.0684 32.8823 33.3089 33.4137 34.3996 35.3727 Columns 73 through 90 35.6455 36.1161 36.1176 36.9620 37.9463 38.3202 38.4168 38.4364 38.9077 39.7840 40.4438 40.9849 41.2182 41.2293 41.8259 42.7953 43.1664 43.7214 Columns 91 through 100 44.2298 44.8806 45.6269 46.4621 46.8687 46.8965 47.5213 48.0524 48.8224 0 ans = 1×100 logical array Columns 1 through 45 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 46 through 90 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 91 through 100 1 1 1 1 1 1 1 1 1 0 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 0

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

n = 50 z = Columns 1 through 18 0.9217 1.4002 2.0973 2.5637 3.2016 3.5114 4.3301 4.9244 5.7814 6.1801 6.7643 7.1942 8.0378 8.7802 9.4356 10.4122 11.2865 12.1752 Columns 19 through 36 12.5991 13.0357 13.9540 14.0987 14.8349 15.3340 15.7356 15.8000 16.7377 16.9318 17.9046 18.3971 19.3079 19.8201 20.1245 20.9771 21.8038 22.6069 Columns 37 through 49 23.0762 23.4309 24.0286 24.6078 24.7189 24.8502 25.4528 25.6158 26.2134 26.3299 26.8906 27.0746 27.5402 z = Columns 1 through 18 0.9217 1.4002 2.0973 2.5637 3.2016 3.5114 4.3301 4.9244 5.7814 6.1801 6.7643 7.1942 8.0378 8.7802 9.4356 10.4122 11.2865 12.1752 Columns 19 through 36 12.5991 13.0357 13.9540 14.0987 14.8349 15.3340 15.7356 15.8000 16.7377 16.9318 17.9046 18.3971 19.3079 19.8201 20.1245 20.9771 21.8038 22.6069 Columns 37 through 50 23.0762 23.4309 24.0286 24.6078 24.7189 24.8502 25.4528 25.6158 26.2134 26.3299 26.8906 27.0746 27.5402 0 ans = 1×50 logical array Columns 1 through 45 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 46 through 50 1 1 1 1 0 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1 tf = logical 1