MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

show residuals of circle fit

  • To: mathgroup at smc.vnet.net
  • Subject: [mg79900] show residuals of circle fit
  • From: will <willpowers69 at hotmail.com>
  • Date: Wed, 8 Aug 2007 04:53:39 -0400 (EDT)

Dear Mathforum,

I am having a problem with displaying residuals after fitting a circle to
a set of points. I am using some code that I found on the mathgroup 
site (see:http://forums.wolfram.com/mathgroup/archive/2003/Jan/msg00019.html)
 to generate the points and fit the circle:

points generation and display:

points = Table[theta = Random[];
  {2*Cos[theta] + 1 + .05*Random[], 
   2*Sin[theta] - 3 + .05*Random[]}, {30}]

plot = ListPlot[points, AspectRatio -> Automatic]

circle fitting and display with points:

fit circle:

hypersphereFit[data_List] := 
 Module[{mat, rhs, qq, rr, params, cen}, 
  mat = Map[Append[#, 1] &, data];
  rhs = Map[#.# &, data];
  {qq, rr} = QRDecomposition[mat];
  params = LinearSolve[rr, qq.rhs];
  cen = Drop[params, -1]/2;
  {Sqrt[Last[params] + cen.cen], cen}]

display circle (using Graphics[Circle[]] inputing the results from the above
function) and points:

Show[Graphics[
  Circle[Part[hypersphereFit[points], 2], 
   Part[hypersphereFit[points], 1], {0, 1}]], plot]

now i really want to be able to display the residuals for the points, but can't
figure out how to. 

If it is any help i use the following code when displaying residuals from 
a quadratic curve fit:

quadratic fit:

func = Fit[points, {1, x, x^2}, x]

define range of plot:

Insert[Part[Sort[points], {1, -1}, 1], x, 1]

out: {x, 2.1305, 3.04856}

copy and paste this output into the range for the Plot function:

Show[Graphics[
  Plot[func, {x, 2.1305, 3.04856}]], 
 ListPlot[points, PlotStyle -> {Red, PointSize[Small]}], Axes -> True,
  AspectRatio -> Automatic]

this shows the quadratic fitted line with the points

then calculate and display the residuals for the quadratic fit:

res = Transpose[{First /@ points, 
    Last /@ points - (func /. x -> First /@ points)}];
ListPlot[res]

I would really, really like to be able to do this residuals calculation
and display for the circle fit.

Any help would be much appreciated,

William Parr


  • Prev by Date: Re: problems with delayed write: tag list
  • Next by Date: Re: problems with delayed write: tag list
  • Previous by thread: Re: Can model parameters be global?
  • Next by thread: Re: show residuals of circle fit