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?
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]
murray
(Murray Eisenberg)
3
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,
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];