Problem 2365. Generate this matrix

For a given odd integer n, generate a matrix as follows:

Input: n = 5; Output:

 [  2     1     0     0     0
    1     1     1     0     0
    0     1     0     1     0
    0     0     1     1     1
    0     0     0     1     2  ]

Input: n=7; Output:

 [  3     1     0     0     0     0     0
    1     2     1     0     0     0     0
    0     1     1     1     0     0     0
    0     0     1     0     1     0     0
    0     0     0     1     1     1     0
    0     0     0     0     1     2     1
    0     0     0     0     0     1     3 ]

For further understanding of the pattern, please check the test suite.

Solution Stats

62.98% Correct | 37.02% Incorrect
Last Solution submitted on Mar 14, 2024

Problem Comments

Solution Comments

Show comments


Problem Recent Solvers126

Problem Tags

Community Treasure Hunt

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

Start Hunting!