> 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) + rando()/(10.0^5)/10; > od; > x[1] := 1 y[1] := 2.953602000 x[2] := 2 y[2] := 5.036794000 x[3] := 3 y[3] := 7.004580000 x[4] := 4 y[4] := 9.098314000 x[5] := 5 y[5] := 11.02952400 x[6] := 6 y[6] := 12.93161500 x[7] := 7 y[7] := 15.09333500 x[8] := 8 y[8] := 17.05073800 x[9] := 9 y[9] := 19.07516700 x[10] := 10 y[10] := 21.04424800 > points := []:for i from 1 to 10 do > points := [op(points), [x[i], y[i]]]; > od: > > points; [[1, 2.953602000], [2, 5.036794000], [3, 7.004580000], [4, 9.098314000], [5, 11.02952400], [6, 12.93161500], [7, 15.09333500], [8, 17.05073800], [9, 19.07516700], [10, 21.04424800]] > p1 := plot(points, style=point,color = blue): > A := linalg[matrix](10,2): b := linalg[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: > > print(A); [1 1] [ ] [1 2] [ ] [1 3] [ ] [1 4] [ ] [1 5] [ ] [1 6] [ ] [1 7] [ ] [1 8] [ ] [1 9] [ ] [1 10] > print(b); [2.953602000, 5.036794000, 7.004580000, 9.098314000, 11.02952400, 12.93161500, 15.09333500, 17.05073800, 19.07516700, 21.04424800] > x_coords; [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] > y_coords; [2.953602000, 5.036794000, 7.004580000, 9.098314000, 11.02952400, 12.93161500, 15.09333500, 17.05073800, 19.07516700, 21.04424800] > model := stats[fit,leastsquare[[x,y],y=a*x + b]]([x_coords, > y_coords]); model := y = 2.007287085 x + .9917127333 > with(linalg): > xhat := linsolve(evalm(transpose(A) &* A), evalm(transpose(A) &* b)); xhat := [.9917127252, 2.007287086] > norm(evalm(A &* xhat - b), 2); .1521416914 > p2 := plot(op(2, model), x=0..10, color = red): > plots[display]({p1, p2}); > read("/afs/eos.ncsu.edu/users/k/kaltofen/www/courses/LinAlgebra/Maple/ > LeastSqus/incsolve.mpl"): > xhat_inf := incsolve(A, b); w = .08168983334 xhat_inf := [1.023262833, 1.998340333] > evalm(xhat); [.9917127252, 2.007287086] > norm(evalm(A &* xhat - b), infinity); .10382025 > norm(evalm(A &* xhat_inf - b), infinity); .08168984 > yw_coords; [Weight(2.931113000, 1), Weight(5.194618000, 1/2), Weight(6.733798000, 1/3), Weight(9.068172000, 1/4), Weight(11.47842000, 1/5), Weight(12.88197400, 1/6), Weight(14.73701000, 1/7), Weight(16.26247200, 1/8), Weight(18.18408700, 1/9), Weight(20.24305000, 1/10)] > modelw := stats[fit,leastsquare[[x,y],y=a*x + b]]([x_coords, > yw_coords]); modelw := y = 1.933546834 x + 1.136963814