-4
$\begingroup$

I am trying to create a button which will give random values for certain parameters. I am using the following in Manipulate[].

Delimiter, Button["Arbitary Parameters", time = 0;
 r = RandomReal[{0.04, 0.3}];
 c = RandomReal[{0, 0.15}];
 μ = RandomReal[{0, 0.25}]],
{{tMax, 30}, ControlType -> None},
TrackedSymbols :> True, ControlPlacement -> Left,

However, I get the following errors:

"Manipulate argument TrackedSymbols:>True does not have the correct \ form for a variable specification." "Manipulate argument ControlPlacement->Left does not have the correct \ form for a variable specification. "

How do I resolve this so that I can create a button which when used will randomly change the values of the parameters?

Code including manipulate wrapper:

Manipulate[If[time > tMax, time = tMax];
 Quiet @ 
   Module[{g = 9.8, R = 1, m, center, axis1, axis2, eqn, sol},
   m = 2.52*(4/3)*π*r^3;
   eqn = {ϕ''[t] == (
       5*(r - R)*Sin[2*θ[t]]*θ'[t]*ϕ'[t])/(
       2*r^2 - 5*r*Sin[θ[t]]^2 + 5*R*Sin[θ[t]]^2) - 
       c*ϕ'[t]*(R - r)*
        Sqrt[θ'[t]^2 + 
          Sin[θ[t]]^2*ϕ'[t]^2] - μ*7/5*r/
        g*ϕ'[t]*(R - r)*
        Sqrt[θ'[t]^2 + Sin[θ[t]]^2*ϕ'[t]^2],
     θ''[t] == -g*Sin[θ[t]] + 
       Cos[θ[t]]*Sin[θ[t]]*ϕ'[t]^2 - 
       c*θ'[t]*(R - r)*
        Sqrt[θ'[t]^2 + 
          Sin[θ[t]]^2*ϕ'[t]^2] - μ*7/5*r/
        g*θ'[t]*(R - r)*
        Sqrt[θ'[t]^2 + Sin[θ[t]]^2*ϕ'[t]^2],
     r ψ[t] == -(R - r)*θ[t], 
     r α[t] == -(R - r)*ϕ[t],
     θ[0] == θ0, θ'[0] == θd0, ϕ[
       0] == ϕ0, ϕ'[0] == ϕd0};
   sol = First[
     NDSolve[eqn, {ϕ, θ, ψ, α}, {t, 0, time}]];
   center[t_, 
     r_] = (R - r)*{Sin[θ[t]]*Cos[ϕ[t]], 
       Sin[θ[t]]*Sin[ϕ[t]], -Cos[θ[t]]} /. sol;
   axis1[t_] = {Sin[ϕ[time]], -Cos[ϕ[time]], 0} /. sol;
   axis2[t_] = {Cos[θ[time]]*Cos[ϕ[time]], 
      Cos[θ[time]]*Sin[ϕ[time]], Sin[θ[time]]} /. 
     sol;
   Graphics3D[{bowl,
     If[tr, 
      ParametricPlot3D[center[t, 0], {t, 0, time}, PlotPoints -> 50, 
        PlotStyle -> Directive[{Thick, Blue}]][[1]], {}],
     {Specularity[1, 25],
      Rotate[
       Rotate[marble[center[time, r], r],
        (α[time]) /. sol, axis2[time], center[time, r]],
       ψ[time] /. sol, axis1[time], center[time, r]]}},
    Boxed -> False, Lighting -> "Neutral", 
    PlotRange -> {All, All, {-R, 2}}, ViewAngle -> 40 °, 
    ViewPoint -> {1, 0, 2.7}, ImageSize -> {400, 400}]],
 Style["Animation", Bold], {{time, 0.001, ""}, 0.001, tMax, .15, 
  Trigger, AnimationRate -> 1, 
  AppearanceElements -> {"PlayButton", "PauseButton", 
    "StepLeftButton", "StepRightButton", "ResetButton"}, 
  ImageSize -> Large}, Delimiter,
 Style["Parameters", Bold],
 "\nRadius of the Marble", {{r, .1, "r"}, 0.04, 0.3, .01, 
  ImageSize -> Tiny, Appearance -> "Labeled"},
 "Drag on the Marble", {{c, .09, "c"}, 0, .15, .01, ImageSize -> Tiny,
   Appearance -> 
   "Labeled"}, "Friction between the ball and the surface", {{μ, \
.07, "μ"}, 0, .25, .01, ImageSize -> Tiny, 
  Appearance -> "Labeled"}, Delimiter,
 Style["Initial Conditions", Bold],
 "\nAngular Position", "  \!\(\*SubscriptBox[\(θ\), \(0\)]\)=\
π/2", {{ϕ0, -2.7, 
   "\!\(\*SubscriptBox[\(ϕ\), \(0\)]\)"}, -3.14, 3.14, .01, 
  ImageSize -> Tiny, Appearance -> "Labeled"},
 "\nAngular Speed", "  θ\!\(\*SubscriptBox[\('\), \(0\)]\)=0", \
{{ϕd0, .90, "ϕ\!\(\*SubscriptBox[\('\), \(0\)]\)"}, -2, 
  2, .01, ImageSize -> Tiny, Appearance -> "Labeled"}, Delimiter,
 {{θ0, π/2}, ControlType -> None}, {{θd0, 0}, 
  ControlType -> None},


 Delimiter, Evaluate[Button["Arbitary Parameters", time = 0;
   r = RandomReal[{0.04, 0.3}];
   c = RandomReal[{0, 0.15}];
   μ = RandomReal[{0, 0.25}]]],
 {{tMax, 30}, ControlType -> None},
 TrackedSymbols :> True, ControlPlacement -> Left,

 Row[{"Path Followed", Control[{{tr, True, ""}, {True, False}}]}],
 {{tMax, 30}, ControlType -> None},
 TrackedSymbols -> Manipulate, ControlPlacement -> Left,

 (*Delimiter,Button["Arbitary Parameters",time=0;
 r=RandomInteger[{0.04,0.3}];
 c=RandomInteger[{0,0.15}];
 μ=RandomInteger[{0,0.25}]],
 {{tMax,30},ControlType\[Rule]None},
 TrackedSymbols\[RuleDelayed]True, ControlPlacement\[Rule]Left,*)


 Initialization :> (bowl = 
    RegionPlot3D[
      1 < x^2 + y^2 + z^2 < 1.25, {x, -1.25, 1.25}, {y, -1.25, 
       1.25}, {z, -1.25, 0}, PlotPoints -> 32, 
      BoundaryStyle -> Directive[Black, Thick], Boxed -> False, 
      Axes -> False, Mesh -> None, BoxRatios -> {1, 1, .5}, 
      TextureCoordinateFunction -> ({#1, #2, #3} &)][[1]];
   marble[{x_, y_, z_}, 
     r_] := {{Black, Sphere[{x, y, z}, r]}, {Black, 
      Sphere[{x, y, z + 0.025}, .999 r]}})]
$\endgroup$

closed as off-topic by m_goldberg, Simon Woods, dr.blochwave, Yves Klett, user9660 Nov 29 '15 at 21:04

  • The question does not concern the technical computing software Mathematica by Wolfram Research. Please see the help center to find out about the topics that can be asked here.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ "Error in Manipulate" is a vast understatement. There are so many errors that I am unable to quantify them. My first piece of advice is that you should read the documentation concerning TrackedSymbols. Your use of it is both syntactically and semantically wrong. $\endgroup$ – m_goldberg Nov 29 '15 at 18:05
  • $\begingroup$ I think your differential equations are not correct. Try to solve them separately, outside the Manipulate first. Since you have four variables, I think you should have four equations and eight initial conditions. Once you successfully solve the DE outside, write a module which takes in time and initial conditions and returns the output of the NDSolve. Modularising the code helps is debugging. $\endgroup$ – Saurav Nov 29 '15 at 18:08
  • $\begingroup$ @Saurav: It is only the Button named as 'Arbitary Parameters' that is giving the error. Rest all seem to work fine and I am not quite sure how to resolve this particular error. $\endgroup$ – Varun Kulkarni Nov 29 '15 at 18:10
  • 1
    $\begingroup$ Options must appear after all the controls specifications are given. Move ControlPlacement to the end of the Manipulate expression. $\endgroup$ – m_goldberg Nov 29 '15 at 18:23
  • 4
    $\begingroup$ I'm voting to close this question as off-topic because it is too localized; i.e, it applies only to the local situation and needs of its poster and answers will not benefit others. $\endgroup$ – m_goldberg Nov 29 '15 at 19:11
5
$\begingroup$

This is not an answer. It is a long, long way from being an answer. It is a comment that needs to show a lot of code and an image.

Here is your code after some clean up. It doesn't work, but at least it makes an initial display close to what you likely want. I hope it will help you to work further on your problem.

Manipulate[
  If[time > tMax, time = tMax];
  Module[{g = 9.8, R = 1, m, center, axis1, axis2, eqn, sol}, 
   m = 2.52*(4/3)*π*r^3;
   eqn = 
     {ϕ''[t] == (5*(r - R)*Sin[2*θ[t]]*θ'[t]*ϕ'[t])/(2*r^2 - 
        5*r*Sin[θ[t]]^2 + 5*R*Sin[θ[t]]^2) - c*ϕ'[t]*(R - r)*Sqrt[θ'[t]^2 + 
        Sin[θ[t]]^2*ϕ'[t]^2] - μ*7/5*r/g*ϕ'[t]*(R - r)*Sqrt[θ'[t]^2 + 
        Sin[θ[t]]^2*ϕ'[t]^2], 
      θ''[t] == -g*Sin[θ[t]] + Cos[θ[t]]*Sin[θ[t]]*ϕ'[t]^2 - 
        c*θ'[t]*(R - r)*Sqrt[θ'[t]^2 + Sin[θ[t]]^2*ϕ'[t]^2] - 
        μ*7/5*r/g*θ'[t]*(R - r)*Sqrt[θ'[t]^2 + Sin[θ[t]]^2*ϕ'[t]^2], 
      r ψ[t] == -(R - r)*θ[t], 
      r α[t] == -(R - r)*ϕ[t], 
      θ[0] == θ0, θ'[0] == θd0, ϕ[0] == ϕ0, ϕ'[0] == ϕd0};
   sol = 
     First[NDSolve[eqn, {ϕ, θ, ψ, α}, {t, 0, time}]];
   center[t_, r_] = 
     (R - r)*{Sin[θ[t]]*Cos[ϕ[t]], Sin[θ[t]]*Sin[ϕ[t]], -Cos[θ[t]]} /. sol;
   axis1[t_] = {Sin[ϕ[time]], -Cos[ϕ[time]], 0} /. sol;
   axis2[t_] = 
     {Cos[θ[time]]*Cos[ϕ[time]], Cos[θ[time]]*Sin[ϕ[time]], Sin[θ[time]]} /. sol;
   Graphics3D[{
     bowl, 
     If[tr, 
       ParametricPlot3D[center[t, 0], {t, 0, time}, 
         PlotPoints -> 50, 
         PlotStyle -> Directive[{Thick, Blue}]][[1]], {}], 
     {Specularity[1, 25], 
      Rotate[
        Rotate[marble[center[time, r], r], (α[time]) /. sol, 
          axis2[time], center[time, r]], 
        ψ[time] /. sol, 
      axis1[time], center[time, r]]}}, 
      Boxed -> False, 
      Lighting -> "Neutral", 
      PlotRange -> {All, All, {-R, 2}}, 
      ViewAngle -> 40 °, 
      ViewPoint -> {1, 0, 2.7}, 
      ImageSize -> {400, 400}]], 
  Style["Animation", Bold],
  {{time, 0.001, ""}, 0.001, tMax, .15, Trigger, 
    AnimationRate -> 1, 
    AppearanceElements -> 
      {"PlayButton", "PauseButton", "StepLeftButton", 
       "StepRightButton", "ResetButton"}, 
    ImageSize -> Large}, 
  Delimiter, 
  Style["Parameters", Bold],
  "\nRadius of the Marble",
  {{r, .1, "r"}, 0.04, 0.3, .01, ImageSize -> Tiny, Appearance -> "Labeled"}, 
  "Drag on the Marble",
  {{c, .09, "c"}, 0, .15, .01, ImageSize -> Tiny, Appearance -> "Labeled"}, 
  "Friction between the ball and the surface", 
  {{μ, .07, "μ"}, 0, .25, .01, ImageSize -> Tiny, Appearance -> "Labeled"},
  Delimiter,
  Style["Initial Conditions", Bold],
  "\nAngular Position",
  "  \!\(\*SubscriptBox[\(θ\), \(0\)]\)=    π/2",
  {{ϕ0, -2.7, "\!\(\*SubscriptBox[\(ϕ\), \(0\)]\)"}, -3.14, 3.14, .01, 
    ImageSize -> Tiny, Appearance -> "Labeled"},
  "\nAngular Speed",
  "  θ\!\(\*SubscriptBox[\('\), \(0\)]\)=0", 
  {{ϕd0, .90, "ϕ\!\(\*SubscriptBox[\('\), \(0\)]\)"}, -2, 2, .01, 
    ImageSize -> Tiny, Appearance -> "Labeled"},
  Delimiter,
  {{θ0, π/2}, ControlType -> None},
  {{θd0, 0}, ControlType -> None}, Delimiter, 
  Button["Arbitary Parameters",
    time = 0;
    r = RandomInteger[{0.04, 0.3}];
    c = RandomInteger[{0, 0.15}];
    μ = RandomInteger[{0, 0.25}]],
  {{tMax, 30}, ControlType -> None},
  Row[{"Path Followed", Control[{{tr, True, ""}, {True, False}}]}], 
  {{tMax, 30}, ControlType -> None},
  ControlPlacement -> Left,
  Initialization :> (
    bowl = 
     RegionPlot3D[
       1 < x^2 + y^2 + z^2 < 1.25, {x, -1.25, 1.25}, {y, -1.25, 
       1.25}, {z, -1.25, 0}, PlotPoints -> 32, 
       BoundaryStyle -> Directive[Black, Thick], 
       Boxed -> False, Axes -> False, Mesh -> None, 
       BoxRatios -> {1, 1, .5}, 
       TextureCoordinateFunction -> ({#1, #2, #3} &)][[1]];
   marble[{x_, y_, z_}, r_] := 
     {{Black, Sphere[{x, y, z}, r]}, {Black, Sphere[{x, y, z + 0.025}, .999 r]}})]

demo

Note this code gives the error message

NDSolve::depdole: The differential order of a dependent variable in {(α^′)[t],(θ^′)[t],(θ^′′)[t],(ϕ^′)[t],(ϕ^′′)[t],(ψ^′)[t]} exceeds the highest order that appears in the differential equations. >>

so you clearly have some work to do.

$\endgroup$
  • $\begingroup$ Exactly my comment in the beginning! I believe the differential equations are not formulated properly! {I think your differential equations are not correct. Try to solve them separately, outside the Manipulate first. Since you have four variables, I think you should have four equations and eight initial conditions. Once you successfully solve the DE outside, write a module which takes in time and initial conditions and returns the output of the NDSolve. Modularising the code helps is debugging. } But if the OP has solved, it's solved. $\endgroup$ – Saurav Nov 29 '15 at 18:58
  • $\begingroup$ I am not getting this error when I run it from my side. Will look into it as well. Is it, possible to rotate the bowl around any particular axis at the same time as the sphere is rolling inside it? $\endgroup$ – Varun Kulkarni Nov 29 '15 at 19:03
  • $\begingroup$ @Saurav. I totally agree with you. $\endgroup$ – m_goldberg Nov 29 '15 at 19:03
  • 1
    $\begingroup$ @VarunKulkarni. Do you still have Quiet in your code. If so, you are living a dream if you think you don't have errors. Using Quiet is just a way of denying reality. $\endgroup$ – m_goldberg Nov 29 '15 at 19:09
  • $\begingroup$ @m_goldberg Is it impolite and detrimental to just abandon once the question is solved? Or is it normal and accepted? Should check in meta though. $\endgroup$ – Saurav Nov 29 '15 at 19:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.