MATLAB Answers

how can i create a 400 by 400 matrix with a pattern?

1 view (last 30 days)
absadgs
absadgs on 23 Feb 2020
Edited: Guillaume on 23 Feb 2020
The matrix is 400 by 400 and i need a -1 2 -1 pattern starting with 2. Like this:

  0 Comments

Sign in to comment.

Accepted Answer

Guillaume
Guillaume on 23 Feb 2020
Edited: Guillaume on 23 Feb 2020
full(gallery('tridiag', 400))
If the subdiagonal, diagonal and superdiagonal were anything other than -1, 2, 1, for example: 1, 2, 3 respectively:
fulll(gallery('tridiag', 400, 1, 2, 3))
Another way:
toeplitz([2, -1, repelem(0, 398)])

  0 Comments

Sign in to comment.

More Answers (0)

Sign in to answer this question.