我如何在MATHEMATICA中通过键盘输入矩阵

时间:2015-04-03 11:42:58

标签: matrix wolfram-mathematica keyboard-input

我可以通过键盘输入单行矩阵。如

x = {};
n = 3;
For[k = 1, k ≤ n, k++,
    br = Input[Row[{"Enter the ", k, " element"}]];
    AppendTo[x, br];
]

这将获得单行矩阵,如x = {2,3,6}。但如果我想通过键盘输入x = {{2,3,4},{4,5,6},{0,1,0}}那么我该怎么办?

1 个答案:

答案 0 :(得分:1)

优于For循环:

 x = Table[ 
      Input[Row[{ "enter component:"  , i , j}] ], {i, 3}, {j, 3}]

最好还是试试这个:

 Table[ ToExpression@StringSplit[
         InputString[
             Row[{"enter row", i , 
                  " ( three numbers space separated)" }]]], {i, 3}]