Friday, September 1, 2017

TI-84 Plus CE: Fitting Points to an Ellipse

TI-84 Plus CE: Fitting Points to an Ellipse

Back to one of my favorite subjects: curve fitting.



The program ELLIPFIT attempts to fit a parametric curve for a collection of points (x, y) to an ellipse using the following equations:

x = a * cos t + b
y = c * sin t + d

where the independent variable is t.  The program also plots the estimated line and the scatter plot.  I decided to keep the correlation (r^2) separate, so we can tell how well the line fits both the x and y data. 

The program uses the range of 0 ≤ t ≤ 2*π, where t is in radians.

The user is asked to provide two lists, x and y.   The list of t values is determined by the atan2, angle, or arg function of the complex number point x + y*i.  The angle is adjusted to the range of [0, 2*π].

Quadrant I: x ≥ 0, y ≥ 0, angle(x + y*i)
Quadrant II: x < 0, y ≥ 0, angle(x + y*i)
Quadrant III: x < 0, y < 0, angle(x + y*i) + 2*π
Quadrant IV: x ≥ 0, y < 0, angle(x + y*i) + 2*π

TI-84 Plus CE Program ELLIPFIT

Notes:

L1: list 1, [ 2nd ] [ 1 ]; L2: list 2, [ 2nd ] [ 2 ], etc.  X1T, Y1T are from the [ vars ], Y-VARS, Parametric submenu

[square] is from [2nd] [ y= ] (stat plot) , MARK submenu, option 1

The complex variable i = √-1 is found by pressing [ 2nd ] [ . ].

Program:

"ELLIPTICAL FIT"
"2017-08-31 EWS"
Param:Radian:a+bi
Input "X LIST: ",L2
Input "Y LIST: ",L3
FnOff
L2→L1
For(I,1,dim(L1))
angle(L2(I)+L3(I)*i)→T
If L3(I)<0
Then
T+2π→T
End
T→L1(I)
End
PlotsOff
cos(L1)→L4
LinReg(ax+b) L4,L2
a→A:b→B:r²→E
"Acos(T)+B"→X1T
ClrHome
Disp "X = A*cos(T)+B"
Disp A
Disp B
Disp "CORR: "
Pause E
sin(L1)→L4
LinReg(ax+b) L4,L3
a→C:b→D:r²→F
"Csin(T)+D"→Y1T
ClrHome
Disp "Y = C*sin(T)+D"
Disp C
Disp D
Disp "CORR: "
Pause F
FnOn 1
PlotsOn 1
GraphColor(1,RED)
Plot1(Scatter,L2,L3,[square],GREEN)
0→Tmin
2π→Tmax
ZoomStat

(Obviously use the colors and makers you like.   If you are working with a monochrome TI-83/TI-84, ignore the color commands.)

You can get a download here:

Example 1

A perfect circle:

X
Y
0
1
1
0
0
-1
-1
0

Results:
x = cos t (r^2 = 1)
y = sin t (r^2 = 1)




Example 2

X
Y
1.0
0.0
0.5
0.5
0.0
1.0
-0.5
0.5
-1.0
0.0
-0.5
-0.5
0.0
-1.0
0.5
-0.5

Results:
x = 0.8535533906 cos t (r^2  ≈ 0.97140)
y = 0.8535533906 sin t  (r^2 ≈ 0.97140)

 


Eddie


This blog is property of Edward Shore, 2017.

TI 84 Plus CE: Consolidated Debts

TI 84 Plus CE: Consolidated Debts   Disclaimer: This blog is for informational and academic purposes only. Financial decisions are your ...