In [ ]:
h = [0.282, 0.564, 0.752, 0.940]
d = [0.752, 1.102, 1.248, 1.410]
using Plots
scatter(h,d)
plot!(xlim=(0,1.5),ylim=(0,2),
    xlabel="Height",ylabel="Distance")
In [12]:
m = length(h)
A = [ones(m,1) h]
b = d
@show A
@show b
@show c = A\b
;
A = [1.0 0.282
 1.0 0.564
 1.0 0.752
 1.0 0.94]
b = [0.752,1.102,1.248,1.41]
c = A \ b = [0.49816822429906615,0.9926426724995022]
Out[12]:
2-element Array{Float64,1}:
 0.498168
 0.992643
In [16]:
scatter(h,d,label="Galileo's data")
plot!(h, c[1]+c[2]*h, color="red", label="Best fit")
plot!(xlim=(0,1.5),ylim=(0,2),
    xlabel="Height",ylabel="Distance")
Out[16]: