-2
$\begingroup$

I have a mathematica subroutine setup that computes the least squares approximation as follows

uniform[n_, knot_, data_] := (m = Length[data] - 1; 
vandermonde = 
Table[BernsteinBasis[n, j - 1, knot[[i]]], {i, 1, m + 1}, {j, 1, 
  n + 1}]; 
bez = LinearSolve[Transpose[vandermonde].vandermonde, 
 Transpose[vandermonde].data]; dplot = ListPlot[data]; 
points = Graphics[{PointSize[0.015], Point[bez]}]; 
bplot = ListLinePlot[bez]; 
curve[t_] := Sum[BernsteinBasis[n, i, t]*bez[[i + 1]], {i, 0, n}]; 
cplot = ParametricPlot[curve[t], {t, 0, 1}, 
 PlotStyle -> {Thick, Green}]; 
Show[{cplot, points, bplot, dplot}]);

I now need to compute the least squares error for the set of equations and return the total,min,max and average error.

I went through this example in order to understand the concept - https://en.wikipedia.org/wiki/Linear_least_squares_(mathematics)#Motivational_example

I am unsure as to how to proceed with performing this computation in mathematica as I'm still a newbie.

$\endgroup$

closed as unclear what you're asking by dr.blochwave, MarcoB, RunnyKine, Dr. belisarius, Andy Ross Mar 7 '16 at 0:45

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

3
$\begingroup$

Here's how to calculate the errors in a simple case. a is a matrix and b is a vector. You find the x that minimizes the least square error and then calculate the errors err. Then find the Total, Min, Max, Mean.

a = RandomReal[{-1, 1}, {3, 2}];
b = RandomReal[{-1, 1}, 3];
x = LeastSquares[a, b]
err = a.x - b;
{Total[err], Min[err], Max[err], Mean[err]}
$\endgroup$

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