> restart; > f := proc(x) 2*x + 1; end: > rando := rand(-10^5 .. 10^5): > for i from 1 to 10 do > x[i] := i; > y[i] := f(i) + i*rando()/(10.0^5)/10; > od; > x[1] := 1 y[1] := 3.031994000 x[2] := 2 y[2] := 4.975450000 x[3] := 3 y[3] := 7.166623000 x[4] := 4 y[4] := 9.289180000 x[5] := 5 y[5] := 11.13348500 x[6] := 6 y[6] := 12.98072800 x[7] := 7 y[7] := 14.73242500 x[8] := 8 y[8] := 17.05532800 x[9] := 9 y[9] := 19.83168100 x[10] := 10 y[10] := 21.09528000 > points := []:for i from 1 to 10 do > points := [op(points), [x[i], y[i]]]; > od: > > points; [[1, 3.031994000], [2, 4.975450000], [3, 7.166623000], [4, 9.289180000], [5, 11.13348500], [6, 12.98072800], [7, 14.73242500], [8, 17.05532800], [9, 19.83168100], [10, 21.09528000]] > A := Matrix(10,2): b := Vector(10): > x_coords := []: y_coords:=[]: yw_coords:=[]: > for i from 1 to 10 do > x_coords := [op(x_coords), x[i]]; A[i,1] := 1; A[i,2] := x[i]; > y_coords := [op(y_coords), y[i]]; b[i] := y[i]; > yw_coords := [op(yw_coords), Weight(y[i],1/i)]; b[i] := y[i]; > od: > > A; [1 1] [ ] [1 2] [ ] [1 3] [ ] [1 4] [ ] [1 5] [ ] [1 6] [ ] [1 7] [ ] [1 8] [ ] [1 9] [ ] [1 10] > b; [3.031994000] [ ] [4.975450000] [ ] [7.166623000] [ ] [9.289180000] [ ] [11.13348500] [ ] [12.98072800] [ ] [14.73242500] [ ] [17.05532800] [ ] [19.83168100] [ ] [21.09528000] > with(LinearAlgebra): > xhat := LinearSolve(Transpose(A) . A, Transpose(A) . b); [.989760933333321824] xhat := [ ] [2.02535572121212315] > x_coords; [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] > y_coords; [3.031994000, 4.975450000, 7.166623000, 9.289180000, 11.13348500, 12.98072800, 14.73242500, 17.05532800, 19.83168100, 21.09528000] > model := stats[fit,leastsquare[[x,y],y='c'[1]*x + 'c'[2]]]([x_coords, > y_coords]); model := y = 2.025355721 x + .9897609333 # > read("/afs/eos.ncsu.edu/users/k/kaltofen/www/courses/LinAlgebra/Maple/ > LeastSqus/incsolve.mpl"): > xhat_inf := incsolve(convert(A,'matrix'), convert(b,vector)); w = .4496671250 xhat_inf := [.4823660000, 2.099960875] > Norm(A . xhat - b, infinity); .613718575757570050 > Norm(A . Transpose(convert(xhat_inf,'Vector')) - b, infinity); .604116669999996247 > yw_coords; [Weight(3.031994000, 1), Weight(4.975450000, 1/2), Weight(7.166623000, 1/3), Weight(9.289180000, 1/4), Weight(11.13348500, 1/5), Weight(12.98072800, 1/6), Weight(14.73242500, 1/7), Weight(17.05532800, 1/8), Weight(19.83168100, 1/9), Weight(21.09528000, 1/10)] > modelw := stats[fit,leastsquare[[x,y],y='c'[1]*x + 'c'[2]]]([x_coords, > yw_coords]); modelw := y = 2.022392924 x + 1.006056316 > xhatw := Vector([op([2,2],modelw),op([2,1,1],modelw)]); [1.006056316] xhatw := [ ] [2.022392924] > Norm(A . xhatw - b, 2); .829063295213279038 > model; y = 2.025355721 x + .9897609333 >