谁能把mathematica的计算结果排列优化一下?
本帖最后由 cn8888 于 2014-6-30 09:00 编辑http://bbs.emath.ac.cn/forum.php?mod=redirect&goto=findpost&ptid=5642&pid=54411&fromuid=8888
问题来自这里.
代码如下
Clear["Global`*"];(*Clear all variables*)
(*把三维空间中的三角形转化成球面a^2+b^2+c^2==1*)
fun=(2*a^2-b^2)(2*b^2-c^2)(2*c^2-a^2)+x*(a^2+b^2+c^2-1)
fa=D
fb=D
fc=D
fx=D
sol1=Solve[{fa==0,fb==0,fc==0,fx==0},{a,b,c,x}]
Print["显示三角形内部的最值"]
sol11=fun/.sol1
Print["数值化"]
N@sol1
N@sol11
其中的一行代码如下:
sol1=Solve[{fa==0,fb==0,fc==0,fx==0},{a,b,c,x}]
求解结果数值化如下:
{{x -> -0.111111, b -> -0.57735, c -> -0.57735,
a -> -0.57735}, {x -> -0.111111, b -> -0.57735, c -> -0.57735,
a -> 0.57735}, {x -> -0.111111, b -> -0.57735, c -> 0.57735,
a -> -0.57735}, {x -> -0.111111, b -> -0.57735, c -> 0.57735,
a -> 0.57735}, {x -> -0.111111, b -> 0.57735, c -> -0.57735,
a -> -0.57735}, {x -> -0.111111, b -> 0.57735, c -> -0.57735,
a -> 0.57735}, {x -> -0.111111, b -> 0.57735, c -> 0.57735,
a -> -0.57735}, {x -> -0.111111, b -> 0.57735, c -> 0.57735,
a -> 0.57735}, {x -> 0., a -> -1., c -> 0., b -> 0.}, {x -> 0.,
a -> 1., c -> 0., b -> 0.}, {x -> 0., b -> -1., c -> 0.,
a -> 0.}, {x -> 0., b -> 1., c -> 0., a -> 0.}, {x -> 0.,
b -> -0.534522, c -> -0.755929, a -> -0.377964}, {x -> 0.,
b -> -0.534522, c -> -0.755929, a -> 0.377964}, {x -> 0.,
b -> -0.534522, c -> 0.755929, a -> -0.377964}, {x -> 0.,
b -> -0.534522, c -> 0.755929, a -> 0.377964}, {x -> 0.,
b -> 0.534522, c -> -0.755929, a -> -0.377964}, {x -> 0.,
b -> 0.534522, c -> -0.755929, a -> 0.377964}, {x -> 0.,
b -> 0.534522, c -> 0.755929, a -> -0.377964}, {x -> 0.,
b -> 0.534522, c -> 0.755929, a -> 0.377964}, {x -> 0.,
b -> -0.755929, c -> -0.377964, a -> -0.534522}, {x -> 0.,
b -> -0.755929, c -> -0.377964, a -> 0.534522}, {x -> 0.,
b -> -0.755929, c -> 0.377964, a -> -0.534522}, {x -> 0.,
b -> -0.755929, c -> 0.377964, a -> 0.534522}, {x -> 0.,
b -> -0.377964, c -> -0.534522, a -> -0.755929}, {x -> 0.,
b -> -0.377964, c -> -0.534522, a -> 0.755929}, {x -> 0.,
b -> -0.377964, c -> 0.534522, a -> -0.755929}, {x -> 0.,
b -> -0.377964, c -> 0.534522, a -> 0.755929}, {x -> 0.,
b -> 0.377964, c -> -0.534522, a -> -0.755929}, {x -> 0.,
b -> 0.377964, c -> -0.534522, a -> 0.755929}, {x -> 0.,
b -> 0.377964, c -> 0.534522, a -> -0.755929}, {x -> 0.,
b -> 0.377964, c -> 0.534522, a -> 0.755929}, {x -> 0.,
b -> 0.755929, c -> -0.377964, a -> -0.534522}, {x -> 0.,
b -> 0.755929, c -> -0.377964, a -> 0.534522}, {x -> 0.,
b -> 0.755929, c -> 0.377964, a -> -0.534522}, {x -> 0.,
b -> 0.755929, c -> 0.377964, a -> 0.534522}, {x -> 0., c -> -1.,
a -> 0., b -> 0.}, {x -> 0., c -> 1., a -> 0.,
b -> 0.}, {x -> -0.420754, a -> -0.921698, c -> -0.387907,
b -> 0.}, {x -> -0.420754, a -> -0.921698, c -> 0.387907,
b -> 0.}, {x -> -0.420754, a -> 0.921698, c -> -0.387907,
b -> 0.}, {x -> -0.420754, a -> 0.921698, c -> 0.387907,
b -> 0.}, {x -> -0.420754, b -> -0.387907, c -> -0.921698,
a -> 0.}, {x -> -0.420754, b -> -0.387907, c -> 0.921698,
a -> 0.}, {x -> -0.420754, b -> 0.387907, c -> -0.921698,
a -> 0.}, {x -> -0.420754, b -> 0.387907, c -> 0.921698,
a -> 0.}, {x -> -0.420754, b -> -0.921698, a -> -0.387907,
c -> 0.}, {x -> -0.420754, b -> -0.921698, a -> 0.387907,
c -> 0.}, {x -> -0.420754, b -> 0.921698, a -> -0.387907,
c -> 0.}, {x -> -0.420754, b -> 0.921698, a -> 0.387907,
c -> 0.}, {x -> 1.40841, a -> -0.511452, c -> -0.859312,
b -> 0.}, {x -> 1.40841, a -> -0.511452, c -> 0.859312,
b -> 0.}, {x -> 1.40841, a -> 0.511452, c -> -0.859312,
b -> 0.}, {x -> 1.40841, a -> 0.511452, c -> 0.859312,
b -> 0.}, {x -> 1.40841, b -> -0.511452, a -> -0.859312,
c -> 0.}, {x -> 1.40841, b -> -0.511452, a -> 0.859312,
c -> 0.}, {x -> 1.40841, b -> 0.511452, a -> -0.859312,
c -> 0.}, {x -> 1.40841, b -> 0.511452, a -> 0.859312,
c -> 0.}, {x -> 1.40841, b -> -0.859312, c -> -0.511452,
a -> 0.}, {x -> 1.40841, b -> -0.859312, c -> 0.511452,
a -> 0.}, {x -> 1.40841, b -> 0.859312, c -> -0.511452,
a -> 0.}, {x -> 1.40841, b -> 0.859312, c -> 0.511452, a -> 0.}}
我明明是按照{a,b,c,x}列举求解变量的.但是....................
求解结果让我很不爽,简直就是胡乱排列有{x,a,c,b}有{x,b,c,a}
请问如何把他们都搞成{a,b,c,x}的?
请问如何让每个求解结果{x -> 1.40841, b -> 0.859312, c -> 0.511452, a -> 0.}一行显示呢?
@hujunhua @wayne @chyanog
你们觉得应该如何弄呢? 我的是mathematica 7.0
也许这是mathematica的一个bug
我看solve的帮助里面的结果都是按照指定的变量的顺序排列的,
但是变量只有两个或者三个,而我指定的是4个 这个@wayne的专长,我换电脑了,没装Mathematica 9了,准备等一等直接装Mathematica 10.
看了wayne的一个帖子,说是可以装免费的Mathematica, 还打算学一学呢。Linux、树莓派、Free Mathematica,一连串的,得花时间折腾。 或许可以用下面的命令试试。
ans = {{x -> 1, a -> 2, b -> 3}, {b -> 2, a -> 3, x -> 1}};
Map -> Last[#] &, Map &, {x, a, b} /. ans], {2}]
{a -> (a /. #), b -> (b /. #), c -> (c /. #), x -> (x /. #)} & /@%
:) 上面是指定次序,如果是默认字母排序可以
Map
fun = (2*a^2 - b^2) (2*b^2 - c^2) (2*c^2 - a^2) +x*(a^2 + b^2 + c^2 - 1);
Column & /@ #), #] &@{a, b, c, x}]
页:
[1]