Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #4250

Some questions about a Mathematica script

From "DaleJenk" <dale.jenkins8@deletegooglemail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Some questions about a Mathematica script
Date 2011-08-09 11:30 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <j1r5oj$fl0$1@smc.vnet.net> (permalink)

Show all headers | View raw


I downloaded the following from the Mathematica website. Most of it is 
fairly easy to understand but there's a section in the middle which isn't 
(at least to me).

1. At the end of the NDSolve instruction comes the list: {x1[t], x2[t], 
x3[t], x1'[t], x2'[t], x3'[t]}. What exactly is the reason for putting in 
the primed items in this list?

2. "soln" and "solnx1", etc. are all just labels. Right?

3. But what exactly does soln[[1,1]] refer to?

Thanks for any help.

Dale



Manipulate[
 m = 1.0;
 len = 4.0;
 dx1 = (1/m1)*(((tension*(x2[t] - x1[t]))/len) - tension (x1[t]/len));
 dx2 = (1/
    m2)*(((-tension*(x2[t] - x1[t]))/len) -
     tension ((x2[t] - x3[t])/len));
 dx3 = (1/m3)*(((tension*(x2[t] - x3[t]))/len) - tension (x3[t]/len));
 soln = NDSolve[{{x1''[t] == dx1, x2''[t] == dx2,
     x3''[t] == dx3}, {x1[0] == x1int, x1'[0] == 0.0, x2[0] == x2int,
     x2'[0] == 0.0, x3[0] == x3int, x3'[0] == 0.0}}, {x1[t], x2[t],
    x3[t], x1'[t], x2'[t], x3'[t]}, {t, 0, 5},
   Method -> "StiffnessSwitching"];
 solnx1[t_] = x1[t] /. soln[[1, 1]];
 solnx2[t_] = x2[t] /. soln[[1, 2]];
 solnx3[t_] = x3[t] /. soln[[1, 3]];
 solnx1p[t_] = x1'[t] /. soln[[1, 4]];
 solnx2p[t_] = x2'[t] /. soln[[1, 5]];
 solnx3p[t_] = x3'[t] /. soln[[1, 6]];
 With[{xa = solnx1[run], xb = solnx2[run], xc = solnx3[run]},
  balls =
   Graphics[{Black, Line[{{0, 0}, {1, xa}, {2, xb}, {3, xc}, {4, 0}}],
      Red, {Disk[{1, xa}, .1 Sqrt[m1]], Disk[{2, xb}, .1 Sqrt[m2]],
      Disk[{3, xc}, .1 Sqrt[m3]]}}, PlotRange -> {{0, 4}, {-1, 1}},
    Frame -> True, ImageSize -> {400, 250}];
  disp = Plot[{solnx1[t], solnx2[t], solnx3[t]}, {t, 0, 5},
    ImageSize -> {200, 150},
    AxesLabel -> {Row[{"time ", Style["t", Italic]}], "displacement"},
     ImagePadding -> {{35, 35}, {10, 20}}];
  velocity =
   Plot[{solnx1p[t], solnx2p[t], solnx3p[t]}, {t, 0, 5},
    ImageSize -> {200, 150},
    AxesLabel -> {Row[{"time ", Style["t", Italic]}], "velocity"},
    ImagePadding -> {{35, 35}, {10, 20}}];
  Grid[{{balls, SpanFromLeft}, {disp, velocity}}]],
 {{tension, 10, "tension T"}, 5, 20, .1, ImageSize -> Tiny},
 Style["displacement", Bold],
 {{x1int, 0, "\!\(\*SubscriptBox[\"x\", \"1\"]\)"}, -.2, .2,
  ImageSize -> Tiny},
 {{x2int, .1, "\!\(\*SubscriptBox[\"x\", \"2\"]\)"}, -.2, .2,
  ImageSize -> Tiny},
 {{x3int, 0, "\!\(\*SubscriptBox[\"x\", \"3\"]\)"}, -.2, .2,
  ImageSize -> Tiny},
 Style["mass", Bold],
 {{m1, 1, "\!\(\*SubscriptBox[\"m\", \"1\"]\)"}, .1, 3, .1,
  ImageSize -> Tiny},
 {{m2, 1, "\!\(\*SubscriptBox[\"m\", \"2\"]\)"}, .1, 3, .1,
  ImageSize -> Tiny},
 {{m3, 1, "\!\(\*SubscriptBox[\"m\", \"3\"]\)"}, .1, 3, .1,
  ImageSize -> Tiny},
 {{run, 0, "release system"}, 0, 5, .1, ControlType -> Trigger,
  AnimationRate -> 1},
 SynchronousUpdating -> True, TrackedSymbols -> True,
 AutorunSequencing -> {1, 3, 5, 8}] 

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Some questions about a Mathematica script "DaleJenk" <dale.jenkins8@deletegooglemail.com> - 2011-08-09 11:30 +0000

csiph-web