# Defining an object which is function in some variables and tensor in some other indices

I am trying to define an object which function in some variable and tensor in other indices. My attempt at it was:

Clear[mat, k];
mat[k_] := {{0,0},{0,0}};
mat[k_][[1, 1]] := k + 1
mat[k_][[1, 2]] := k + 2
mat[k_][[2, 1]] := k + 3
mat[k_][[2, 2]] := k + 4
mat[1]


The ouput it gives is:

During evaluation of In[268]:= SetDelayed::setps: mat[k_] in the part    assignment is not a symbol. >>

Out[270]= $Failed During evaluation of In[268]:= SetDelayed::setps: mat[k_] in the part assignment is not a symbol. >> Out[271]=$Failed

During evaluation of In[268]:= SetDelayed::setps: mat[k_] in the part assignment is not a symbol. >>

Out[272]= $Failed During evaluation of In[268]:= SetDelayed::setps: mat[k_] in the part assignment is not a symbol. >> Out[273]=$Failed

Out[274]= {{0, 0}, {0, 0}}


Could someone please points me out as to what's going wrong here and what are the ways to get what i want?

• you could try to use mat[k_][1,1]:= k + 1 instead of mat[k_][[1,1]]:=... , and so on. – AccidentalFourierTransform Nov 28 '15 at 13:00
• I tried as you suggested, it doesn't work. – Krishna Tripathi Nov 29 '15 at 4:40
• why not? what happened? did you get an error message? (if you did, post it here). Anyway, im not really sure about what you are trying to do in your code, but the obvious solution is to define mat through mat[k_]:={{k+1,k+2},{k+3,k+4}}, and delete the other lines of code (delete mat[k_][[1,1]]:=... and so on). Does this solve your issues? – AccidentalFourierTransform Nov 29 '15 at 10:30