Message Boards Message Boards

0
|
4889 Views
|
3 Replies
|
2 Total Likes
View groups...
Share
Share this post:

How to define the following matrix like the following?

Posted 5 years ago

How to define the following matrix: the order of matrix is n, In other word, I want define the matrix function of n and i represents the imaginary unit. enter image description here

POSTED BY: Licheng Zhang
3 Replies
Posted 4 years ago

Very thanks to you

POSTED BY: Licheng Zhang

You can define a function like so:

bandMatrix[dim_Integer] := Module[{mat},
  mat = SparseArray[{Band[{1, 1}] -> 0, Band[{2, 1}] -> I, Band[{1, 2}] -> I}, {dim, dim}];
  mat[[1, dim]] = mat[[dim, 1]] = 1;
  Return[Normal[mat]]
  ]

enter image description here

POSTED BY: Henrik Schachner
Posted 4 years ago

Band[{1, 1}] -> 0 can be omitted, certainly. Also, you can put in the assignments of the corner elements in SparseArray[] itself. Thus,

With[{n = 5}, 
     SparseArray[{Band[{2, 1}] -> I, Band[{1, 2}] -> I,
                  {1, -1} -> 1, {-1, 1} -> 1}, {n, n}]] // MatrixForm
POSTED BY: J. M.
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract