#!/usr/bin/env ruby
require("gsl")
include GSL::Fit

n = 4
x = Vector.new([1970, 1980, 1990, 2000])
y = Vector.new([12, 11, 14, 13])
w = Vector.new([0.1, 0.2, 0.3, 0.4])

c0, c1, cov00, cov01, cov11, chisq = wlinear(x, w, y)

printf("# best fit: Y = %g + %g X\n", c0, c1);
printf("# covariance matrix:\n");
printf("# [ %g, %g\n#   %g, %g]\n", 
        cov00, cov01, cov01, cov11);
printf("# chisq = %g\n", chisq);

File.open("testwlinear-0.dat", "w") do |f|
  for i in 0...n do
    f.printf("%e %e %e\n", x[i], y[i], 1.0/Math::sqrt(w[i]))
  end
end
