1
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ you could try to use mat[k_][1,1]:= k + 1 instead of mat[k_][[1,1]]:=... , and so on. $\endgroup$ – AccidentalFourierTransform Nov 28 '15 at 13:00
  • $\begingroup$ I tried as you suggested, it doesn't work. $\endgroup$ – Krishna Tripathi Nov 29 '15 at 4:40
  • $\begingroup$ 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? $\endgroup$ – AccidentalFourierTransform Nov 29 '15 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.