# Why UnitCovert doesn't work with Fit?

I need to find the Hubble constant (Ho) in light years, from some data, the exercise tells me that the constant of the hubble is the slope of the line.

data: r1 is in MegaParsecs.

r1 = UnitConvert[Quantity[{1.52, 3.45, 2.37, 0.62, 1.16, 1.42, 0.67, 1.24, 0.79, 1.0,1.74, 1.49, 1.1, 1.27, 1.53, 1.79, 1.2, 2.35, 2.23, 2.06, 1.73},"Megaparsecs"], "LightYears"]


and v1 is in Km/s

v1 = Quantity[{650, 1800, 1300, 300, 800, 700, 400, 600, 290, 600,940, 810, 600, 730, 800, 800, 580, 1100, 1140, 900, 650},"Kilometers"/"Seconds"]


I used Transpose.

data1 = {r1, v1}\[Transpose];


and then Fit

aj1 = Fit[data1, {1, x}, x]


but I have this error message...

Fit::fitm: Unable to solve for the fit parameters; the design matrix is nonrectangular, non-numerical, or could not be inverted.

I dont know why, and I need to get the constant for my homework

• Looks like Fit cannot deal with units. Try Fit[QuantityMagnitude@data1, {1, x}, x]. Then you can add the units to the slope and intercept. – Rohit Namjoshi Jun 2 '19 at 2:44

fit = Fit[QuantityMagnitude@data1, {1, x}, x]