账号 自动登录 找回密码 密码 欢迎注册
 搜索

# [提问] 谁能把mathematica的计算结果排列优化一下?

### 马上注册，结交更多好友，享用更多功能，让你轻松玩转社区。

×

http://bbs.emath.ac.cn/forum.php ... 11&fromuid=8888

1. Clear["Global`*"];(*Clear all variables*)
2. (*把三维空间中的三角形转化成球面a^2+b^2+c^2==1*)
3. fun=(2*a^2-b^2)(2*b^2-c^2)(2*c^2-a^2)+x*(a^2+b^2+c^2-1)
4. fa=D[fun,a]
5. fb=D[fun,b]
6. fc=D[fun,c]
7. fx=D[fun,x]
8. sol1=Solve[{fa==0,fb==0,fc==0,fx==0},{a,b,c,x}]
9. Print["显示三角形内部的最值"]
10. sol11=fun/.sol1
11. Print["数值化"]
12. N@sol1
13. N@sol11

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

@hujunhua @wayne @chyanog

楼主| 发表于 2014-6-30 09:09:49 | 显示全部楼层
 我的是mathematica 7.0 也许这是mathematica的一个bug 我看solve的帮助里面的结果都是按照指定的变量的顺序排列的, 但是变量只有两个或者三个,而我指定的是4个

### 点评

@hujunhua  发表于 2014-6-30 09:10

 这个@wayne的专长，我换电脑了，没装Mathematica 9了，准备等一等直接装Mathematica 10. 看了wayne的一个帖子，说是可以装免费的Mathematica, 还打算学一学呢。Linux、树莓派、Free Mathematica，一连串的，得花时间折腾。

### 评分

wayne + 12 + 12 + 12 + 12 + 12 赞助一下！

 或许可以用下面的命令试试。 ans = {{x -> 1, a -> 2, b -> 3}, {b -> 2, a -> 3, x -> 1}}; Map[First[#] -> Last[#] &, Map[Transpose[{{x, a, b}, #}] &, {x, a, b} /. ans], {2}]

 {a -> (a /. #), b -> (b /. #), c -> (c /. #), x -> (x /. #)} & /@%复制代码

 上面是指定次序，如果是默认字母排序可以 Map[Sort, %]复制代码

 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[N@Solve[# == 0 & /@ (D[fun, #] & /@ #), #] &@{a, b, c, x}]复制代码

 您需要登录后才可以回帖 登录 | 欢迎注册 本版积分规则 回帖并转播 回帖后跳转到最后一页

GMT+8, 2024-9-20 08:24 , Processed in 0.025345 second(s), 17 queries .