I'd like to make a function that takes an odd integer N and returns a diagonal matrix A with the odd diagonal elements $A_{11}$, $A_{33}$, etc. equal to zero and the even diagonal elements $A_{22}$, $A_{44}$, etc. equal to one. The best idea I've come up with is to use ReplacePart on a (NxN) constant array. I had hoped that the following would do the job:
A[N_]:= ReplacePart[ConstantArray[0,{N,N}],{2 i_,2 i_}->1]
but it seems like {2 i_,2 i_} is not a recognisable pattern (unlike if I were to put in {i_,i_} it would replace all diagonal elements with ones).
N
as a variable.N
is a built-in function in Mathematica. In general, avoid naming your own variables or functions using names that start with a capital letter. $\endgroup$