re-us 发表于 2007-12-24 10:25

符号运算中化简遇到的一个问题

clc; clear
syms a a1 a2 p1 p2 p3;
s=a*p2+a1*p2*p3+a2*p2*p3;
我想要的结果是
s=a*p2+(a1+a2)*p2*p3;
用simplify、simple,factor好像都不行。 谢谢

[ 本帖最后由 ChaChing 于 2010-2-3 10:58 编辑 ]

花如月 发表于 2007-12-24 10:43

如果真都不行,那应该是2个并不等价。或者其他的原因,同类项合并用simple应该可以

如果真需要那样的式子,自己写成那样吧,电脑的灵活性本就差

[ 本帖最后由 ChaChing 于 2010-2-3 10:57 编辑 ]

re-us 发表于 2007-12-24 10:54

呵呵,就是怕麻烦才想让电脑作的。
最后计算出来的结果是这样的:就想要ps2*ps3项。

-6356373612921259/36028797018963968*(cos(x)*sin(y)*sin(p)*ps1-sin(x)*sin(3*y)*sin(p)*ps2-2*sin(2*x)*sin(4*y)*sin(p)*ps3+2*cos(2*x)*sin(y)*sin(p)*ps4)*(sin(x)*cos(y)*cos(p)*ps1+3*cos(x)*cos(3*y)*cos(p)*ps2+4*cos(2*x)*cos(4*y)*cos(p)*ps3+sin(2*x)*cos(y)*cos(p)*ps4-2*sin(y)*cos(2*p)*ps5-4*sin(2*y)*cos(2*p)*ps6)+6356373612921259/36028797018963968*(sin(x)*cos(y)*sin(p)*ps1+3*cos(x)*cos(3*y)*sin(p)*ps2+4*cos(2*x)*cos(4*y)*sin(p)*ps3+sin(2*x)*cos(y)*sin(p)*ps4-sin(y)*sin(2*p)*ps5-2*sin(2*y)*sin(2*p)*ps6)*(cos(x)*sin(y)*cos(p)*ps1-sin(x)*sin(3*y)*cos(p)*ps2-2*sin(2*x)*sin(4*y)*cos(p)*ps3+2*cos(2*x)*sin(y)*cos(p)*ps4)-3972733508075787/1125899906842624*(cos(x)*sin(y)*sin(p)*ps1-sin(x)*sin(3*y)*sin(p)*ps2-2*sin(2*x)*sin(4*y)*sin(p)*ps3+2*cos(2*x)*sin(y)*sin(p)*ps4)*(-2*sin(x)*cos(y)*sin(p)*ps1-30*cos(x)*cos(3*y)*sin(p)*ps2-80*cos(2*x)*cos(4*y)*sin(p)*ps3-5*sin(2*x)*cos(y)*sin(p)*ps4+sin(y)*sin(2*p)*ps5+8*sin(2*y)*sin(2*p)*ps6)+3972733508075787/1125899906842624*(sin(x)*cos(y)*sin(p)*ps1+3*cos(x)*cos(3*y)*sin(p)*ps2+4*cos(2*x)*cos(4*y)*sin(p)*ps3+sin(2*x)*cos(y)*sin(p)*ps4-sin(y)*sin(2*p)*ps5-2*sin(2*y)*sin(2*p)*ps6)*(-2*cos(x)*sin(y)*sin(p)*ps1+10*sin(x)*sin(3*y)*sin(p)*ps2+40*sin(2*x)*sin(4*y)*sin(p)*ps3-10*cos(2*x)*sin(y)*sin(p)*ps4)-4947310427677087/281474976710656*cos(x)*sin(y)*sin(p)*ps1+4947310427677087/281474976710656*sin(x)*sin(3*y)*sin(p)*ps2+4947310427677087/140737488355328*sin(2*x)*sin(4*y)*sin(p)*ps3-4947310427677087/140737488355328*cos(2*x)*sin(y)*sin(p)*ps4-57/2500*sin(x)*sin(y)*sin(p)*sita1-57/500*cos(x)*sin(3*y)*sin(p)*sita2-57/250*cos(2*x)*sin(4*y)*sin(p)*sita3-57/1000*sin(2*x)*sin(y)*sin(p)*sita4-57/5000*cos(y)*sin(2*p)*sita5-57/1250*cos(2*y)*sin(2*p)*sita6+57/2500*sin(x)*sin(y)*sin(p)*ps1+57/500*cos(x)*sin(3*y)*sin(p)*ps2+57/250*cos(2*x)*sin(4*y)*sin(p)*ps3+57/1000*sin(2*x)*sin(y)*sin(p)*ps4+57/5000*cos(y)*sin(2*p)*ps5+57/1250*cos(2*y)*sin(2*p)*ps6

即使用digits 和vpa 处理也简单不了多少。
anyway,谢谢花如月。我再找找

bjb05 发表于 2007-12-24 10:56

回复 #1 re-us 的帖子

没有正好的函数,它还没有那么智能

re-us 发表于 2007-12-24 11:23

回复 #4 bjb05 的帖子

谢谢

TurtleRock 发表于 2007-12-24 20:40

可以把p2*p3用一个新的符号代替,试一下:
clc; clear
syms a a1 a2 p1 p2 p3;
s=a*p2+a1*p2*p3+a2*p2*p3;
s2=strrep(char(s),'p2*p3','p4');
s2=maple('collect',s2,'p4'); disp(s2);
如果要重新回到符号变量,再加上下面两句:
s2=strrep(char(s2),'p4','p2*p3'); s=sym(s2)

结果:
(a1+a2)*p4+a*p2

s =
(a1+a2)*p2*p3+a*p2

[ 本帖最后由 ChaChing 于 2010-2-3 11:02 编辑 ]

re-us 发表于 2007-12-24 21:47

回复 #6 TurtleRock 的帖子

thank you so much
you are so 强:lol
页: [1]
查看完整版本: 符号运算中化简遇到的一个问题