# Using Quantity[] units causes errors in my calculation

I have an interpolation function in which I wish to use actual units. If I perform the calculation normally, it works fine and returns a proper FittedModel.

To illustrate my problem, consider the following:

(CALCULATION WITHOUT UNITS)

xB = {0.00, 0.076, 0.164, 0.300, 0.479, 0.638, 0.854, 0.941, 1.00};
pP = {44.0, 42.2, 39.5, 36.4, 30.4, 27.6, 22.4, 12.9, 0.00};
pT = {44.0, 66.4, 84.0, 99.8, 105.8, 108.4, 109.0, 104.5, 94.4};
torrToPascal = 133.3223;
pPPascal = pP*torrToPascal;
pTPascal = pT*torrToPascal;
pBz = pTPascal - pPPascal;
nlmpBz = Transpose[{xB, pBz}];
nlmpPp = Transpose[{xB, pPPascal}];
linfit = NonlinearModelFit[nlmpBz, (x2)*pBz[[-1]]*Exp[a (1 - x2) + b (1 - x2)^2 + c (1 - x2)^3], {a, b, c}, x2]


This returns: FittedModel[12585.6 E^(0.312901 (1-x2)+1.5389 (1-x2)^2-0.485642 (1-x2)^3) x2

Now when I try to use Quantity[], the following happens:

(CALCULATION WITH UNITS) (xB = fraction and thus dimensionless)

xB = {0.00, 0.076, 0.164, 0.300, 0.479, 0.638, 0.854, 0.941, 1.00};
pP = Quantity[{44.0, 42.2, 39.5, 36.4, 30.4, 27.6, 22.4, 12.9, 0.00},
"Torr"];
pT = Quantity[{44.0, 66.4, 84.0, 99.8, 105.8, 108.4, 109.0, 104.5,
94.4}, "Torr"];
pPPascal = UnitConvert[pP, "Pascal"];
pTPascal = UnitConvert[pT, "Pascal"];
pBz = pTPascal - pPPascal;
nlmpBz = Transpose[{xB, pBz}];
nlmpPp = Transpose[{xB, pPPascal}];
linfit = NonlinearModelFit[nlmpBz, (x2)*pBz[[-1]]*Exp[a (1 - x2) + b (1 - x2)^2 + c (1 - x2)^3], {a, b, c}, x2]


Now to me this seems like the exact same calculation, only with the proper units. Mathematica disagrees and yields the following result:

NonlinearModelFit::nrnq: The function value 0.5 ((0. Pa+2.71828^(3. Automatic) (0. Pa))^2+0. ((Pa)^2)+(-3226.4 Pa+2.71828^(2.56667 Automatic) (956.508 Pa))^2+(-5932.85 Pa+2.71828^(2.11917 Automatic) (2064.04 Pa))^2+(-8452.64 Pa+2.71828^(1.533 Automatic) (3775.69 Pa))^2+(-10052.5 Pa+2.71828^(0.933862 Automatic) (6028.52 Pa))^2+(-10772.4 Pa+2.71828^(0.540482 Automatic) (8029.63 Pa))^2+(-11545.7 Pa+2.71828^(0.170428 Automatic) (10748.1 Pa))^2+(-12212.3 Pa+2.71828^(0.0626864 Automatic) (11843.1 Pa))^2) is not a real number or quantity at {a,b,c} = {Automatic,Automatic,Automatic}. >>


What am I missing to resolve this issue? As always, your help is most appreciated.

• NonlinearModelFit does not yet support Quantity units. – ilian May 17 '15 at 21:33
• @ilian I suspected as much, but couldn't find confirmation anywhere in the docs, apart from the evidence brought by the OP. Would you have a resource listing functions that do / do not support Quantity? – MarcoB May 17 '15 at 21:41
• Thank you for the prompt response. Are there also issues with Solve that you happen to know of? Because I'm experiencing various errors there as well. – user27448 May 17 '15 at 22:30
• @MarcoB I think it would be good to have such a list. The closest thing is Units Overview which covers the initial scope as of version 9 and mentions various symbolic, numerical and statistical functions. Then the New in V10 pages mention some more recent extensions to visualization functions, Interpolation etc. The latest numerical function to become aware of quantities is NIntegrate and it is likely unit support will continue to be added throughout the system. – ilian May 18 '15 at 13:06
• @user27448 I would be interested in any examples of Solve failing where it shouldn't. Please feel free to post them on the site and/or email them to support@wolfram.com. – ilian May 18 '15 at 13:08