Cody

Problem 1704. Triangular matrices in 3D array

Solution 2890637

Submitted on 29 Aug 2020 by Pauli Huusari
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(:,:,1) = [1 2 3;4 5 6;7 8 9]; x(:,:,2) = [1 4 7;2 5 8;3 6 9]; x(:,:,3) = [1 2 3;1 2 3;1 2 3]; y_correct(:,:,1) = [1 0 0;4 5 0;7 8 9]; y_correct(:,:,2) = [1 0 0;2 5 0;3 6 9]; y_correct(:,:,3) = [1 0 0;1 2 0;1 2 3]; assert(isequal(tril3(x),y_correct))

y(:,:,1) = 1 0 0 4 5 0 7 8 9 y(:,:,2) = 1 0 0 2 5 0 3 6 9 y(:,:,3) = 1 0 0 1 2 0 1 2 3

2   Pass
x = cumsum(ones(3,3,50)); y_correct = repmat([1 0 0;2 2 0; 3 3 3],[1,1,50]); assert(isequal(tril3(x),y_correct))

y(:,:,1) = 1 0 0 2 2 0 3 3 3 y(:,:,2) = 1 0 0 2 2 0 3 3 3 y(:,:,3) = 1 0 0 2 2 0 3 3 3 y(:,:,4) = 1 0 0 2 2 0 3 3 3 y(:,:,5) = 1 0 0 2 2 0 3 3 3 y(:,:,6) = 1 0 0 2 2 0 3 3 3 y(:,:,7) = 1 0 0 2 2 0 3 3 3 y(:,:,8) = 1 0 0 2 2 0 3 3 3 y(:,:,9) = 1 0 0 2 2 0 3 3 3 y(:,:,10) = 1 0 0 2 2 0 3 3 3 y(:,:,11) = 1 0 0 2 2 0 3 3 3 y(:,:,12) = 1 0 0 2 2 0 3 3 3 y(:,:,13) = 1 0 0 2 2 0 3 3 3 y(:,:,14) = 1 0 0 2 2 0 3 3 3 y(:,:,15) = 1 0 0 2 2 0 3 3 3 y(:,:,16) = 1 0 0 2 2 0 3 3 3 y(:,:,17) = 1 0 0 2 2 0 3 3 3 y(:,:,18) = 1 0 0 2 2 0 3 3 3 y(:,:,19) = 1 0 0 2 2 0 3 3 3 y(:,:,20) = 1 0 0 2 2 0 3 3 3 y(:,:,21) = 1 0 0 2 2 0 3 3 3 y(:,:,22) = 1 0 0 2 2 0 3 3 3 y(:,:,23) = 1 0 0 2 2 0 3 3 3 y(:,:,24) = 1 0 0 2 2 0 3 3 3 y(:,:,25) = 1 0 0 2 2 0 3 3 3 y(:,:,26) = 1 0 0 2 2 0 3 3 3 y(:,:,27) = 1 0 0 2 2 0 3 3 3 y(:,:,28) = 1 0 0 2 2 0 3 3 3 y(:,:,29) = 1 0 0 2 2 0 3 3 3 y(:,:,30) = 1 0 0 2 2 0 3 3 3 y(:,:,31) = 1 0 0 2 2 0 3 3 3 y(:,:,32) = 1 0 0 2 2 0 3 3 3 y(:,:,33) = 1 0 0 2 2 0 3 3 3 y(:,:,34) = 1 0 0 2 2 0 3 3 3 y(:,:,35) = 1 0 0 2 2 0 3 3 3 y(:,:,36) = 1 0 0 2 2 0 3 3 3 y(:,:,37) = 1 0 0 2 2 0 3 3 3 y(:,:,38) = 1 0 0 2 2 0 3 3 3 y(:,:,39) = 1 0 0 2 2 0 3 3 3 y(:,:,40) = 1 0 0 2 2 0 3 3 3 y(:,:,41) = 1 0 0 2 2 0 3 3 3 y(:,:,42) = 1 0 0 2 2 0 3 3 3 y(:,:,43) = 1 0 0 2 2 0 3 3 3 y(:,:,44) = 1 0 0 2 2 0 3 3 3 y(:,:,45) = 1 0 0 2 2 0 3 3 3 y(:,:,46) = 1 0 0 2 2 0 3 3 3 y(:,:,47) = 1 0 0 2 2 0 3 3 3 y(:,:,48) = 1 0 0 2 2 0 3 3 3 y(:,:,49) = 1 0 0 2 2 0 3 3 3 y(:,:,50) = 1 0 0 2 2 0 3 3 3

3   Pass
x = cumsum(ones(5,5,100),2); y_correct = repmat(tril(cumsum(ones(5,5),2)),[1,1,100]); assert(isequal(tril3(x),y_correct))

y(:,:,1) = 1 0 0 0 0 1 2 0 0 0 1 2 3 0 0 1 2 3 4 0 1 2 3 4 5 y(:,:,2) = 1 0 0 0 0 1 2 0 0 0 1 2 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4 0 1 2 3 4 5 y(:,:,54) = 1 0 0 0 0 1 2 0 0 0 1 2 3 0 0 1 2 3 4 0 1 2 3 4 5 y(:,:,55) = 1 0 0 0 0 1 2 0 0 0 1 2 3 0 0 1 2 3 4 0 1 2 3 4 5 y(:,:,56) = 1 0 0 0 0 1 2 0 0 0 1 2 3 0 0 1 2 3 4 0 1 2 3 4 5 y(:,:,57) = 1 0 0 0 0 1 2 0 0 0 1 2 3 0 0 1 2 3 4 0 1 2 3 4 5 y(:,:,58) = 1 0 0 0 0 1 2 0 0 0 1 2 3 0 0 1 2 3 4 0 1 2 3 4 5 y(:,:,59) = 1 0 0 0 0 1 2 0 0 0 1 2 3 0 0 1 2 3 4 0 1 2...

4   Pass
x = rand([1 1 400]); y_correct = x; assert(isequal(tril3(x),y_correct))

y(:,:,1) = 0.2444 y(:,:,2) = 0.8429 y(:,:,3) = 0.2771 y(:,:,4) = 0.6034 y(:,:,5) = 0.4760 y(:,:,6) = 0.5219 y(:,:,7) = 0.0625 y(:,:,8) = 0.4990 y(:,:,9) = 0.1721 y(:,:,10) = 0.3602 y(:,:,11) = 0.0364 y(:,:,12) = 0.6786 y(:,:,13) = 0.4870 y(:,:,14) = 0.3752 y(:,:,15) = 0.7478 y(:,:,16) = 0.1587 y(:,:,17) = 0.8389 y(:,:,18) = 0.8441 y(:,:,19) = 0.8679 y(:,:,20) = 0.3774 y(:,:,21) = 0.4147 y(:,:,22) = 0.0755 y(:,:,23) = 0.3606 y(:,:,24) = 0.2737 y(:,:,25) = 0.8933 y(:,:,26) = 0.2856 y(:,:,27) = 0.7500 y(:,:,28) = 0.3019 y(:,:,29) = 0.0062 y(:,:,30) = 0.8692 y(:,:,31) = 0.6833 y(:,:,32) = 0.4412 y(:,:,33) = 0.0155 y(:,:,34) = 0.7823 y(:,:,35) = 0.3736 y(:,:,36) = 0.2949 y(:,:,37) = 0.1524 y(:,:,38) = 0.3512 y(:,:,39) = 0.5967 y(:,:,40) = 0.7476 y(:,:,41) = 0.9108 y(:,:,42) = 0.2740 y(:,:,43) = 0.9732 y(:,:,44) = 0.5872 y(:,:,45) = 0.3882 y(:,:,46) = 0.8912 y(:,:,47) = 0.0195 y(:,:,48) = 0.9758 y(:,:,49) = 0.8765 y(:,:,50) = 0.4838 y(:,:,51) = 0.2419 y(:,:,52) = 0.3144 y(:,:,53) = 0.7352 y(:,:,54) = 0.2279 y(:,:,55) = 0.2139 y(:,:,56) = 0.3892 y(:,:,57) = 0.0225 y(:,:,58) = 0.6535 y(:,:,59) = 0.0376 y(:,:,60) = 0.7463 y(:,:,61) = 0.0397 y(:,:,62) = 0.2819 y(:,:,63) = 0.1789 y(:,:,64) = 0.0763 y(:,:,65) = 0.2032 y(:,:,66) = 0.1023 y(:,:,67) = 0.1482 y(:,:,68) = 0.0169 y(:,:,69) = 0.6659 y(:,:,70) = 0.7593 y(:,:,71) = 0.8434 y(:,:,72) = 0.3024 y(:,:,73) = 0.7512 y(:,:,74) = 0.1832 y(:,:,75) = 0.7396 y(:,:,76) = 0.1027 y(:,:,77) = 0.8888 y(:,:,78) = 0.4285 y(:,:,79) = 0.7151 y(:,:,80) = 0.0542 y(:,:,81) = 0.4159 y(:,:,82) = 0.6613 y(:,:,83) = 0.0155 y(:,:,84) = 0.4517 y(:,:,85) = 0.0524 y(:,:,86) = 0.0665 y(:,:,87) = 0.1059 y(:,:,88) = 0.2271 y(:,:,89) = 0.0927 y(:,:,90) = 0.9943 y(:,:,91) = 0.1721 y(:,:,92) = 0.1981 y(:,:,93) = 0.8414 y(:,:,94) = 0.2010 y(:,:,95) = 0.7891 y(:,:,96) = 0.3783 y(:,:,97) = 0.2887 y(:,:,98) = 0.9642 y(:,:,99) = 0.8138 y(:,:,100) = 0.8245 y(:,:,101) = 0.6457 y(:,:,102) = 0.3763 y(:,:,103) = 0.1031 y(:,:,104) = 0.4326 y(:,:,105) = 0.8043 y(:,:,106) = 0.5261 y(:,:,107) = 0.6010 y(:,:,108) = 0.4047 y(:,:,109) = 0.3233 y(:,:,110) = 0.4472 y(:,:,111) = 0.9722 y(:,:,112) = 0.1879 y(:,:,113) = 0.1965 y(:,:,114) = 0.7771 y(:,:,115) = 0.6727 y(:,:,116) = 0.7833 y(:,:,117) = 0.1830 y(:,:,118) = 0.9226 y(:,:,119) = 0.8934 y(:,:,120) = 0.6275 y(:,:,121) = 0.8201 y(:,:,122) = 0.7369 y(:,:,123) = 0.5727 y(:,:,124) = 0.9761 y(:,:,125) = 0.9202 y(:,:,126) = 0.3294 y(:,:,127) = 0.2036 y(:,:,128) = 0.4751 y(:,:,129) = 0.9877 y(:,:,130) = 0.7339 y(:,:,131) = 0.0915 y(:,:,132) = 0.8197 y(:,:,133) = 0.4746 y(:,:,134) = 0.2210 y(:,:,135) = 0.3370 y(:,:,136) = 0.4052 y(:,:,137) = 0.6978 y(:,:,138) = 0.9492 y(:,:,139) = 0.0053 y(:,:,140) = 0.4822 y(:,:,141) = 0.7426 y(:,:,142) = 0.9741 y(:,:,143) = 0.0360 y(:,:,144) = 0.3989 y(:,:,145) = 0.0805 y(:,:,146) = 0.1450 y(:,:,147) = 0.4698 y(:,:,148) = 0.5779 y(:,:,149) = 0.8395 y(:,:,150) = 0.8575 y(:,:,151) = 0.3029 y(:,:,152) = 0.2882 y(:,:,153) = 0.3964 y(:,:,154) = 0.7360 y(:,:,155) = 0.8440 y(:,:,156) = 0.1649 y(:,:,157) = 0.7981 y(:,:,158) = 0.5251 y(:,:,159) = 0.1973 y(:,:,160) = 0.0637 y(:,:,161) = 0.2638 y(:,:,162) = 0.5273 y(:,:,163) = 0.3776 y(:,:,164) = 0.0653 y(:,:,165) = 0.1446 y(:,:,166) = 0.8705 y(:,:,167) = 0.1885 y(:,:,168) = 0.4147 y(:,:,169) = 0.4777 y(:,:,170) = 0.4529 y(:,:,171) = 0.4183 y(:,:,172) = 0.3219 y(:,:,173) = 0.3935 y(:,:,174) = 0.2081 y(:,:,175) = 0.7706 y(:,:,176) = 0.3764 y(:,:,177) = 0.0831 y(:,:,178) = 0.9955 y(:,:,179) = 0.3607 y(:,:,180) = 0.0111 y(:,:,181) = 0.9791 y(:,:,182) = 0.7096 y(:,:,183) = 0.3718 y(:,:,184) = 0.1768 y(:,:,185) = 0.7702 y(:,:,186) = 0.8817 y(:,:,187) = 0.3736 y(:,:,188) = 0.8394 y(:,:,189) = 0.0145 y(:,:,190) = 0.4507 y(:,:,191) = 0.6393 y(:,:,192) = 0.0045 y(:,:,193) = 0.4978 y(:,:,194) = 0.5396 y(:,:,195) = 0.2126 y(:,:,196) = 0.0095 y(:,:,197) = 0.2074 y(:,:,198) = 0.9538 y(:,:,199) = 0.8547 y(:,:,200) = 0.1832 y(:,:,201) = 0.1464 y(:,:,202) = 0.7000 y(:,:,203) = 0.4375 y(:,:,204) = 0.1243 y(:,:,205) = 0.1881 y(:,:,206) = 0.6621 y(:,:,207) = 0.9878 y(:,:,208) = 0.0930 y(:,:,209) = 0.8634 y(:,:,210) = 0.5186 y(:,:,211) = 0.3811 y(:,:,212) = 0.5368 y(:,:,213) = 0.6117 y(:,:,214) = 0.7644 y(:,:,215) = 0.9514 y(:,:,216) = 0.3621 y(:,:,217) = 0.8261 y(:,:,218) = 0.6654 y(:,:,219) = 0.5865 y(:,:,220) = 0.7185 y(:,:,221) = 0.8269 y(:,:,222) = 0.4244 y(:,:,223) = 0.3837 y(:,:,224) = 0.9472 y(:,:,225) = 0.1208 y(:,:,226) = 0.4911 y(:,:,227) = 0.9742 y(:,:,228) = 0.9702 y(:,:,229) = 0.4281 y(:,:,230) = 0.8951 y(:,:,231) = 0.7052 y(:,:,232) = 0.8287 y(:,:,233) = 0.0108 y(:,:,234) = 0.3625 y(:,:,235) = 0.2142 y(:,:,236) = 0.2355 y(:,:,237) = 0.2265 y(:,:,238) = 0.4233 y(:,:,239) = 0.1463 y(:,:,240) = 0.5666 y(:,:,241) = 0.3241 y(:,:,242) = 0.4480 y(:,:,243) = 0.7657 y(:,:,244) = 0.5405 y(:,:,245) = 0.9418 y(:,:,246) = 0.3323 y(:,:,247) = 0.6650 y(:,:,248) = 0.2962 y(:,:,249) = 0.7962 y(:,:,250) = 0.9449 y(:,:,251) = 0.8338 y(:,:,252) = 0.7251 y(:,:,253) = 0.0382 y(:,:,254) = 0.0915 y(:,:,255) = 0.2781 y(:,:,256) = 0.7688 y(:,:,257) = 0.6997 y(:,:,258) = 0.8172 y(:,:,259) = 0.4650 y(:,:,260) = 0.9710 y(:,:,261) = 0.9708 y(:,:,262) = 0.5015 y(:,:,263) = 0.0823 y(:,:,264) = 0.3109 y(:,:,265) = 0.1246 y(:,:,266) = 0.9399 y(:,:,267) = 0.8356 y(:,:,268) = 0.9308 y(:,:,269) = 0.5751 y(:,:,270) = 0.3291 y(:,:,271) = 0.8248 y(:,:,272) = 0.5994 y(:,:,273) = 0.4276 y(:,:,274) = 0.7795 y(:,:,275) = 0.3072 y(:,:,276) = 0.9303 y(:,:,277) = 0.8193 y(:,:,278) = 0.6657 y(:,:,279) = 0.6115 y(:,:,280) = 0.1657 y(:,:,281) = 0.6712 y(:,:,282) = 0.1483 y(:,:,283) = 0.4608 y(:,:,284) = 0.1716 y(:,:,285) = 0.8867 y(:,:,286) = 0.4348 y(:,:,287) = 0.3773 y(:,:,288) = 0.8101 y(:,:,289) = 0.8599 y(:,:,290) = 0.2146 y(:,:,291) = 0.3896 y(:,:,292) = 0.2992 y(:,:,293) = 0.7062 y(:,:,294) = 0.0960 y(:,:,295) = 0.4648 y(:,:,296) = 0.9807 y(:,:,297) = 0.5439 y(:,:,298) = 0.3718 y(:,:,299) = 0.0534 y(:,:,300) = 0.7381 y(:,:,301) = 0.9874 y(:,:,302) = 0.9963 y(:,:,303) = 0.6216 y(:,:,304) = 0.9396 y(:,:,305) = 0.7160 y(:,:,306) = 0.4020 y(:,:,307) = 0.7796 y(:,:,308) = 0.8564 y(:,:,309) = 0.3178 y(:,:,310) = 0.0744 y(:,:,311) = 0.5627 y(:,:,312) = 0.3429 y(:,:,313) = 0.0465 y(:,:,314) = 0.6314 y(:,:,315) = 0.2739 y(:,:,316) = 0.3417 y(:,:,317) = 0.4367 y(:,:,318) = 0.3995 y(:,:,319) = 0.7167 y(:,:,320) = 0.9000 y(:,:,321) = 0.2072 y(:,:,322) = 0.8360 y(:,:,323) = 0.7027 y(:,:,324) = 0.8405 y(:,:,325) = 0.0692 y(:,:,326) = 0.3328 y(:,:,327) = 0.3414 y(:,:,328) = 0.6557 y(:,:,329) = 0.6463 y(:,:,330) = 0.5127 y(:,:,331) = 0.0564 y(:,:,332) = 0.7879 y(:,:,333) = 0.5679 y(:,:,334) = 0.9915 y(:,:,335) = 0.8853 y(:,:,336) = 0.2874 y(:,:,337) = 0.7521 y(:,:,338) = 0.6621 y(:,:,339) = 0.1323 y(:,:,340) = 0.0528 y(:,:,341) = 0.6953 y(:,:,342) = 0.4177 y(:,:,343) = 0.9850 y(:,:,344) = 0.2572 y(:,:,345) = 0.2819 y(:,:,346) = 0.8209 y(:,:,347) = 0.8291 y(:,:,348) = 0.2204 y(:,:,349) = 0.5435 y(:,:,350) = 0.5535 y(:,:,351) = 0.0927 y(:,:,352) = 0.0466 y(:,:,353) = 0.2415 y(:,:,354) = 0.4702 y(:,:,355) = 0.9430 y(:,:,356) = 0.3970 y(:,:,357) = 0.2051 y(:,:,358) = 0.1696 y(:,:,359) = 0.2145 y(:,:,360) = 0.3027 y(:,:,361) = 0.7079 y(:,:,362) = 0.1167 y(:,:,363) = 0.6743 y(:,:,364) = 0.2401 y(:,:,365) = 0.5712 y(:,:,366) = 0.8394 y(:,:,367) = 0.3537 y(:,:,368) = 0.2788 y(:,:,369) = 0.7343 y(:,:,370) = 0.2645 y(:,:,371) = 0.3866 y(:,:,372) = 0.8220 y(:,:,373) = 0.2465 y(:,:,374) = 0.9037 y(:,:,375)...

5   Pass
x = reshape(1:40,[2,2,10]); y_correct(:,:,1) = [1 0;2 4]; y_correct(:,:,2) = [5 0;6 8]; y_correct(:,:,3) = [9 0;10 12]; y_correct(:,:,4) = [13 0;14 16]; y_correct(:,:,5) = [17 0;18 20]; y_correct(:,:,6) = [21 0;22 24]; y_correct(:,:,7) = [25 0;26 28]; y_correct(:,:,8) = [29 0;30 32]; y_correct(:,:,9) = [33 0;34 36]; y_correct(:,:,10) = [37 0;38 40]; assert(isequal(tril3(x),y_correct))

y(:,:,1) = 1 0 2 4 y(:,:,2) = 5 0 6 8 y(:,:,3) = 9 0 10 12 y(:,:,4) = 13 0 14 16 y(:,:,5) = 17 0 18 20 y(:,:,6) = 21 0 22 24 y(:,:,7) = 25 0 26 28 y(:,:,8) = 29 0 30 32 y(:,:,9) = 33 0 34 36 y(:,:,10) = 37 0 38 40

6   Pass
x = randi([0 1],[4,4,5]); y_correct(:,:,1) = tril(x(:,:,1)); y_correct(:,:,2) = tril(x(:,:,2)); y_correct(:,:,3) = tril(x(:,:,3)); y_correct(:,:,4) = tril(x(:,:,4)); y_correct(:,:,5) = tril(x(:,:,5)); assert(isequal(tril3(x),y_correct))

y(:,:,1) = 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 1 y(:,:,2) = 1 0 0 0 0 0 0 0 1 1 0 0 1 0 0 1 y(:,:,3) = 0 0 0 0 1 1 0 0 0 0 1 0 0 1 1 1 y(:,:,4) = 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 y(:,:,5) = 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0

Suggested Problems

More from this Author44

Community Treasure Hunt

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

Start Hunting!