Generate this matrix - MATLAB Cody - MATLAB Central

Problem 2365. Generate this matrix

Difficulty:Rate

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

60.37% Correct | 39.63% Incorrect
Last Solution submitted on Mar 07, 2025

Problem Comments

Solution Comments

Show comments

Group

Project Euler II Image
Project Euler II
  • 12 Problems
  • 51 Finishers

Problem Recent Solvers141

Problem Tags

Community Treasure Hunt

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

Start Hunting!
Go to top of page