0
$\begingroup$

I have a code that produces two lists to be animated using ListAnimate and I want to have these two animations taking place on the same plot but I can't see a clear way to do this and was wondering if anyone could help or had any ideas?

The values I am using are:

cVal = {1., 0.8090169943749475, 
   0.30901699437494745, -0.30901699437494745, -0.8090169943749475, 
-1., -0.8090169943749475, -0.30901699437494745, 
   0.30901699437494745, 0.8090169943749475, 1.};


sVal = {0., 0.5877852522924731, 0.9510565162951535, 
   0.9510565162951535, 0.5877852522924731, 
   0., -0.5877852522924731, -0.9510565162951535, 
-0.9510565162951535, -0.5877852522924731, 0.};


solVals = {{0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 
    0.125, 0.125, 0.125, 0.125}, {0.12490148827035571, 
    0.12464449866763125, 0.12442505176003116, 0.1244223463177388, 
    0.12463736991663273, 0.12499191997994591, 0.1253531547434718, 
    0.12558070842365024, 0.12558354323701965, 0.12536051828017497, 
    0.1250994004033477}, {0.12480384709546988, 0.1242939341780157, 
    0.12385862558252374, 0.12384799275047834, 0.12426573496222888, 
    0.12496769300729224, 0.12569636813682097, 0.12616421257572788, 
    0.12617574946914567, 0.1257261340087955, 
    0.1251997082335011}, {0.12470708257569338, 0.12394825285367117,
     0.12330064002945827, 0.12327715902511607, 0.12388555678367119,
     0.1249273562850483, 0.12602919036770016, 0.1267502550644418, 
    0.1267766885931119, 0.12609690114465189, 
    0.12530091727743586}, {0.12461120068883887, 0.1236073951160553,
     0.12275100275202656, 0.12271007702920879, 0.12349734772541728,
     0.1248709740470937, 0.12635112913506485, 0.1273385398615683, 
    0.12738643468770763, 0.12647287907280338, 
    0.12540301988421534}, {0.12451620597345099, 
    0.12327130632752725, 0.12220962673019696, 0.12214694486285972, 
    0.12310157717049357, 0.1247986333640127, 0.12666174196262933, 
    0.1279287826296457, 0.1280050512784557, 0.1268541216286478, 
    0.12550600807208026}, {0.12442210234560008, 
    0.12293993046137541, 0.12167642116190003, 0.12158795438046, 
    0.12269872499996635, 0.12471044547575386, 0.12696058324786766, 
    0.1285206818181489, 0.12863259986320424, 0.1272406834263168, 
    0.12560987281940664}, {0.12432889300763066, 
    0.12261321145350433, 0.12115129358146054, 0.12103328614526516, 
    0.12228926966459856, 0.12460654426849799, 0.1272472158550164, 
    0.12911392521428341, 0.12926913806764226, 0.12763261852451369, 
    0.12571460421758704}, {0.12423658035218303, 
    0.12229109323322443, 0.12063414972822373, 0.12048310761517643, 
    0.12187368710919808, 0.12448708981559341, 0.12752121342394807, 
    0.1297081883650303, 0.12991471880821223, 0.1280299802631563, 
    0.12582019128605407}, {0.12414516614006692, 
    0.12197351978111352, 0.12012489409055069, 0.11993757558871533, 
    0.12145245000629556, 0.12435226329714764, 0.12778215973303794, 
    0.13030313710125782, 0.13056939084851202, 0.12843282129358177, 
    0.12592662211972083}, {0.12405465147008787, 0.1216604351616048,
     0.11962342991308532, 0.11939683547817558, 0.12102602690488753,
     0.12420226834101644, 0.12802965013098178, 0.13089842700822404,
     0.13123319833473931, 0.12884119346758624, 
    0.12603388378961122}};

These give the following plots

base = Table[
   ListLinePlot[Partition[Riffle[Flatten[cVal], Flatten[sVal]], 2], 
    AspectRatio -> Full], {l, 1, 11}];

outer = Table[
   ListLinePlot[
    Partition[
     Riffle[Table[solVals[[j]]*cVal + cVal, {j, 1, 11}][[l]], 
      Table[solVals[[j]]*sVal + sVal, {j, 1, 11}][[l]]], 2], 
    AspectRatio -> Full, PlotRange -> {{-1.5, 1.5}, {-1.5, 1.5}}], {l,1, 11}];

Using ListAnimate[base] gives a fixed plot centred at the origin and ListAnimate[outer] gives another plot initially fixed on the origin but moves away from its initial position as time passes.

$\endgroup$
  • $\begingroup$ Table[Show[outer[[i]], base[[i]]], {i, 1, 11}]? $\endgroup$ – MelaGo Oct 29 at 0:31
2
$\begingroup$

First an alternative, more streamlined, way to construct outer:

tbl = Transpose[{cVal + cVal #, sVal + sVal #}] & /@ solVals; 

outer2 = ListLinePlot[#, 
  AspectRatio -> Full, 
  PlotRange -> {{-1.5, 1.5}, {-1.5, 1.5}}] & /@ tbl;

outer2 == outer

True

baseplot = ListLinePlot[Transpose[{cVal, sVal}], PlotStyle -> Red];

ListAnimate[Show[#, baseplot] & /@ outer2]

enter image description here

The movement is almost imperceptible.

Using scaled-up versions of the input data makes the movement more visible:

tblB = Transpose[{cVal + cVal #, sVal + sVal #}] & /@ (10000 solVals); 

outer2B = ListLinePlot[#, AspectRatio -> Full, 
    PlotRange -> {1000 {-1.5, 1.5}, 1000 {-1.5, 1.5}}] & /@ tblB;

baseplotB = ListLinePlot[Transpose[1000 {cVal, sVal}], PlotStyle -> Red];

ListAnimate[Show[#, baseplotB] & /@ outer2B]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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