0

I am trying to do a plot of a function with Quantities (with Units) in Mathematica.

insertvalues := {Lr -> Quantity[57* 10 ^-6, "Henry"], Cr -> Quantity[100* 10^-9, "Farad"], U1 -> Quantity[540, "V"]}
uc0[t_] = U1 (1 - Cos[1/Sqrt[Lr *Cr]*t])
Plot[uc0[t] /. insertvalues , {t, Quantity[0, "sec"], Quantity[2.5, "\[Mu]s"]}]

However the resulting plot stays empty:

Empty Plot

I have no idea what went wrong or how to debug that. Any ideas how to solve that are appreciated. Wolfram Mathematica version 10.0.1 is used. Thanks!

  • At least under V9, if I change insertvalues := to insertvalues = and I change uc0[t_] = to uc0[t_] := then it plots just fine. You can try all four possible choices of = and := and see which ones work for you. – Bill Jan 09 '15 at 18:48
  • Thanks. I can confirm that this also works in V10. Do you know why changing from = to := makes a difference here? – martinzellner Jan 09 '15 at 19:06
  • you can also fix with `Evaluate` inside plot `Evaluate[ uc0[t] /. insertvalues]`. – agentp Jan 09 '15 at 19:15
  • EVERYTHING about the way Mathematica behaves depends on the process it uses to evaluate (which really means pattern match and replace) expressions. Sometimes this makes it look like it is an ordinary programming language, but under the surface it is doing things very differently from what you expect. := saves the right hand side and only does the assignment later when the left hand side is used and uses the then current values. But your first line only has constants so you would think it didn't matter. = assigns immediately using current values. Plot is even different. Too long to answer this. – Bill Jan 09 '15 at 20:28

0 Answers0