Re: Question about subscripts and polynomial
- To: mathgroup at smc.vnet.net
- Subject: [mg107469] Re: [mg107355] Question about subscripts and polynomial
- From: Luca Zanotti Fragonara <Luca.Zanottifragonara at polito.it>
- Date: Sat, 13 Feb 2010 05:24:46 -0500 (EST)
- References: <201002100836.DAA21317@smc.vnet.net> <op.u7xj9seetgfoz2@bobbys-imac.local>
Hello, I've finally solved the problem, in this way: Clear["Global`*"]; Poly = d^2*v; Subscript[q, 1] = Poly /. {d -> Sum[Subscript[d, i], {i, 1, 11}]} /. {v -> Sum[Subscript[v, i], {i, 1, 11}]}; basicSum = Expand[Subscript[q, 1]] /. {Subscript[d, 2] -> 0, Subscript[d, 4] -> 0, Subscript[d, 6] -> 0, Subscript[d, 8] -> 0, Subscript[d, 10] -> 0, Subscript[v, 2] -> 0, Subscript[v, 4] -> 0, Subscript[v, 6] -> 0, Subscript[v, 8] -> 0, Subscript[v, 10] -> 0}; listSumnotord = basicSum /. Plus -> List; Coeff = listSumnotord /. Table[Rule[Subscript[d, i], 1], {i, 1, 11}] /. Table[Rule[Subscript[v, i], 1], {i, 1, 11}]; WithoutCoeff = listSumnotord/Coeff; order[term_] := term /. Times -> Plus /. Power -> Times /. Subscript[_, k_] :> k; listSum = SortBy[WithoutCoeff, order]; displaySum = Infix[listSum, "+"] Now it gives to me a List (WithoutCoeff) wich is in the order that I initially wanted. The only problem is that I would like to rebuild the polynomial with also the coefficients. How do I reorder the Coeff List, in the same way that I've reordered the Coeff List? Sorry, but I'm a user of another system, and I'm a bit confused, the approach in Mathematica is totally different, and especially for simple problem, I found it very difficult to handle because I always think at how would I solve the problem in another system! Thank you in advance, Luca DrMajorBob ha scritto: > I'm not entirely sure what ordering you want, but here's something to > get you on the way. > > You can tweak the "order" function if needed. > > First, your original expansion: > > poly = d^2*v; > Subscript[q, 1] = > poly /. {d -> Sum[Subscript[d, i], {i, 1, 3}]} /. {v -> > Sum[Subscript[v, i], {i, 1, 3}]}; > basicSum = Expand[Subscript[q, 1]] > > (ugly output omitted; it looks fine in Mathematica) > > Here's the same thing transformed to a List and sorted by the total > order of each product: > > order[term_] := > term /. Times -> Plus /. Power -> Times /. Subscript[_, k_] :> k > listSum = SortBy[basicSum /. Plus -> List, order] > > (ugly output omitted; it looks fine in Mathematica) > > That's a List, not a sum; the following is also NOT a sum, but it > looks like one, sorted the same as listSum: > > displaySum = Infix[listSum, "+"] > > (ugly output omitted; it looks fine in Mathematica) > > To get back the original: > > backToBasics = Plus @@ displaySum[[1]]; > basicSum === backToBasics > > True > > Bobby > > On Wed, 10 Feb 2010 02:36:40 -0600, Luca Zanotti Fragonara > <Luca.Zanottifragonara at polito.it> wrote: > >> Hello everybody, >> >> I would like to write a Polynomial, in this way: >> >> Poly = d^2*v >> Subscript[q, 1] = >> Poly /. {d -> Sum[Subscript[d, i], {i, 1, 3}]} /. {v ->Sum[Subscript[v, >> i], {i, 1, 3}]} >> Expand[Subscript[q, 1]] >> >> In this way I will obtain a polynomial in this form: >> >> d_1^2 v_1+2 d_1 d_2 v_1+d_2^2 v_1+2 d_1 d_3 v_1+2 d_2 d_3 v_1+d_3^2 >> v_1+d_1^2 v_2+2 d_1 d_2 v_2+d_2^2 v_2+2 d_1 d_3 v_2+2 d_2 d_3 v_2+d_3^2 >> v_2+d_1^2 v_3+2 d_1 d_2 v_3+d_2^2 v_3+2 d_1 d_3 v_3+2 d_2 d_3 >> v_3+d_3^2 v_3 >> >> I would like to reorder the expanded polynomial in a way such that the >> terms with lower subcripts indexes will be at the beginning of the >> polynomial, and the terms with higher order of subscripts will be at the >> end (a sort of order due to the subscript instead of the power terms). >> So the order should be something: >> >> Order 3: d_1^2 v_1 >> Order 4: 2 d_1 d_2 v_1+d_1^2 v_2+... >> Order 5: d_2^2 v_1+2 d_1 d_3 v_1+... >> Order 6: 2 d_2 d_3 v_1+... >> >> I've tried to figure it out but I don't know which way to turn!!! >> >> Thank you in advance. >> >> Luca >> >> >> > >
- References:
- Question about subscripts and polynomial
- From: Luca Zanotti Fragonara <Luca.Zanottifragonara@polito.it>
- Question about subscripts and polynomial