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




Tuesday, December 6, 2016

TI-84 Plus and Casio Prizm: Area between Polynomials p(x) and q(x)

TI-84 Plus and Casio Prizm:  Area between Polynomials p(x) and q(x)




The program POLYSURF calculates the area of a surfaces with:

* Side borders are straight vertical lines.  The left border line begins at x = 0
* The top and the bottom are defined polynomials: p(x) for the top and q(x) for the bottom.
* There are n partitions in the shape, for all partition points, p(x) > q(x).

The program also draws the shape.  If the number of partitions are 4 or less, an exact area is calculated.  Otherwise, p(x) and q(x) are approximated by a quartic polynomial and an approximated area is calculated.

TI-84 Plus Program POLYSURF

"EWS 2016-12-06"
Disp "P(X) > Q(X)"
FnOff
PlotsOff
{0}→L
Input "P(0)=",P
{P}→L
Input "Q(0)=",Q
{Q}→L
Input "NO. OF PARTITIONS:",N
For(I,1,N)
ClrHome
Output(7,1,"POINT")
Output(7,8,I)
Output(8,1,"P(X)>Q(X)")
Input "X:",X
Input "P(X):",P
Input "Q(X):",Q
augment(L,{X})→L
augment(L,{P})→L
augment(L,{Q})→L
End
L(dim(L))→L
If N=1
Then
LinReg(ax+b) L,L,Y
LinReg(ax+b) L,L,Y
End
If N=2
Then
QuadReg L,L,Y
QuadReg L,L,Y
End
If N=3
Then
CubicReg L,L,Y
CubicReg L,L,Y
End
If N≥4
Then
QuartReg L,L,Y
QuartReg L,L,Y
End
FnOn 1,2
fnInt(Y-Y,X,0,L)→S
Disp "AREA=",S
Pause
ClrDraw
­.5→Xmin
L+.5→Xmax
min(L)-.5→Ymin
max(L)+.5→Ymax
Shade(Y,Y,0,L)

Casio Prizm Program:  POLYSURF

The character # can be found by exiting to the “main” program menu (TOP, BOTTOM, etc).  Press F6 for CHAR, select #, and press [EXE].

Get the regressions by pressing [F4] (MENU), [F1] (STAT), [F6] twice (CALC, >) and selecting the regression.  The statistic variables a, b, c, d, and e are calculated after regression calculation.

“EWS 2016-12-06”
“P(x)>Q(x)”
{0} → List 1
“P(0)=”? → P
{P} → List 2
“Q(0)=”? → Q
{Q} → List 3
“# PARTITIONS:”? → N
For 1 → I To N
“POINT”
I
“X:”? → X
“P(X):”? → P
“Q(X):”? → Q
Augment(List 1, {X}) → List 1
Augment(List 2, {P}) → List 2
Augment(List 3, {Q}) → List 3
Next
If N = 1
Then
LinearReg (ax+b) List 1, List 2
a → A
b → B
“Ax+B” → Y1
LinearReg (ax+b) List 1, List 3
a → F
b → G
“Fx+G” → Y2
IfEnd
If N = 2
Then
QuadReg List 1, List 2
a → A
b → B
c → C
“Ax^2+Bx+C” → Y1
QuadReg List 1, List 3
a → F
b → G
c → H
“Fx^2+Gx+H” → Y2
IfEnd
If N = 3
Then
CubicReg List 1, List 2
a → A
b → B
c → C
d → D
“Ax^3+Bx^2+Cx+D” → Y1
CubicReg List 1, List 3
a → F
b → G
c → H
d → I
“Fx^3+Gx^2+Hx+I” → Y2
IfEnd
If N ≥ 4
Then
QuartReg List 1, List 2
a → A
b → B
c → C
d → D
e → E
“Ax^4+Bx^3+Cx^2+Dx+E” → Y1
CubicReg List 1, List 3
a → F
b → G
c → H
d → I
e → J
“Fx^4+Gx^3+Hx^2+Ix+J” → Y2
IfEnd
List 1[Dim List 1] → L
∫(Y1-Y2, 0, L) → S
“AREA=”
S
ClrGraph
ViewWindow -.5, L+.5, 1, Min(List 3)-.5, Max(List 2)+.5, 1
F-Line 0, List 2[1], 0, List 1[3]
Dim List 1 → Z
F-line List 1[Z], List 2[Z], List 1[Z], List 3[Z]
DrawGraph

Examples

Example 1



Data:
n
x
p(x)
q(x)
0
0
2
-2
1
1
5
-2
2
2
2
-2

Number of partitions, n = 2
Area = 12

Example 2



Data:
n
x
p(x)
q(x)
0
0.0
0.00
0.00
1
1.5
5.62
-0.64
2
2.5
3.83
1.38
3
3.5
1.25
0.76

Number of Partitions, n = 3
Area ≈ 13.16619792

Example 3



Data:
n
x
p(x)
q(x)
0
0.00
3.00
-3.00
1
0.50
2.54
-2.84
2
1.25
2.01
-3.00
3
1.60
2.36
-3.55
4
2.00
2.76
-1.98

Number of Partitions, n = 4
 Area ≈ 10.77281698

This blog is property of Edward Shore, 2016


Sunday, December 4, 2016

TI-84 Plus: Staircases

TI-84 Plus:  Staircases
  
Given the rise (height from lower floor to upper floor), run (length of the staircase), and desired riser height (how high each stair is), the program STAIRS calculates the number risers needed, along with the width of each stair, the incline, and finally illustrates the staircase. STAIRS is designed with inches and feet (US units) in mind. 



Formulas

Given:  Rise, Run, Desired Rise Height (DRH)

Number of Risers:
n = rise/DRH, rounded to the nearest integer

Tread width:
TW = run/(n – 1)

Adjusted Riser Height (ARH)
ARH = rise/n, rounded to the nearest 1/16th

One way to approach this: 
ARH = round(16*frac(rise/n),0)*16 + int(rise/n)

Incline:
θ = atan(RH/TW)

Other Calculations:

Stringer:
S = (n – 1)*√(ARH^2 + TW^2)

Number of Stairs:
N_stairs = n - 1


TI-84 Plus Program: STAIRS

Input:  Rise, Run, Desired Riser Height.  Keep the units consistent.  (12 inches = 1 foot)

Output:  Number of Risers (R), Tread width of each stair (T), Adjusted Riser Height (H), Angle of Incline (θ)

* Adjusted Riser Height is rounded to the nearest 1/16th (of an inch).  This is accomplished by the line iPart(H)+round(16*fPart(H),0)/16

The graph screen shows the staircase.  A stat plot shows where each stair ends with X (L1) representing the position and Y representing the height (L2). 

The program sets the TI-84 Plus to Degrees mode.

"EWS 2016-12-03"
Degree
Input "RISE:",B
Input "RUN:",A
Input "DESIRED RISER HEIGHT:",H
round(B/H,0)→N
A/(N-1)→T
B/N→H
"ROUND H TO 1/16"
iPart(H)+round(16*fPart(H),0)/16→H
tan^-1(H/T)→θ
√(H²+T²)*(N-1)→S
Disp "NUMBER OF RISERS:",N
Disp "TREAD WIDTH:",T
Pause
Disp "ADJ. RISER HEIGHT:",H
Disp "ANGLE:",θ
Pause
{0}→L1:{0}→L2
­.5→Xmin:A+.5→Xmax
­.5→Ymin:B+.5→Ymax
ClrDraw
For(I,1,N-1)
augment(L1,{I*T})→L1
augment(L2,{I*H})→L2
End
PlotsOff
PlotsOn 1
Plot1(xyLine,L1,L2)
Line(0,0,A,0)
Line(A,0,A,B)
For(I,0,N-1)
Line(T*I,H*I,T*I,H*(I+1))
Line(T*I,H*(I+1),T*(I+1),H*(I+1))
End
DispGraph




Examples

All amounts are in inches.

Example 1:  Rise = 35 in, Run = 84 in, Desired Riser Height = 7 in
Results:  Number of Risers: 5, Tread width: 21 in, Adjusted Riser Height:  7 in, θ ≈ 18.43495°

Example 1 is shown in the screen shots above.

Example 2:  Rise = 40 in, Run = 90 in, Desired Riser Height = 7 in
Results:  Number of Risers: 6, Tread width: 18 in, Adjusted Riser Height:  6.6875 in,
θ ≈ 20.38143°

Example 3:  Rise = 56 in, Run = 50 in, Desired Riser Height = 6.5 in
Results:  Number of Risers: 9, Tread width: 6.25 in, Adjusted Riser Height:  6.25 in,
θ ≈ 45°

This program was inspired by the Calculated Industries Construction Master 5 calculator

Eddie


This blog is property of Edward Shore, 2016

DM42 and HP 42S: Quadratic Equation, Characteristic Polynomial, and Eigenvalues

DM42 and HP 42S: Quadratic Equation, Characteristic Polynomial, and Eigenvalues The programs are listed for the Swiss Micros DM42 an...