Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
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. –  MBenedetto Feb 11 at 17:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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