Cody

# Problem 43492. Create a square matrix with given conditions

Solution 1709058

Submitted on 18 Jan 2019 by HH
• Size: 9
• This is the leading solution.
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
n = 1; y = 1; assert(isequal(ResultMatrix(n),y))

[Warning: Function assert has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In unix (line 32) In ResultMatrix (line 2) In ScoringEngineTestPoint1 (line 3) In solutionTest (line 3)]

2   Pass
n = 3; y =[9 6 3; 6 4 2; 3 2 1]; assert(isequal(ResultMatrix(n),y))

[Warning: Function assert has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In unix (line 32) In ResultMatrix (line 2) In ScoringEngineTestPoint2 (line 5) In solutionTest (line 5)]

3   Pass
n = 4; y =[16 12 8 4; 12 9 6 3; 8 6 4 2; 4 3 2 1]; assert(isequal(ResultMatrix(n),y))

[Warning: Function assert has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In unix (line 32) In ResultMatrix (line 2) In ScoringEngineTestPoint3 (line 6) In solutionTest (line 7)]

4   Pass
n = 5; y =[25 20 15 10 5; 20 16 12 8 4; 15 12 9 6 3; 10 8 6 4 2; 5 4 3 2 1]; assert(isequal(ResultMatrix(n),y))

[Warning: Function assert has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In unix (line 32) In ResultMatrix (line 2) In ScoringEngineTestPoint4 (line 7) In solutionTest (line 9)]

5   Pass
n = 7; y=[49 42 35 28 21 14 7 42 36 30 24 18 12 6 35 30 25 20 15 10 5 28 24 20 16 12 8 4 21 18 15 12 9 6 3 14 12 10 8 6 4 2 7 6 5 4 3 2 1]; assert(isequal(ResultMatrix(n),y))

[Warning: Function assert has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In unix (line 32) In ResultMatrix (line 2) In ScoringEngineTestPoint5 (line 9) In solutionTest (line 11)]

6   Pass
n = 10; y=[100 90 80 70 60 50 40 30 20 10; 90 81 72 63 54 45 36 27 18 9; 80 72 64 56 48 40 32 24 16 8; 70 63 56 49 42 35 28 21 14 7; 60 54 48 42 36 30 24 18 12 6; 50 45 40 35 30 25 20 15 10 5; 40 36 32 28 24 20 16 12 8 4; 30 27 24 21 18 15 12 9 6 3; 20 18 16 14 12 10 8 6 4 2; 10 9 8 7 6 5 4 3 2 1]; assert(isequal(ResultMatrix(n),y))

[Warning: Function assert has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In unix (line 32) In ResultMatrix (line 2) In ScoringEngineTestPoint6 (line 12) In solutionTest (line 13)]

### Community Treasure Hunt

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

Start Hunting!