Friday, December 9, 2016

HP Prime and TI-84 Plus: Fitting Points to a Circle

HP Prime and TI-84 Plus:  Fitting Points to a Circle

Introduction



The program CIRCFIT attempts to fit a collection of points to the circle:

x^2 + y^2 = r^2

The center is assumed to be the origin (0,0).

The estimated radius is measured in three ways:

Maximum:  The radius is determined by the point that is furthest away from the origin.

Arithmetic Mean:  The radius is determined by the arithmetic mean (Σx/n) of all the radii.

Geometric Mean:  The radius is determined by the geometric mean ((Πx)^(1/n)) of all the radii.

For each estimated radius, the root mean square (RMS, see formula below) is calculated.  The object is to get the RMS as low as possible.  I tested several fits and its seems that the radius determined by the arithmetic mean gives the lowest RMS.

RMS = √( Σ((y_i – mean)^2) / n)

HP Prime Program:  CIRCFIT

EXPORT CIRCFIT(lx,ly)
BEGIN
// "CIRCLE FIT TEST"
// "EWS 2016-12-09"

LOCAL n,lr,r,s;
LOCAL a,b,g,h;

n:=SIZE(lx);
lr:=√(lx^2+ly^2);

PRINT();

r:=(MAX(lr));
s:=√(ΣLIST((lr-r)^2)/n);

PRINT("Maximum radius: "+√r);
PRINT("RMS: "+s);
PRINT("---------");
a:=mean(lr);
b:=√(ΣLIST((lr-a)^2)/n);

PRINT("Arithmetic mean: "+√a);
PRINT("RMS: "+b);
PRINT("---------");
g:=n NTHROOT ΠLIST(lr);
h:=√(ΣLIST((lr-g)^2)/n);

PRINT("Geometric mean: "+√g);
PRINT("RMS: "+h);

END;

TI-84 Plus Program CIRCFIT

"CIRCLE FIT TEST"
"EWS 2016-12-09"
Input "LIST X:",L
Input "LIST Y:",L
dim(L)→N
√(L²+L²)→L
max(L)→R
√(sum((L-R)²)/N)→S
Disp "MAX RADIUS:",√(R)
Disp "RMS:",S
Pause
mean(L)→A
√(sum((L-A)²)/N)→B
Disp "ARITH. AVG.:",√(A)
Disp "RMS:",B
Pause
Nx√(prod(L))→G
√(sum((L-G)²)/N)→H
Disp "GEOM. AVG.:",√(G)
Disp "RMS:",H

Examples

Each of the results are rounded to 5 digits.

Example 1:

X
Y
0.99
0.09
0.56
-0.82
-0.36
0.72
-0.96
-0.08

Maximum Radius:  0.99704, RMS: 0.09579
Arithmetic Mean: 0.96894, RMS:  0.07826
Geometric Mean:  0.96714, RMS:  0.07834


Example 2:

X
Y
1.02
0.01
0.96
-0.05
0.86
0.16
0.77
0.24
0.64
-0.33
0.03
1.00

Maximum Radius: 1.00997, RMS: 0.16356
Arithmetic Mean: 0.94724, RMS: 0.10798
Geometric Mean: 0.94362, RMS:  0.10819

This blog is property of Edward Shore, 2016