4
$\begingroup$

I´m new to using units in Mathematica. I have read other similar posts about this issue but I haven´t found an answer so far. My problem is simple: I want to plot a certain function with a certain unit. In my case, I want a graphic in Angle - mm.

I have this function depending on a.

f[a_]:=(1 - Cos[0.017 a])*(Quantity[45.2,"Millimeters"]) + 
(Quantity[145.`, "Millimeters"])*(1-Sqrt[1 - 0.097 Sin[0.017 a]^2])

When I plot it using

Plot[Evaluate[f[a]], {a, 0, 720}]

I get a results which is 1/1000 times the correct one (which should be in mm), so I assume that it is being shown in m. But in general, there is no way to know in which unit the graphic is being shown.

Or is there a way to do this? Thank you for the help.

$\endgroup$
0

1 Answer 1

2
$\begingroup$

With one change on the function: move the (1-COS[]), (1-Sin[]) parts inside the respective Quantity, this is how I handle Units:

f = Function[\[Theta], 
  Evaluate[QuantityMagnitude[
    UnitConvert[(Quantity[(1 - Cos[(\[Pi] \[Theta])/180]) 45.2, 
        "Millimeters"]) + (Quantity[(1 - 
           Sqrt[1 - 0.0971719 Sin[(\[Pi] \[Theta])/180]^2]) 145, 
        "Millimeters"]), "Millimeters"]]]]

Essentially -- convert everything using UnitConvert into the units you want, and then take a magnitude. Not the prettiest, but it works.

Note that the described change is necessary for the Function definition to properly evaluate.

$\endgroup$
1
  • $\begingroup$ Thank you @tkott , you have given me the idea to steer myself in the right direction. To sum up for anyone who might use this: First I get the desired unit using UnitConvert. Then, with QuantityMagnitude I can get a unitless function with the correct values that I can plot. $\endgroup$
    – MBenedetto
    Commented Feb 11, 2014 at 17:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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