Message Boards Message Boards

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

Make a matrix from an Array?

Posted 5 years ago

I have this code:

n=Input[];
Array[mat,{n,n}];
For[i = 1, i < n+1, i++,
    For[j = 1, j < n+1, j++,
       mat[i,j]=0;
    ]
]
d=Det[mat];
Print[d];

And when I input "2", the result is 1, which can't be true. Is there something with an Array being a matrix?

POSTED BY: ????? ?????????
3 Replies

If I understand what you're trying to accomplish, which is to create a square zero-matrix, then the following does what you want:

      n = Input[];
      mat = ConstantArray[0, {n, n}];
      Det[mat]
(* 0 *)

There's no earthly reason to use a Fortran-like (or Matlab-like) do loop.

Moreover, if you're filling the matrix with 0's, you would surely already know its determinant will be 0,

POSTED BY: Murray Eisenberg

Your mat is the head of the array. The array itself is Array[mat,{n,n}]:

n = Input[];
myArray = Array[mat, {n, n}];
For[i = 1, i < n + 1, i++, 
 For[j = 1, j < n + 1, j++, mat[i, j] = 0;]]
d = Det[myArray]
POSTED BY: Gianluca Gorni
Posted 5 years ago
d_j^n2=Input [{n,d_d} ]; array=[mat,{n,n_d^d}]; For[i = 1, i < n+1, i++,     For[j = 1, j < n+1, j++,        mat[i,j]=0;     ] ] d=Det[mat,{n,n}]; Print[d];
Attachment

Attachment

Attachment

POSTED BY: Bo Brymer
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