MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: plotting many curves

  • To: mathgroup at smc.vnet.net
  • Subject: [mg108331] Re: plotting many curves
  • From: Guido Tripaldi <guido at gtripaldi.it>
  • Date: Sun, 14 Mar 2010 05:13:06 -0500 (EST)

In this case just using "Table" (since the For cycle is just used in this case to increment an index), and without the need to null-initialize the array (since it is dynamically created during evalutation):

(*--------initialization------------------*)
n == 10^2;
xoi == RandomReal[{-10, 10}, {n}];
yoi == RandomReal[{-10, 10}, {n}];
ri == RandomReal[{0, 10}, {n}];

n == 10^2;
circles ==
  Table[{xoi[[i]] + ri[[i]]*Cos[t], yoi[[i]] + ri[[i]]*Sin[t]}, {i,
    n}];

(*---------------displaying--------------------*) \
ParametricPlot[circles, {t, 0, 2 Pi}, PlotStyle -> Black]



using Table you gain also a little extra performance:

Timing[For[i == 1, i <== n, i++,
  circles[[i]] == {xoi[[i]] + ri[[i]]*Cos[t],
    yoi[[i]] + ri[[i]]*Sin[t]}]]

{0.001701, Null}



Timing[circles ==
   Table[{xoi[[i]] + ri[[i]]*Cos[t], yoi[[i]] + ri[[i]]*Sin[t]}, {i,
     n}];]

{0.001162, Null}


Cheers,
   G


Il giorno 13/mar/2010, alle ore 13.57, eric g ha scritto:

> Hello Group,
>
> I know I should avoid For cycles in mathematica, but I am C person...
> how to do this without For
>
> (*--------initialization------------------*)
> n == 10^2;
> xoi == RandomReal[{-10, 10}, {n}];
> yoi == RandomReal[{-10, 10}, {n}];
> ri == RandomReal[{0, 10}, {n}];
> -----------------------------------
> (*
>
> n==10^2;
> Clear[circles];
> circles == Table[Null, {n}];
> For[i == 1, i <== n, i++,
>  circles[[i]] == {xoi[[i]] + ri[[i]]*Cos[t], yoi[[i]] + ri[[i]]*Sin[t]}]
>
> (*---------------displaying--------------------*)
> ParametricPlot[circles, {t, 0, 2 Pi}, PlotStyle -> Black]
>
>
>

---
Guido Tripaldi




  • Prev by Date: Re: plotting many curves
  • Next by Date: Re: bad Mathieu functions
  • Previous by thread: Re: plotting many curves
  • Next by thread: Re: plotting many curves