2015-11-28 23 views
0

我想定义一个对象,该对象在其他索引中的某些变量和张量中起作用。 我在它的尝试是:定义一个对象,它在某些变量和某些其他索引中的张量中起作用

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}} 

可能有人请指出我出去,什么地方出了错这里,什么是得到我想要什么办法呢?

+1

嗨,不客气,在Stackoverflow。请注意,您也可以在http://mathematica.stackexchange.com/上发帖,许多专家也会为您提供帮助。 –

回答

0

mat[k_]是一个模式不是一个符号。 mat[k_] := {{0,0},{0,0}}定义了一个返回2×2数组的单个变量函数。 mat[k_]Headmat和。

我相信你想定义mat已经在它自己的单元格中。

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

在另一个单元格然后

mat[1] 
(* {{2, 3}, {4, 5}} *) 

希望这有助于。

+0

感谢您的回应。我不想定义你建议的方式,因为在我的原始代码中,这促使我写这个问题,我需要定义一个矩阵(不仅是2 * 2),其块被作为某个变量的函数给出k在这里。 –

+0

看看'表'。 – Edmund

相关问题