MathGroup Archive 2012

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

Search the Archive

Manipulate Animate Bookmarks for Demonstration

  • To: mathgroup at smc.vnet.net
  • Subject: [mg128179] Manipulate Animate Bookmarks for Demonstration
  • From: barandiaran.juan at gmail.com
  • Date: Fri, 21 Sep 2012 04:14:45 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net

Hi,

I'm trying to send a Demonstration of a Electron Collision Model to the Wolfram Demonstrations Project. But one of the requirements is that, if the Manipulate has Bookmarks, the Animate Bookmarks option has to work.
In my notebook, the manipulate and the bookmarks work fine, but when Animate Bookmarks is pressed I get many errors, that seem to come from the "time" variable in my ParametricPlots (if I set these variables to a constant value it works fine, but then the demo is not fun).
The error is : ParametricPlot::plln: "Limiting value Clip[FE`time$$609$45115,{0.1,300}] in {t,0,Clip[FE`time$$609$45115,{0.1,300}]} is not a machine-sized real number."

I tried to use AutorunSequencing -> {1}, InterpolationOrder -> 0 to tell the Autorun and Animate to play only with the first control and not to interpolate between values in the Bookmarks, but with no result. The Autorun moves the two first controls and the Animate Bookmarks causes a lot of errors.
Any suggestions on how to make the Animate Bookmarks work without errors?
Thanks in advance,
JBB
*************************************************************************
Following my code, sorry if it is a bit long although it is just 9 instructions... just copy and paste in a notebook and it works fine:

e = 0.01459; (* Defining the constant "e" as twice the fine structure \
constant=2/137 *)

ecuationList[Ex_, Ey_, Ez_, Bx_, By_, Bz_] := {
  r1x'[t] == u1x[t],                           (*
  Coordinates of the position of the Center of Charge of the first \
particle: r1x, r1y, r1z *)
  u1x'[t] == q1x[t] - r1x[t],        (*
  Speed components of the Center of Charge of the first particle:
  u1x, u1y, u1z *)
  r1y'[t] == u1y[t],
  u1y'[t] == q1y[t] - r1y[t],
  r1z'[t] == u1z[t],
  u1z'[t] == q1z[t] - r1z[t],
 
  q1x'[t] == v1x[t],                           (*
  Coordinates of the position of the Center of Mass: q1x, q1y,
  q1z and Speed components of the Center of Mass: v1x, v1y, v1z *)
  (* Both particles will be affected by the following external \
fields: Electric field with components: Ex, Ey,
  Ez and Magnetic field with components: Bx, By, Bz *)
  v1x'[t] == (e (r1x[t] -
         r2x[t]))/\[Sqrt]((r1x[t] - r2x[t])^2 + (r1y[t] -
          r2y[t])^2 + (r1z[t] - r2z[t])^2)^3 + Ex + u1y[t] Bz -
    u1z[t] By,
  q1y'[t] == v1y[t],
  v1y'[t] == (e (r1y[t] -
         r2y[t]))/\[Sqrt]((r1x[t] - r2x[t])^2 + (r1y[t] -
          r2y[t])^2 + (r1z[t] - r2z[t])^2)^3 + Ey + u1z[t] Bx -
    u1x[t] Bz,
  q1z'[t] == v1z[t],
  v1z'[t] == (e (r1z[t] -
         r2z[t]))/\[Sqrt]((r1x[t] - r2x[t])^2 + (r1y[t] -
          r2y[t])^2 + (r1z[t] - r2z[t])^2)^3 + Ez + u1x [t] By -
    u1y[t] Bx,
 
  r2x'[t] == u2x[t],  (* Now the same with the second particle *)
  u2x'[t] == q2x[t] - r2x[t],
  r2y'[t] == u2y[t],
  u2y'[t] == q2y[t] - r2y[t],
  r2z'[t] == u2z[t],
  u2z'[t] == q2z[t] - r2z[t],
 
  q2x'[t] == v2x[t],
  v2x'[t] == (-e (r1x[t] -
         r2x[t]))/\[Sqrt]((r1x[t] - r2x[t])^2 + (r1y[t] -
          r2y[t])^2 + (r1z[t] - r2z[t])^2)^3 + Ex + u2y[t] Bz -
    u2z[t] By,
  q2y'[t] == v2y[t],
  v2y'[t] == (-e (r1y[t] -
         r2y[t]))/\[Sqrt]((r1x[t] - r2x[t])^2 + (r1y[t] -
          r2y[t])^2 + (r1z[t] - r2z[t])^2)^3 + Ey + u2z[t] Bx -
    u2x [t] Bz,
  q2z'[t] == v2z[t],
  v2z'[t] == (-e (r1z[t] -
         r2z[t]))/\[Sqrt]((r1x[t] - r2x[t])^2 + (r1y[t] -
          r2y[t])^2 + (r1z[t] - r2z[t])^2)^3 + Ez + u2x[t] By -
    u2y[t] Bx
  }

initialConditions[a_, b_, z1_, z2_, Vx_, Vy_, Vz_, theta_, phi_] := {
  r1x[0] == -a + Cos[z1 Degree],
  u1x[0] == -Sin[z1 Degree] + Vx,
  r1y[0] == Sin[z1 Degree],
  u1y[0] == Cos[z1 Degree] + Vy,
  r1z[0] == -b,
  u1z[0] == Vz,
 
  q1x[0] == -a,
  v1x[0] == Vx,
  q1y[0] == 0.0,
  v1y[0] == Vy,
  q1z[0] == -b,
  v1z[0] == Vz,
 
  r2x[0] ==
   a + Cos[phi Degree]*Cos[theta Degree]*Cos[z2 Degree] +
    Sin[phi Degree]*Sin[z2 Degree],
  u2x[0] == -Vx - Cos[phi Degree] Cos[theta Degree]*Sin[z2 Degree] +
    Sin[phi Degree]*Cos[z2 Degree],
  r2y[0] == -Sin[phi Degree]*Cos[theta Degree]*Cos[z2 Degree] +
    Cos[phi Degree]*Sin[z2 Degree],
  u2y[0] == -Vy + Sin[phi Degree]*Cos[theta Degree]*Sin[z2 Degree] +
    Cos[phi Degree]*Cos[z2 Degree],
  r2z[0] == b - Sin[theta Degree]*Cos[z2 Degree],
  u2z[0] == -Vz + Sin[theta Degree]*Sin[z2 Degree],
 
  q2x[0] == a,
  v2x[0] == -Vx,
  q2y[0] == 0.0,
  v2y[0] == -Vy,
  q2z[0] == b,
  v2z[0] == -Vz
  }

diffEqSolution[a_, b_, z1_, z2_, Vx_, Vy_, Vz_, theta_, phi_, Ex_,
   Ey_, Ez_, Bx_, By_, Bz_, tMax_] :=
  NDSolve[
   {ecuationList[Ex, Ey, Ez, Bx, By, Bz],
    initialConditions[a, b, z1, z2, Vx, Vy, Vz, theta, phi]},
   {r1x, r1y, r1z, u1x, u1y, u1z, q1x, q1y, q1z, v1x, v1y, v1z,
    r2x, r2y, r2z, u2x, u2y, u2z, q2x, q2y, q2z, v2x, v2y, v2z},
   {t, 0, tMax}];

plot2DCC1[cc1_, time_, regla_] :=
  ParametricPlot[
   Evaluate[If[cc1, {r1x[t], r1y[t]}, {0, 0}] /. regla], {t, 0, time},
    PlotStyle -> Orange];

plot2DCC2[cc2_, time_, regla_] :=
  ParametricPlot[
   Evaluate[If[cc2, {r2x[t], r2y[t]}, {0, 0}] /. regla], {t, 0, time},
    PlotStyle -> Cyan];

plot2DCM1[cm1_, time_, regla_] :=
  ParametricPlot[
   Evaluate[If[cm1, {q1x[t], q1y[t]}, {0, 0}] /. regla], {t, 0, time},
    PlotStyle -> {Red, Dashed}];

plot2DCM2[cm2_, time_, regla_] :=
 ParametricPlot[
  Evaluate[If[cm2, {q2x[t], q2y[t]}, {0, 0}] /. regla], {t, 0, time},
  PlotStyle -> {Blue, Dotted}];

Manipulate[
 Module[{regla},
  regla =
   diffEqSolution[a, 0, z1, z2, Vx, Vy, Vz, theta, phi, Ex, Ey, Ez,
    Bx, By, Bz, 300];
  Show[
   plot2DCC1[True, time, regla],
   plot2DCC2[True, time, regla],
   plot2DCM1[True, time, regla],
   plot2DCM2[True, time, regla],
   AxesLabel -> {"X", "Y"}, PlotRange -> XMax,
   AspectRatio -> Automatic,
   PlotLabel ->
    "2D spinning particles interaction\n Electron Collision Model\n",
   ImageSize -> 300]],
 {{time, 100, "current time"}, 0.1, 300, ImageSize -> Tiny},
 {{XMax, 8, "zoom"}, 1, 50, ImageSize -> Tiny},
 {{a, 5.0, "X separation"}, 0, 10, ImageSize -> Tiny},
 "particle 1 initial phase",
 {{z1, 160.0, ""}, 0, 360, ImageSize -> Tiny},
 "particle 2 initial phase",
 {{z2, 0.0, ""}, 0, 360, ImageSize -> Tiny},
 {{Vx, 0.1, "speed:             Vx"}, 0, 1, ImageSize -> Tiny},
 {{Vy, 0.02, "   Vy"}, 0, 1, ImageSize -> Tiny},
 {{Vz, 0.0, "  Vz"}, 0, 1, ImageSize -> Tiny},
 "spin orientation of particle 2:",
 {{theta, 0.0}, 0, 360, ImageSize -> Tiny},
 {{phi, 0.0}, 0, 360, ImageSize -> Tiny},
 Delimiter,
 {{Ex, 0.0, "electric field:     Ex"}, 0, 10, ImageSize -> Tiny},
 {{Ey, 0.0, "  Ey"}, 0, 10, ImageSize -> Tiny},
 {{Ez, 0.0, "  Ez"}, 0, 10, ImageSize -> Tiny},
 {{Bx, 0.0, "magnetic field:  Bx"}, 0, 10, ImageSize -> Tiny},
 {{By, 0.0, "  By"}, 0, 10, ImageSize -> Tiny},
 {{Bz, 0.0, "  Bz"}, 0, 10, ImageSize -> Tiny},
 SaveDefinitions -> True,
 ControlPlacement -> Right,
 SynchronousUpdating -> False,
 AutorunSequencing -> {1, 2},
 Bookmarks -> {
   "Electron Scattering" :> {
     a = 5.0, z1 = 160.0, z2 = 0.0,
     Vx = 0.1, Vy = 0.02, Vz = 0.0,
     theta = 0.0, phi = 0.0,
     Ex = 0.0, Ey = 0.0, Ez = 0.0,
     Bx = 0.0, By = 0.0, Bz = 0.0, XMax = 8},
   "Sharp Angle Scattering" :> {
     a = 5.0, z1 = 55.0, z2 = 0.0,
     Vx = 0.2, Vy = 0.002, Vz = 0.0,
     theta = 0.0, phi = 0.0,
     Ex = 0.0, Ey = 0.0, Ez = 0.0,
     Bx = 0.0, By = 0.0, Bz = 0.0, XMax = 8},
   "Forward Scattering" :> {
     a = 5.0, z1 = 160.0, z2 = 0.0,
     Vx = 0.3, Vy = 0.002, Vz = 0.0,
     theta = 0.0, phi = 0.0,
     Ex = 0.0, Ey = 0.0, Ez = 0.0,
     Bx = 0.0, By = 0.0, Bz = 0.0, XMax = 8},
   "Paired Electrons" :> {
     a = 0.0, z1 = 160.0, z2 = 0.0,
     Vx = 0.0, Vy = 0.001, Vz = 0.0,
     theta = 0.0, phi = 0.0,
     Ex = 0.0, Ey = 0.0, Ez = 0.0,
     Bx = 0.0, By = 0.0, Bz = 0.0, XMax = 1.1},
   "Paired Electrons in Electric Field" :> {
     a = 0.0, z1 = 160.0, z2 = 0.0,
     Vx = 0.0, Vy = 0.001, Vz = 0.0,
     theta = 0.0, phi = 0.0,
     Ex = 0.00001, Ey = 0.0, Ez = 0.0,
     Bx = 0.0, By = 0.0, Bz = 0.0, XMax = 1.4},
   "Paired Electrons in Magnetic Field" :> {
     a = 0.0, z1 = 160.0, z2 = 0.0,
     Vx = 0.0, Vy = 0.001, Vz = 0.0,
     theta = 0.0, phi = 0.0,
     Ex = 0.0, Ey = 0.0, Ez = 0.0,
     Bx = 0.00001, By = 0.0, Bz = 0.0, XMax = 1.5}
   },
 AutorunSequencing -> {1}, InterpolationOrder -> 0,
 TrackedSymbols :> {a, z1, z2, Vx, Vy, Vz, theta, phi, Ex, Ey, Ez, Bx,
    By, Bz, XMax, time}]











  • Prev by Date: List & Plot: do they parse options differently?
  • Next by Date: Re: creating a graphic in a text cell
  • Previous by thread: Re: List & Plot: do they parse options differently?
  • Next by thread: Percentage of Primes