mathematica
##指定 list 元素
In[2]:= {{1.2, 3.4}, {5.6, 7.8}}[[2, 2]]
Out[2]= 7.8
In[1]:= {{3, 4}, {5, 6}}[[2]][[2]]
Out[1]= 6
In[9]:= a = {9, 8, 7, 6, 5};
a[[{3, 4}]]
Out[10]= {7, 6}
In[12]:= Range[11, 20][[Range[4, 5]]]
Out[12]= {14, 15}
Module
to define a module by
Module[{list of local variables}, things to do]
In[75]:= F[n_] :=
Module[{tempsum}, tempsum = 0; Do[tempsum = tempsum + i, {i, 1, n}];
tempsum];
Table[F[n], {n, 1, 10}]
Out[76]= {1, 3, 6, 10, 15, 21, 28, 36, 45, 55}
Do loop
s=0;
Do[s = s + 1; Print[i, " ", s], {i, 1, 10}]
Or simply,to repeat 10 times,
s=0;
Do[s=s+1;Print[s], 10]
Or loop through a list:
s=0;
Do[s=s+i;Print[i," ",s], {i,{1,5,6,2}}]
如何批量去掉表格如
{yy -> 8.90323265887200425958769930845,
yy -> 8.90323265943529241591021289811,
yy -> 8.90323265800195651367281533850}中的右箭头?谢谢!
追答
“->”是Mathematica里最重要指令之一Rule的简写……要“去掉”的话,可以:
yy /. List/@{yy -> 8.90323265887200425958769930845,
yy -> 8.90323265943529241591021289811,
yy -> 8.90323265800195651367281533850}
道理:
In[111]:= x /. x -> 3
Out[111]= 3
In[112]:= x /. {x -> 3}
Out[112]= 3
In[81]:= x /. {{x -> 3}}
Out[81]= {3}
In[113]:= x /. {{{x -> 3}}}
Out[113]= {{3}}
In[115]:= res = N[Solve[x^7 + x + 1 == 0, x]]
Out[115]= {{x -> -0.796544}, {x -> -0.705298 -
0.637624 I}, {x -> -0.705298 + 0.637624 I}, {x ->
0.123762 - 1.05665 I}, {x -> 0.123762 + 1.05665 I}, {x ->
0.979808 - 0.516677 I}, {x -> 0.979808 + 0.516677 I}}
In[116]:= x /. res
Out[116]= {-0.796544, -0.705298 - 0.637624 I, -0.705298 + 0.637624 I,
0.123762 - 1.05665 I, 0.123762 + 1.05665 I, 0.979808 - 0.516677 I,
0.979808 + 0.516677 I}
In[117]:= x /. Flatten[res]
Out[117]= -0.796544
Expand: 不能进入子表达式。 尝试ExpandAll !