MathGroup Archive 2010

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

Search the Archive

Re: Plotting a function dynamically in a loop

  • To: mathgroup at smc.vnet.net
  • Subject: [mg112908] Re: Plotting a function dynamically in a loop
  • From: "Nasser M. Abbasi" <nma at 12000.org>
  • Date: Tue, 5 Oct 2010 05:36:43 -0400 (EDT)
  • References: <i8c8ub$g9p$1@smc.vnet.net>
  • Reply-to: nma at 12000.org

On 10/4/2010 3:06 AM, ABHIJIT BHATTACHARYYA wrote:
> Hi!
>
>   Let us consider that I have one 3D array ex[[i,j,k]] which is computed
>   in time loop as given here.
>
>   alfa=0.3; beta=0.4; gamma== 0.5;=0A For[time=0, time<= maxtime, time++,
>   Do[ex[[i,j,k]] = alfa*i+beta*j+gamma*k, {i,1,imax}, {j,2,jmax+1},{k,1,kmax}]
>
>   (* Plot ex[[]]= dynamically *)
>   ]
>
> What I want is that I like to plot ex[[i,j,k]] at every time step in a  single plot so that plot is revealed as a movie.  Is it possible in
>   mathematica?
>
>   Regs
>   Abhijit Bhattacharyya

And here is a bouncing ball simulation I wrote sometime ago. Not sure 
now if this is the best way to do these thing, but it might be of help

----- bouncing ball --------
x = RandomReal[{-0.9, 0.9}];
y = RandomReal[{-0.9, 0.9}];
r = 0.1;
g = Disk[{x, y}, r];

Dynamic[Refresh[
           Graphics[g,
                    ImageMargins -> 0,
                    Frame -> True,
                    ImagePadding -> 1,
                    PlotRangeClipping->False,
                    PlotRange->1],
           UpdateInterval -> $TimeUnit,
           TrackedSymbols -> {g}
        ],
        SynchronousUpdating -> True
]

simulationTime = 1000;
dx = 0.01; dy = 0.01;

(* run the simulaltion *)
For[k = 1, k <= simulationTime, k++,
       {g = Disk[{x += dx, y += dy}, r];
        FinishDynamic[]; (*to eliminate flicker*)
        If[Abs[x] >= 0.9, dx = -dx];
        If[Abs[y] >= 0.9, dy = -dy];
        Pause[$TimeUnit*2]
       }
]
----------------------------

--Nasser


  • Prev by Date: Re: How to apply a list of functions
  • Next by Date: Re: How to apply a list of functions
  • Previous by thread: Re: Plotting a function dynamically in a loop
  • Next by thread: Export Plot3D as text