1
$\begingroup$

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

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Rohit Namjoshi Jun 2 at 2:44
3
$\begingroup$
fit = Fit[QuantityMagnitude@data1, {1, x}, x]
(* 17.5294 + 0.000151023 x *)

Show[Plot[f, {x, 1*10^6, 1.2*10^7}], ListPlot[QuantityMagnitude@data1]]

Slope units: km/s/ly, intercept units: km/s

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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