Re: N-Dimensional line
- To: mathgroup at smc.vnet.net
- Subject: [mg22798] Re: [mg22785] N-Dimensional line
- From: BobHanlon at aol.com
- Date: Sun, 26 Mar 2000 02:58:48 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
The built-in function Fit does what you want. Let the dimension of the space be dim = 5; The variables to define the space are vars = ToExpression[Table["x" <> ToString[k], {k, dim}]]; The functions to define the line are funcs = Join[{1}, vars]; To generate test data coef = 10*Table[Random[], {dim + 1}]; Clear[f]; f[x_List] := First[coef] + (Rest[coef].x) /; Length[x] == dim data = Join[#, {f[#]}] & /@ Table[Random[], {dim + 2}, {dim}]; To Fit a line to the generated test data Fit[data, funcs, vars] 3.9635834515677497 + 4.0699930252986904*x1 + 5.430269807608436*x2 + 5.302060419354726*x3 + 8.430356457003278*x4 + 1.4150730899130353*x5 Verifying that this is the same line as that used to generate the test data % - f[vars] // Chop 0 Bob Hanlon In a message dated 3/25/2000 5:11:54 AM, birdy00 at bu.edu writes: >Does anyone have a reference and/or Mathematica code for finding the >line >in N-dimensional space that minimizes the distances from this line to a >set of >points in this space? >