1
$\begingroup$

I have created a list in Mathematica and for some reason it does not want to Plot my list in pairs {x1,y1}, but instead does {y1,y2} even though I partitioned the list to make it in the correct format. Here is the code:

Dynamic[h = w[1.1][[All, 2]] + w[2.1][[All, 2]] + w[3.1][[All, 2]] + 
   w[4.1][[All, 2]] + w[5.1][[All, 2]] + w[6.1][[All, 2]] + w[7.1][[All, 2]] + 
   w[8.1][[All, 2]] + w[9.1][[All, 2]] + w[10.1][[All, 2]]]
k = Table[l + Pi/50, {l, -Pi/50, 49 Pi/50, Pi/50}]
Dynamic[List[p = Riffle[k, h/g]]]
Dynamic[Partition[p, 2]]
Dynamic[ListPlot[p]]

The first line takes previously made lists and adds the value of their second column -> (x1, y1) and (x2,y2) returns y3 where y3 = y1+y2. Then a new table from 0 to Pi is created. Then a new list is made, p, with riffle to make x-values go from 0 to Pi and y values are the values from table h. Then the values are partitioned into pairs (x1,y1). Finally, the list should be plotted. But again, Mathematica does (y1,y2,...) and not in pairs.

Little help? Thanks.

g is a constant between 1 and 10. Below is Full Form p.

List[0,1.`,Times[Rational[1,50],Pi],1.`,Times[Rational[1,25],Pi],0.7507598383409988`,Times[Rational[3,50],Pi],0.7507598383409988`,Times[Rational[2,25],Pi],0.7507598383409988`,Times[Rational[1,10],Pi],0.7507598383409988`,Times[Rational[3,25],Pi],0.7507598383409988`,Times[Rational[7,50],Pi],0.7507598383409988`,Times[Rational[4,25],Pi],0.7507598383409988`,Times[Rational[9,50],Pi],0.7507598383409988`,Times[Rational[1,5],Pi],0.7515548444052627`,Times[Rational[11,50],Pi],0.7599302324995563`,Times[Rational[6,25],Pi],0.7691783335090264`,Times[Rational[13,50],Pi],0.779262649404044`,Times[Rational[7,25],Pi],0.7901433819968573`,Times[Rational[3,10],Pi],0.8017775900068562`,Times[Rational[8,25],Pi],0.8141193585301891`,Times[Rational[17,50],Pi],0.8271199802449125`,Times[Rational[9,25],Pi],0.8407281476365374`,Times[Rational[19,50],Pi],0.8548901554853492`,Times[Rational[2,5],Pi],0.8695501128163745`,Times[Rational[21,50],Pi],0.8868534924648825`,Times[Rational[11,25],Pi],0.9050207506466612`,Times[Rational[23,50],Pi],0.9235628485337459`,Times[Rational[12,25],Pi],0.9424066089368552`,Times[Rational[1,2],Pi],0.9614776641425731`,Times[Rational[13,25],Pi],0.9807007494087392`,Times[Rational[27,50],Pi],1.`,Times[Rational[14,25],Pi],1.0192992505912608`,Times[Rational[29,50],Pi],1.0385223358574267`,Times[Rational[3,5],Pi],1.0575933910631448`,Times[Rational[31,50],Pi],1.076437151466254`,Times[Rational[16,25],Pi],1.0949792493533388`,Times[Rational[33,50],Pi],1.1131465075351175`,Times[Rational[17,25],Pi],1.1115136239813286`,Times[Rational[7,10],Pi],1.126173581312354`,Times[Rational[18,25],Pi],1.140335589161166`,Times[Rational[37,50],Pi],1.1539437565527906`,Times[Rational[19,25],Pi],1.166944378267514`,Times[Rational[39,50],Pi],1.1792861467908469`,Times[Rational[4,5],Pi],1.1909203548008458`,Times[Rational[41,50],Pi],1.201801087393659`,Times[Rational[21,25],Pi],1.2118854032886768`,Times[Rational[43,50],Pi],1.2211335042981468`,Times[Rational[22,25],Pi],1.2295088923924404`,Times[Rational[9,10],Pi],1.`,Times[Rational[23,25],Pi],1.`,Times[Rational[47,50],Pi],1.`,Times[Rational[24,25],Pi],1.`,Times[Rational[49,50],Pi],1.`,Pi,1.`]
$\endgroup$
4
  • $\begingroup$ What is g? In any case not possible to answer without seeing p. Please evaluate FullForm[p] and add it to the question. $\endgroup$ Jan 25, 2013 at 0:32
  • $\begingroup$ Using the definition of p that you just added ListPlot[p] works in version 7 on Windows: i.stack.imgur.com/toApn.png $\endgroup$
    – Mr.Wizard
    Jan 25, 2013 at 0:38
  • $\begingroup$ The image just provided by Mr. Wizard is my problem. The values of Pi should be x-axis while the numerical values should be y values. $\endgroup$ Jan 25, 2013 at 0:44
  • $\begingroup$ You are plotting p not the Partitioned expression. $\endgroup$
    – Verbeia
    Jan 25, 2013 at 0:58

1 Answer 1

2
$\begingroup$

You are plotting p not the Partitioned expression. Merge the last two lines to read Dynamic[ListPlot[Partition[p,2]]] and it should work. You might need to Reverse each row so the $y$ values are second:

Dynamic[ListPlot[Reverse/@ Partition[p,2]]]
$\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.