1
$\begingroup$

I've created a symmetric series with powers
$${-n,-(n-1),\cdots,-1,0,1,2,\cdots,n}$$

and wish to study the convergence of the series as a function of the number of symmetric terms. So I first start with the 0 term, then choose the (-1,0,1) terms, then the (-2,-1,0,1,2) terms and so on. I am sure Partition can segregate the terms this way but do not understand the documentation to code this and was wondering if someone could help me code it using Partition if that's possible?

Thanks,

$\endgroup$
4
  • $\begingroup$ I do not get your question. Maybe some concrete code and a clearer description of your objective would help... $\endgroup$ May 12, 2019 at 11:32
  • $\begingroup$ Ok, I have the list: mylist= {-15,-14,...,-2,-1,0,1,2,...15}. Now I want to create the lists {{0},{-1,0,1},{-2,-1,0,1,2},...mylist} and I can of course brute-force hack some code to create this but I would like to know if Partition or another function could do it more simply. Also, I don't wish to simply create a sub-list of numbers like above, that was just a simple example. The actual data I have is a power series. $\endgroup$
    – Dominic
    May 12, 2019 at 11:34
  • 1
    $\begingroup$ mylist[[# ;; Length[mylist] - # + 1]] & /@ Range[(Length[mylist] + 1)/2,1, -1]? $\endgroup$
    – kglr
    May 12, 2019 at 11:47
  • $\begingroup$ Thanks, that works. I tried using Take but it's a bit unsophisticated: myTable = Table[a/3 x^(a/3), {a, -5, 5}] myLists = {}; For[i = 0, i <= 5, i++, myLists = Append[myLists, Take[myTable, {6 - i, 6 + i}]]; ]; myLists $\endgroup$
    – Dominic
    May 12, 2019 at 11:57

2 Answers 2

1
$\begingroup$
ClearAll[f1, f2, f3]
f1[l_List] := Reverse@NestList[Take[#, {2, -2}] &, l, (Length[l] - 1)/2]
f2[l_List] := Reverse@NestList[Delete[#, {{1}, {-1}}] &, l, (Length[l] - 1)/2]
f3[l_List] := l[[# ;; -#]] & /@ Range[(Length[l] + 1)/2, 1, -1]


mylist = Range[-5, 5];
f1 @mylist

{{0},
{-1, 0, 1},
{-2, -1, 0, 1, 2},
{-3, -2, -1, 0, 1, 2, 3},
{-4, -3, -2, -1, 0, 1, 2, 3, 4},
{-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5}}

f1[mylist] == f2[mylist] == f3[mylist]

True

myTable = Table[a/3 x^(a/3), {a, -5, 5}] ;
f1 @ myTable // Column // TeXForm

$\begin{array}{l} \{0\} \\ \left\{-\frac{1}{3 \sqrt[3]{x}},0,\frac{\sqrt[3]{x}}{3}\right\} \\ \left\{-\frac{2}{3 x^{2/3}},-\frac{1}{3 \sqrt[3]{x}},0,\frac{\sqrt[3]{x}}{3},\frac{2 x^{2/3}}{3}\right\} \\ \left\{-\frac{1}{x},-\frac{2}{3 x^{2/3}},-\frac{1}{3 \sqrt[3]{x}},0,\frac{\sqrt[3]{x}}{3},\frac{2 x^{2/3}}{3},x\right\} \\ \left\{-\frac{4}{3 x^{4/3}},-\frac{1}{x},-\frac{2}{3 x^{2/3}},-\frac{1}{3 \sqrt[3]{x}},0,\frac{\sqrt[3]{x}}{3},\frac{2 x^{2/3}}{3},x,\frac{4 x^{4/3}}{3}\right\} \\ \left\{-\frac{5}{3 x^{5/3}},-\frac{4}{3 x^{4/3}},-\frac{1}{x},-\frac{2}{3 x^{2/3}},-\frac{1}{3 \sqrt[3]{x}},0,\frac{\sqrt[3]{x}}{3},\frac{2 x^{2/3}}{3},x,\frac{4 x^{4/3}}{3},\frac{5 x^{5/3}}{3}\right\} \\ \end{array}$

You can also construct the list directly without having to create myTable first:

Table[a/3 x^(a/3), {j, 0, 5}, {a, -j, j}] == f1 @ myTable 

True

$\endgroup$
1
$\begingroup$

Thanks guys. Here is the code I used (using kglr's code) to generate a convergence plot of 15 symmetric terms (31 terms of the power series are in myVal). Note how the partial series are converging to the red dot with just 31 terms. enter image description here:

actualValue = {-0.32668, 0.4685};
actualPoint = Graphics[{PointSize[0.01], Red, 
Point[actualValue]}];
mylist = myVal;
newList = 
mylist[[# ;; Length[mylist] - # + 1]] & /@ 
 Range[(Length[mylist] + 1)/2, 1, -1];
partialTerms = Plus @@ # & /@ newList;
Show[{ListPlot[({Re[#], Im[#]} & /@ (partialTerms /. 
  z -> 1/3)),Joined -> True], actualPoint}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.