Matrix 用Mathematica 9中的数字范围排列生成一个矩阵

Matrix 用Mathematica 9中的数字范围排列生成一个矩阵,matrix,wolfram-mathematica,permutation,Matrix,Wolfram Mathematica,Permutation,我开始学习数学。我需要制作一个nx4矩阵“m”,其中第一列是矩阵“a”,第二、第三、第四列是矩阵“B”。此外,我需要排除第一行。有人能帮我吗 `t = 2; a = Range[0, t]; b = Range[0, t]; c = Range[0, t]; {A = MatrixForm[ 1/Sqrt[Flatten[ Table[a^2 + b^2 + c^2, {a, 0, t, 1}, {b, 0, t, 1}, {c, 0, t, 1}]]]],

我开始学习数学。我需要制作一个nx4矩阵“m”,其中第一列是矩阵“a”,第二、第三、第四列是矩阵“B”。此外,我需要排除第一行。有人能帮我吗

`t = 2; a = Range[0, t]; b = Range[0, t]; c = Range[0, t];
{A = MatrixForm[
   1/Sqrt[Flatten[
      Table[a^2 + b^2 + c^2, {a, 0, t, 1}, {b, 0, t, 1}, {c, 0, t, 
        1}]]]],
 B = MatrixForm[Tuples[{a, b, c}]]}`
我需要这样的东西:

List[List[0, 0, 1, 1], List[0, 0, 2, Rational[1, 4]], 
 List[0, 1, 0, 1], List[0, 1, 1, Rational[1, 2]], 
 List[0, 1, 2, Rational[1, 5]], List[0, 2, 0, Rational[1, 4]], 
 List[0, 2, 1, Rational[1, 5]], List[0, 2, 2, \[Placeholder]], 
 List[1, 0, 0, \[Placeholder]], List[1, 0, 1, \[Placeholder]], 
 List[1, 0, 2, \[Placeholder]], List[1, 1, 0, \[Placeholder]], 
 List[1, 1, 1, \[Placeholder]], List[1, 1, 2, \[Placeholder]], 
 List[1, 2, 0, \[Placeholder]], List[1, 2, 1, \[Placeholder]], 
 List[1, 2, 2, \[Placeholder]], List[2, 0, 0, \[Placeholder]], 
 List[2, 0, 1, \[Placeholder]], List[2, 0, 2, \[Placeholder]], 
 List[2, 1, 0, \[Placeholder]], List[2, 1, 1, \[Placeholder]], 
 List[2, 1, 2, \[Placeholder]], List[2, 2, 0, \[Placeholder]], 
 List[2, 2, 1, \[Placeholder]], List[2, 2, 2, \[Placeholder]]]
Drop[Tuples[Range[0, 2], 3], 1] /. {x_, y_, z_} -> {x, y, z, 1/(x^2 + y^2 + z^2)}

这就是我想在Mathematica中做的事情

在开始解决您的问题之前,我可以看到您的代码中存在一些问题,作为初学者,您应该注意并避免这些问题:

  • 您已经将求值
    A=
    B=
    包装在一对
    {}
    中,因此结果将是一个包含求值结果的两个表达式的列表。这不会创建矩阵,而是创建一个包含两个
    MatrixForm
    s的列表

  • 通常,将表达式包装在
    MatrixForm[]
    中并将其分配给变量是个坏主意
    MatrixForm[]
    实际上是为了使输出看起来更漂亮,大多数在Mathematica列表(数组和矩阵只是列表列表)上工作的操作不会在具有head
    MatrixForm[]
    的对象上工作

  • 计算启动
    1/Sqrt[Flatten[
    的表达式会生成错误消息:
    Power::infy:“遇到无限表达式1/0。”
    a==0,b==0,c==0
最后,一些你没有要求的建议:使用只在字母大小写上有所不同的变量名,就像你对
A
A
以及
B
B
所做的那样,是通往痛苦和绝望世界的必经之路。仅仅因为你可以,并不意味着你应该这样做

编辑

您可以使用以下命令轻松生成结果的前3列:

Tuples[Range[0, 2], 3]
现在,这包括元素
{0,0,0}
,所以我们将删除它,如下所示

Drop[Tuples[Range[0, 2], 3],1]
现在用替换规则计算第4列,如下所示:

List[List[0, 0, 1, 1], List[0, 0, 2, Rational[1, 4]], 
 List[0, 1, 0, 1], List[0, 1, 1, Rational[1, 2]], 
 List[0, 1, 2, Rational[1, 5]], List[0, 2, 0, Rational[1, 4]], 
 List[0, 2, 1, Rational[1, 5]], List[0, 2, 2, \[Placeholder]], 
 List[1, 0, 0, \[Placeholder]], List[1, 0, 1, \[Placeholder]], 
 List[1, 0, 2, \[Placeholder]], List[1, 1, 0, \[Placeholder]], 
 List[1, 1, 1, \[Placeholder]], List[1, 1, 2, \[Placeholder]], 
 List[1, 2, 0, \[Placeholder]], List[1, 2, 1, \[Placeholder]], 
 List[1, 2, 2, \[Placeholder]], List[2, 0, 0, \[Placeholder]], 
 List[2, 0, 1, \[Placeholder]], List[2, 0, 2, \[Placeholder]], 
 List[2, 1, 0, \[Placeholder]], List[2, 1, 1, \[Placeholder]], 
 List[2, 1, 2, \[Placeholder]], List[2, 2, 0, \[Placeholder]], 
 List[2, 2, 1, \[Placeholder]], List[2, 2, 2, \[Placeholder]]]
Drop[Tuples[Range[0, 2], 3], 1] /. {x_, y_, z_} -> {x, y, z, 1/(x^2 + y^2 + z^2)}
请注意,我没有将此表达式的结果指定为任何变量的值,您可能需要这样做。请注意,我也没有创建任何中间变量,这会使您的工作区(在Mathematica speak
上下文中)保持整洁