vectorgraphics / asymptote

2D & 3D TeX-Aware Vector Graphics Language
https://asymptote.sourceforge.io/
GNU General Public License v3.0
542 stars 90 forks source link

mapArray #332

Closed abrombo closed 2 years ago

abrombo commented 2 years ago

Need better documentation on mapArray. I tried to use it to use it with mapArray("real[]","pair[]") and got -

import graph; import math; import gsl; import settings; settings.outformat="pdf";

real T = 1.0; real tau = 0.5; real Nper = 5.0; real per = T/Nper; real Period = 2*T;

real F(real t) { real mod_t = t % (2*T); if (mod_t > T) { return 0.0; }

real arg = 2.0pimod_t/per; return exp(-mod_t/tau)*sin(arg); }

pair Fpair(real t) { pair Z = (F(t),0); return Z; }

//size(1000,1000,IgnoreAspect);

//xaxis("$t$",LeftTicks,Arrow); //yaxis("$y$",RightTicks,Arrow);

//draw(" ",graph(F,0,4,4000));

int Nt = 16;

int[] index = sequence(Nt); write(index); real[] t_array = (Period/(real)Nt)*index; write(t_array); mapArray("real[]","pair[]"); pair[] Fmap = map(Fpair,t_array); write(Fmap);

0: 0 1: 1 2: 2 3: 3 4: 4 5: 5 6: 6 7: 7 8: 8 9: 9 10: 10 11: 11 12: 12 13: 13 14: 14 15: 15 0: 0 1: 0.125 2: 0.25 3: 0.375 4: 0.5 5: 0.625 6: 0.75 7: 0.875 8: 1 9: 1.125 10: 1.25 11: 1.375 12: 1.5 13: 1.625 14: 1.75 15: 1.875 ./abe.asy: 45.1: no matching variable 'mapArray'

I can find no documentation on what I need to include to use mapArray.

johncbowman commented 2 years ago

First of all, you need to fix the missing * here: real arg = 2.0pimod_t/per;

Following the documentation, you then need to use mapArray("real","pair");