I'm working on a set of relatively basic ODEs of a physical pendulum and motor:

$$\left\{\text{jb} \theta ''(t\text{s})+\text{rb} \theta '(t\text{s})+\alpha \sin (\theta (t\text{s}))+\mu \tan ^{-1}\left(\frac{\theta '(t\text{s})}{\iota }\right)=\text{jw} \phi ''(t\text{s}),\tau u(t\text{s})=\text{jw} \left(\theta ''(t\text{s})+\phi ''(t\text{s})\right)+\text{rw} \phi '(t\text{s})\right\}$$

In an attempt to understand the system some more, I've updated the code to use real world values via Quantity[]:

displacement = Quantity[5 \[Pi]/180, "Radians"];
params = {\[Mu] -> 0.000795, rw -> 0.000039255383907286545`, 
   rb -> 0.00016799999999999996`, \[Iota] -> 0.1, 
   g -> Quantity[9.81, ("Meters")/("Seconds")^2], 
   mb -> Quantity[88, "Grams"], mw -> Quantity[129.31, "Grams"], 
   x -> Quantity[60.519, "Millimeters"], 
   y -> Quantity[61.816, "Millimeters"], 
   l -> Quantity[86.50, "Millimeters"], 
   k -> Quantity[90, "Millimeters"], 
   jw -> Quantity[0.0004032497194086029`, "Kilograms" ("Meters")^2], 
   jb -> Quantity[0.001412, "Kilograms" ("Meters")^2], \[Tau] -> 
    Quantity[33.5, ("Millinewtons" "Meters")/("Amperes")]};

eqn1 = g (l mb + k mw) Sin[\[Theta][Quantity[t, "Seconds"]]] + 
   jb (\[Theta]^\[Prime]\[Prime])[Quantity[t, "Seconds"]];
eqn2 = jw (\[Phi]^\[Prime]\[Prime])[Quantity[t, "Seconds"]];
deqns = {eqn1 == 
    jw \[Phi]''[Quantity[t, "Seconds"]] - 
     rb \[Theta]'[
       Quantity[t, "Seconds"]] - \[Mu] ArcTan[\[Theta]'[
        Quantity[t, "Seconds"]]/\[Iota]] + fx + fy , 
   eqn2 == \[Tau] u[Quantity[t, "Seconds"]] - 
     jw \[Theta]''[Quantity[t, "Seconds"]] - 
     rw \[Phi]'[Quantity[t, "Seconds"]]} ;
ics = {\[Theta][Quantity[0, "Seconds"]] == 
    displacement, \[Theta]'[Quantity[0, "Seconds"]] == 
    Quantity[0, "Radians"] , \[Phi][Quantity[0, "Seconds"]] == 
    0, \[Phi]'[Quantity[0, "Seconds"]] == 0};

And from here try to to use NDSolve[]

sol = NDSolve[{{deqns /. params, ics} /. {u[t] -> 0, 
      f[t] -> 0}}, {\[Theta][Quantity[t, "Seconds"]], \[Phi][
     Quantity[t, "Seconds"]]}, {t, 0, 60}];
(*pen ={k Sin[\[Theta][t]],-k Cos[\[Theta][t]]} /. sol;*)

However, I get the following error:

NDSolve::litarg: To avoid possible ambiguity, the arguments of the dependent variable in [Theta][ts] should literally match the independent variables.

Is this error because NDSolve can't work with Quantity[], or how can I give units with NDSolve?

The resulting unit should be in Radians.

Thank you for the help!

  • $\begingroup$ Are you trying to force Mathematica to do a calculation with units? $\endgroup$ – Alex Trounev Apr 12 at 17:52
  • $\begingroup$ Im trying to get an interpolated function to plot the swing of a physical pendulum, with physical units yes. $\endgroup$ – morbo Apr 12 at 17:55
  • $\begingroup$ Can you give a similar example in tutorials ? $\endgroup$ – Alex Trounev Apr 12 at 17:58
  • $\begingroup$ Ah, no i can not find an example to that in the docs or randomly googling...Can you? Id appreciate the help. i know plotting with units is possible, as here. mathematica.stackexchange.com/a/145460/48686 however i assume just because something isnt documented, that doesnt mean its not possible, nor does it explain the error message i have. $\endgroup$ – morbo Apr 12 at 18:06
  • $\begingroup$ There is an example with integration equation = FormulaData[ "StefanBoltzmannLaw", {"\[Epsilon]" -> 1, "T" -> Quantity[t, "Kelvins"]}], and Integrate[equation[[2]], {t, 0, 1000}] $\endgroup$ – Alex Trounev Apr 12 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.