Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Replies: 13   Last Post: Nov 23, 2012 6:11 PM

 Messages: [ Previous | Next ]
 Tang Laoya Posts: 23 Registered: 11/21/12
Posted: Nov 23, 2012 8:41 AM

On Friday, November 23, 2012 8:29:56 PM UTC+8, Peter Pein wrote:
> Am 23.11.2012 05:28, schrieb Tang Laoya:
>

> > On Friday, November 23, 2012 9:35:01 AM UTC+8, Nasser M. Abbasi wrote:
>
> >> On 11/22/2012 7:10 PM, Tang Laoya wrote:
>
> >>
>
> >>
>
> >>
>
> >>>
>
> >>
>
> >>> k11 = 1/60 (b1^2 + c1^2 + d1^2)
>
> >>
>
> >>> k11 = HornerForm[k11]
>
> >>
>
> >>>
>
> >>
>
> >>> The outputs are:
>
> >>
>
> >>> 1/60 (b1^2 + c1^2 + d1^2)
>
> >>
>
> >>> b1^2/60 + c1^2/60 + d1^2/60
>
> >>
>
> >>>
>
> >>
>
> >>> respectively.
>
> >>
>
> >>>
>
> >>
>
> >>> How to do to let the numbers are also been combined?
>
> >>
>
> >>>
>
> >>
>
> >>
>
> >>
>
> >>
>
> >>
>
> >> In[25]:= Simplify[k11]
>
> >>
>
> >> Out[25]= 1/60 (b1^2+c1^2+d1^2)
>
> >
>
> > Dear Nasser,
>
> >
>
> > Thank you very much for your kindly reply. What I mean is that 'Simplify' conflicts with 'HornerForm'. I wish both variables and numbers be combined, which could lead to smallest number of floating operations.
>
> >
>
> > Thanks,
>
> > Tang Laoya
>
> >
>
>
>
> Hi!
>
>
>
> I do not see a (very) simple approach, but the following seems to work:
>
>
>
> In[1]:= vv =
>
> Det[{{1, 1, 1, 1}, {x1, x2, x3, x4}, {y1, y2, y3, y4}, {z1, z2, z3,
>
> z4}}];
>
>
>
> In[2]:= hf = HornerForm[vv/60, Sort[Variables[vv]]]
>
>
>
> Out[2]= x4*(y3*(z1/60 - z2/60) + y1*(z2/60 - z3/60) +
>
> y2*(-(z1/60) + z3/60)) +
>
> x2*(y4*(z1/60 - z3/60) + y1*(z3/60 - z4/60) +
>
> y3*(-(z1/60) + z4/60)) +
>
> x3*(y4*(-(z1/60) + z2/60) + y2*(z1/60 - z4/60) +
>
> y1*(-(z2/60) + z4/60)) +
>
> x1*(y4*(-(z2/60) + z3/60) + y3*(z2/60 - z4/60) +
>
> y2*(-(z3/60) + z4/60))
>
>
>
> In[3]:= hf //. (a_.)*(x_) + (b_.)*(y_) /;
>
> Abs[a] == Abs[b] && a^2 != 1 :>
>
> Block[{aa = Abs[a]}, aa*((a*x)/aa + (b*y)/aa)]
>
>
>
> Out[3]= (1/60)*(x4*(y3*(z1 - z2) + y1*(z2 - z3) + y2*(-z1 + z3)) +
>
> x2*(y4*(z1 - z3) + y1*(z3 - z4) + y3*(-z1 + z4)) +
>
> x3*(y4*(-z1 + z2) + y2*(z1 - z4) + y1*(-z2 + z4)) +
>
> x1*(y4*(-z2 + z3) + y3*(z2 - z4) + y2*(-z3 + z4)))
>
>
>
> HTH,
>
> Peter

Dear Dr. Peter,

Thank you very much for your kindly reply. Your method can work for the example I posted. However, it still can't work for the final matrix I need to be simplified, could you please help me to take a look at it?

Thanks,
Tang Laoya

The code:

nod = 10;
K = {{b1^2/60 + c1^2/60 + d1^2/60, -((b1 b2)/180) - (c1 c2)/180 - (
d1 d2)/180, -((b1 b3)/180) - (c1 c3)/180 - (d1 d3)/
180, -((b1 b4)/180) - (c1 c4)/180 - (d1 d4)/180,
b1 (-(b1/180) + b2/60) + c1 (-(c1/180) + c2/60) +
d1 (-(d1/180) + d2/60),
b1 (-(b2/180) - b3/180) + c1 (-(c2/180) - c3/180) +
d1 (-(d2/180) - d3/180),
b1 (-(b1/180) + b3/60) + c1 (-(c1/180) + c3/60) +
d1 (-(d1/180) + d3/60),
b1 (-(b3/180) - b4/180) + c1 (-(c3/180) - c4/180) +
d1 (-(d3/180) - d4/180),
b1 (-(b1/180) + b4/60) + c1 (-(c1/180) + c4/60) +
d1 (-(d1/180) + d4/60),
b1 (-(b2/180) - b4/180) + c1 (-(c2/180) - c4/180) +
d1 (-(d2/180) - d4/180)}, {-((b1 b2)/180) - (c1 c2)/180 - (
d1 d2)/180,
b2^2/60 + c2^2/60 + d2^2/60, -((b2 b3)/180) - (c2 c3)/180 - (
d2 d3)/180, -((b2 b4)/180) - (c2 c4)/180 - (d2 d4)/180, (b1 b2)/
60 - b2^2/180 + (c1 c2)/60 - c2^2/180 + (d1 d2)/60 - d2^2/180,
b2 (-(b2/180) + b3/60) + c2 (-(c2/180) + c3/60) +
d2 (-(d2/180) + d3/60), -((b1 b2)/180) - (b2 b3)/180 - (c1 c2)/
180 - (c2 c3)/180 - (d1 d2)/180 - (d2 d3)/180,
b2 (-(b3/180) - b4/180) + c2 (-(c3/180) - c4/180) +
d2 (-(d3/180) - d4/180), -((b1 b2)/180) - (b2 b4)/180 - (c1 c2)/
180 - (c2 c4)/180 - (d1 d2)/180 - (d2 d4)/180,
b2 (-(b2/180) + b4/60) + c2 (-(c2/180) + c4/60) +
d2 (-(d2/180) + d4/60)}, {-((b1 b3)/180) - (c1 c3)/180 - (d1 d3)/
180, -((b2 b3)/180) - (c2 c3)/180 - (d2 d3)/180,
b3^2/60 + c3^2/60 + d3^2/60, -((b3 b4)/180) - (c3 c4)/180 - (
d3 d4)/180, -((b1 b3)/180) - (b2 b3)/180 - (c1 c3)/180 - (c2 c3)/
180 - (d1 d3)/180 - (d2 d3)/180, (b2 b3)/60 - b3^2/180 + (c2 c3)/
60 - c3^2/180 + (d2 d3)/60 - d3^2/180, (b1 b3)/60 - b3^2/180 + (
c1 c3)/60 - c3^2/180 + (d1 d3)/60 - d3^2/180,
b3 (-(b3/180) + b4/60) + c3 (-(c3/180) + c4/60) +
d3 (-(d3/180) + d4/60), -((b1 b3)/180) - (b3 b4)/180 - (c1 c3)/
180 - (c3 c4)/180 - (d1 d3)/180 - (d3 d4)/180, -((b2 b3)/180) - (
b3 b4)/180 - (c2 c3)/180 - (c3 c4)/180 - (d2 d3)/180 - (d3 d4)/
180}, {-((b1 b4)/180) - (c1 c4)/180 - (d1 d4)/
180, -((b2 b4)/180) - (c2 c4)/180 - (d2 d4)/
180, -((b3 b4)/180) - (c3 c4)/180 - (d3 d4)/180,
b4^2/60 + c4^2/60 + d4^2/60, -((b1 b4)/180) - (b2 b4)/180 - (
c1 c4)/180 - (c2 c4)/180 - (d1 d4)/180 - (d2 d4)/
180, -((b2 b4)/180) - (b3 b4)/180 - (c2 c4)/180 - (c3 c4)/180 - (
d2 d4)/180 - (d3 d4)/180, -((b1 b4)/180) - (b3 b4)/180 - (c1 c4)/
180 - (c3 c4)/180 - (d1 d4)/180 - (d3 d4)/180, (b3 b4)/60 - b4^2/
180 + (c3 c4)/60 - c4^2/180 + (d3 d4)/60 - d4^2/180, (b1 b4)/60 -
b4^2/180 + (c1 c4)/60 - c4^2/180 + (d1 d4)/60 - d4^2/180, (
b2 b4)/60 - b4^2/180 + (c2 c4)/60 - c4^2/180 + (d2 d4)/60 - d4^2/
180}, {b1 (-(b1/180) + b2/60) + c1 (-(c1/180) + c2/60) +
d1 (-(d1/180) + d2/60), (b1 b2)/60 - b2^2/180 + (c1 c2)/60 -
c2^2/180 + (d1 d2)/60 - d2^2/180, -((b1 b3)/180) - (b2 b3)/
180 - (c1 c3)/180 - (c2 c3)/180 - (d1 d3)/180 - (d2 d3)/
180, -((b1 b4)/180) - (b2 b4)/180 - (c1 c4)/180 - (c2 c4)/180 - (
d1 d4)/180 - (d2 d4)/180,
b1 ((2 b1)/45 + (2 b2)/45) + (2 b2^2)/45 +
c1 ((2 c1)/45 + (2 c2)/45) + (2 c2^2)/45 +
d1 ((2 d1)/45 + (2 d2)/45) + (2 d2^2)/45,
b2 (b2/45 + b3/45) + b1 (b2/45 + (2 b3)/45) + c2 (c2/45 + c3/45) +
c1 (c2/45 + (2 c3)/45) + d2 (d2/45 + d3/45) +
d1 (d2/45 + (2 d3)/45),
b1 (b1/45 + b2/45 + b3/45) + (2 b2 b3)/45 +
c1 (c1/45 + c2/45 + c3/45) + (2 c2 c3)/45 +
d1 (d1/45 + d2/45 + d3/45) + (2 d2 d3)/45,
b1 (b3/45 + b4/45) + b2 (b3/45 + b4/45) + c1 (c3/45 + c4/45) +
c2 (c3/45 + c4/45) + d1 (d3/45 + d4/45) + d2 (d3/45 + d4/45),
b1 (b1/45 + b2/45 + b4/45) + (2 b2 b4)/45 +
c1 (c1/45 + c2/45 + c4/45) + (2 c2 c4)/45 +
d1 (d1/45 + d2/45 + d4/45) + (2 d2 d4)/45,
b2 (b2/45 + b4/45) + b1 (b2/45 + (2 b4)/45) + c2 (c2/45 + c4/45) +
c1 (c2/45 + (2 c4)/45) + d2 (d2/45 + d4/45) +
d1 (d2/45 + (2 d4)/45)}, {b1 (-(b2/180) - b3/180) +
c1 (-(c2/180) - c3/180) + d1 (-(d2/180) - d3/180),
b2 (-(b2/180) + b3/60) + c2 (-(c2/180) + c3/60) +
d2 (-(d2/180) + d3/60), (b2 b3)/60 - b3^2/180 + (c2 c3)/60 -
c3^2/180 + (d2 d3)/60 - d3^2/180, -((b2 b4)/180) - (b3 b4)/
180 - (c2 c4)/180 - (c3 c4)/180 - (d2 d4)/180 - (d3 d4)/180,
b2 (b2/45 + b3/45) + b1 (b2/45 + (2 b3)/45) + c2 (c2/45 + c3/45) +
c1 (c2/45 + (2 c3)/45) + d2 (d2/45 + d3/45) +
d1 (d2/45 + (2 d3)/45),
b2 ((2 b2)/45 + (2 b3)/45) + (2 b3^2)/45 +
c2 ((2 c2)/45 + (2 c3)/45) + (2 c3^2)/45 +
d2 ((2 d2)/45 + (2 d3)/45) + (2 d3^2)/45,
b1 ((2 b2)/45 + b3/45) + (b2 b3)/45 + b3^2/45 +
c1 ((2 c2)/45 + c3/45) + (c2 c3)/45 + c3^2/45 +
d1 ((2 d2)/45 + d3/45) + (d2 d3)/45 + d3^2/45,
b3 (b3/45 + b4/45) + b2 (b3/45 + (2 b4)/45) + c3 (c3/45 + c4/45) +
c2 (c3/45 + (2 c4)/45) + d3 (d3/45 + d4/45) +
d2 (d3/45 + (2 d4)/45),
b1 (b2/45 + b3/45) + (b2 b4)/45 + (b3 b4)/45 +
c1 (c2/45 + c3/45) + (c2 c4)/45 + (c3 c4)/45 +
d1 (d2/45 + d3/45) + (d2 d4)/45 + (d3 d4)/45,
b2 (b2/45 + b3/45 + b4/45) + (2 b3 b4)/45 +
c2 (c2/45 + c3/45 + c4/45) + (2 c3 c4)/45 +
d2 (d2/45 + d3/45 + d4/45) + (2 d3 d4)/
45}, {b1 (-(b1/180) + b3/60) + c1 (-(c1/180) + c3/60) +
d1 (-(d1/180) + d3/60), -((b1 b2)/180) - (b2 b3)/180 - (c1 c2)/
180 - (c2 c3)/180 - (d1 d2)/180 - (d2 d3)/180, (b1 b3)/60 - b3^2/
180 + (c1 c3)/60 - c3^2/180 + (d1 d3)/60 - d3^2/
180, -((b1 b4)/180) - (b3 b4)/180 - (c1 c4)/180 - (c3 c4)/180 - (
d1 d4)/180 - (d3 d4)/180,
b1 (b1/45 + b2/45 + b3/45) + (2 b2 b3)/45 +
c1 (c1/45 + c2/45 + c3/45) + (2 c2 c3)/45 +
d1 (d1/45 + d2/45 + d3/45) + (2 d2 d3)/45,
b1 ((2 b2)/45 + b3/45) + (b2 b3)/45 + b3^2/45 +
c1 ((2 c2)/45 + c3/45) + (c2 c3)/45 + c3^2/45 +
d1 ((2 d2)/45 + d3/45) + (d2 d3)/45 + d3^2/45,
b1 ((2 b1)/45 + (2 b3)/45) + (2 b3^2)/45 +
c1 ((2 c1)/45 + (2 c3)/45) + (2 c3^2)/45 +
d1 ((2 d1)/45 + (2 d3)/45) + (2 d3^2)/45,
b3 (b3/45 + b4/45) + b1 (b3/45 + (2 b4)/45) + c3 (c3/45 + c4/45) +
c1 (c3/45 + (2 c4)/45) + d3 (d3/45 + d4/45) +
d1 (d3/45 + (2 d4)/45),
b1 (b1/45 + b3/45 + b4/45) + (2 b3 b4)/45 +
c1 (c1/45 + c3/45 + c4/45) + (2 c3 c4)/45 +
d1 (d1/45 + d3/45 + d4/45) + (2 d3 d4)/45, (b2 b3)/45 +
b1 (b2/45 + b4/45) + (b3 b4)/45 + (c2 c3)/45 +
c1 (c2/45 + c4/45) + (c3 c4)/45 + (d2 d3)/45 +
d1 (d2/45 + d4/45) + (d3 d4)/45}, {b1 (-(b3/180) - b4/180) +
c1 (-(c3/180) - c4/180) + d1 (-(d3/180) - d4/180),
b2 (-(b3/180) - b4/180) + c2 (-(c3/180) - c4/180) +
d2 (-(d3/180) - d4/180),
b3 (-(b3/180) + b4/60) + c3 (-(c3/180) + c4/60) +
d3 (-(d3/180) + d4/60), (b3 b4)/60 - b4^2/180 + (c3 c4)/60 -
c4^2/180 + (d3 d4)/60 - d4^2/180,
b1 (b3/45 + b4/45) + b2 (b3/45 + b4/45) + c1 (c3/45 + c4/45) +
c2 (c3/45 + c4/45) + d1 (d3/45 + d4/45) + d2 (d3/45 + d4/45),
b3 (b3/45 + b4/45) + b2 (b3/45 + (2 b4)/45) + c3 (c3/45 + c4/45) +
c2 (c3/45 + (2 c4)/45) + d3 (d3/45 + d4/45) +
d2 (d3/45 + (2 d4)/45),
b3 (b3/45 + b4/45) + b1 (b3/45 + (2 b4)/45) + c3 (c3/45 + c4/45) +
c1 (c3/45 + (2 c4)/45) + d3 (d3/45 + d4/45) +
d1 (d3/45 + (2 d4)/45),
b3 ((2 b3)/45 + (2 b4)/45) + (2 b4^2)/45 +
c3 ((2 c3)/45 + (2 c4)/45) + (2 c4^2)/45 +
d3 ((2 d3)/45 + (2 d4)/45) + (2 d4^2)/45,
b1 ((2 b3)/45 + b4/45) + (b3 b4)/45 + b4^2/45 +
c1 ((2 c3)/45 + c4/45) + (c3 c4)/45 + c4^2/45 +
d1 ((2 d3)/45 + d4/45) + (d3 d4)/45 + d4^2/45,
b2 ((2 b3)/45 + b4/45) + (b3 b4)/45 + b4^2/45 +
c2 ((2 c3)/45 + c4/45) + (c3 c4)/45 + c4^2/45 +
d2 ((2 d3)/45 + d4/45) + (d3 d4)/45 + d4^2/
45}, {b1 (-(b1/180) + b4/60) + c1 (-(c1/180) + c4/60) +
d1 (-(d1/180) + d4/60), -((b1 b2)/180) - (b2 b4)/180 - (c1 c2)/
180 - (c2 c4)/180 - (d1 d2)/180 - (d2 d4)/180, -((b1 b3)/180) - (
b3 b4)/180 - (c1 c3)/180 - (c3 c4)/180 - (d1 d3)/180 - (d3 d4)/
180, (b1 b4)/60 - b4^2/180 + (c1 c4)/60 - c4^2/180 + (d1 d4)/60 -
d4^2/180,
b1 (b1/45 + b2/45 + b4/45) + (2 b2 b4)/45 +
c1 (c1/45 + c2/45 + c4/45) + (2 c2 c4)/45 +
d1 (d1/45 + d2/45 + d4/45) + (2 d2 d4)/45,
b1 (b2/45 + b3/45) + (b2 b4)/45 + (b3 b4)/45 +
c1 (c2/45 + c3/45) + (c2 c4)/45 + (c3 c4)/45 +
d1 (d2/45 + d3/45) + (d2 d4)/45 + (d3 d4)/45,
b1 (b1/45 + b3/45 + b4/45) + (2 b3 b4)/45 +
c1 (c1/45 + c3/45 + c4/45) + (2 c3 c4)/45 +
d1 (d1/45 + d3/45 + d4/45) + (2 d3 d4)/45,
b1 ((2 b3)/45 + b4/45) + (b3 b4)/45 + b4^2/45 +
c1 ((2 c3)/45 + c4/45) + (c3 c4)/45 + c4^2/45 +
d1 ((2 d3)/45 + d4/45) + (d3 d4)/45 + d4^2/45,
b1 ((2 b1)/45 + (2 b4)/45) + (2 b4^2)/45 +
c1 ((2 c1)/45 + (2 c4)/45) + (2 c4^2)/45 +
d1 ((2 d1)/45 + (2 d4)/45) + (2 d4^2)/45,
b1 ((2 b2)/45 + b4/45) + (b2 b4)/45 + b4^2/45 +
c1 ((2 c2)/45 + c4/45) + (c2 c4)/45 + c4^2/45 +
d1 ((2 d2)/45 + d4/45) + (d2 d4)/45 + d4^2/
45}, {b1 (-(b2/180) - b4/180) + c1 (-(c2/180) - c4/180) +
d1 (-(d2/180) - d4/180),
b2 (-(b2/180) + b4/60) + c2 (-(c2/180) + c4/60) +
d2 (-(d2/180) + d4/60), -((b2 b3)/180) - (b3 b4)/180 - (c2 c3)/
180 - (c3 c4)/180 - (d2 d3)/180 - (d3 d4)/180, (b2 b4)/60 - b4^2/
180 + (c2 c4)/60 - c4^2/180 + (d2 d4)/60 - d4^2/180,
b2 (b2/45 + b4/45) + b1 (b2/45 + (2 b4)/45) + c2 (c2/45 + c4/45) +
c1 (c2/45 + (2 c4)/45) + d2 (d2/45 + d4/45) +
d1 (d2/45 + (2 d4)/45),
b2 (b2/45 + b3/45 + b4/45) + (2 b3 b4)/45 +
c2 (c2/45 + c3/45 + c4/45) + (2 c3 c4)/45 +
d2 (d2/45 + d3/45 + d4/45) + (2 d3 d4)/45, (b2 b3)/45 +
b1 (b2/45 + b4/45) + (b3 b4)/45 + (c2 c3)/45 +
c1 (c2/45 + c4/45) + (c3 c4)/45 + (d2 d3)/45 +
d1 (d2/45 + d4/45) + (d3 d4)/45,
b2 ((2 b3)/45 + b4/45) + (b3 b4)/45 + b4^2/45 +
c2 ((2 c3)/45 + c4/45) + (c3 c4)/45 + c4^2/45 +
d2 ((2 d3)/45 + d4/45) + (d3 d4)/45 + d4^2/45,
b1 ((2 b2)/45 + b4/45) + (b2 b4)/45 + b4^2/45 +
c1 ((2 c2)/45 + c4/45) + (c2 c4)/45 + c4^2/45 +
d1 ((2 d2)/45 + d4/45) + (d2 d4)/45 + d4^2/45,
b2 ((2 b2)/45 + (2 b4)/45) + (2 b4^2)/45 +
c2 ((2 c2)/45 + (2 c4)/45) + (2 c4^2)/45 +
d2 ((2 d2)/45 + (2 d4)/45) + (2 d4^2)/45}};
For[ii = 1, ii <= nod,
For[jj = 1, jj <= nod,
K[[ii, jj]] = HornerForm[K[[ii, jj]], Sort[Variables[K[[ii, jj]]]]];
K[[ii, jj]] //. (a_.)*(x_) + (b_.)*(y_) /;
Abs[a] == Abs[b] && a^2 != 1 :>
Block[{aa = Abs[a]}, aa*((a*x)/aa + (b*y)/aa)];
jj++];
ii++];
kk = K

Date Subject Author
11/22/12 Tang Laoya
11/22/12 Nasser Abbasi
11/22/12 Nasser Abbasi
11/22/12 Tang Laoya
11/22/12 Nasser Abbasi
11/22/12 Tang Laoya
11/22/12 Nasser Abbasi
11/22/12 Tang Laoya
11/22/12 Tang Laoya
11/22/12 Nasser Abbasi
11/22/12 Tang Laoya
11/23/12 Peter Pein
11/23/12 Tang Laoya
11/23/12 Richard Fateman