Cody

# Problem 1704. Triangular matrices in 3D array

Solution 2822979

Submitted on 12 Aug 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   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))

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))

3   Fail
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))

Assertion failed.

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

Assertion failed.

5   Fail
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))

Assertion failed.

6   Fail
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))

Assertion failed.

### Community Treasure Hunt

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

Start Hunting!
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}