我正在尝试定义一个在某些变量中起作用的对象,在其他索引中定义张量。 我的尝试是:
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]
它给出的输出是:
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}}
有人可以指出我这里出了什么问题以及获得我想要的方法是什么?
答案 0 :(得分:0)
mat[k_]
是一种不是符号的模式。 mat[k_] := {{0,0},{0,0}}
定义了一个返回2x2数组的变量函数。 mat[k_]
有Head
mat
和Part
1 k_
。
我相信你想在自己的单元格中定义mat
。
mat[k_] := {{k + 1, k + 2}, {k + 3, k + 4}}
然后在另一个单元格中
mat[1]
(* {{2, 3}, {4, 5}} *)
希望这有帮助。