Showing posts with label slope. Show all posts
Showing posts with label slope. Show all posts

Sunday, January 18, 2026

HP 15C: Distance and Slope Between Two Points Using Polar Conversion and the Stack

HP 15C: Distance and Slope Between Two Points Using Polar Conversion and the Stack



HP 15C Program: Distance and Slope



This short program calculates the slope and distance between two Cartesian points (x1, y1) and (x2, y2) using the four level stack and rectangular-polar conversion. The code can be adopted to other Hewlett Packard, Swiss Micros, and other RPN with four-stacks. RPL will need a short adjustment.



Input Stack:

T: y2

Z: x2

Y: y1

X: x1



Code:

LBL A

001

42, 21, 11

Program start

X<>Y

002

34


R↓

003

33


-

004

30


R↓

005

33


-

006

30


CHS

007

16


R↑

008

43, 33

Y: Δy, X: Δx

→P

009

43, 1

Rectangular to polar conversion; calculate distance

X<>Y

010

34


TAN

011

25

Calculate slope

X<>Y

012

34


RTN

013

43, 32

Program end









Reference formulas



Distance = √((x2^2 – x1^2) + (y2^2 – y1^2))

Slope = (y2 – y1) ÷ (x2 – x1) = tan(Θ)



Derivation:

Let y’ = y2 – y1 and x’ = x2 – x1

Then by rectangular to polar function, angle:

Θ = arctan( y’ / x’ )

tan Θ = y’ / x’

tan Θ = (y2 – y1) ÷ (x2 – x1)



Examples



Example 1: (-3, 8) to (11, 16)

Stack:

T: 16

Z: 11

Y: 8

X: -3

Result:

Y: slope ≈ 0.5714

X: distance ≈ 16.1245



Example 2: (5, 6) to (7, 9)

Stack:

T: 9

Z: 7

Y: 6

X: 5

Result:

Y: slope = 1.5000

X: distance ≈ 3.6056


Eddie


All original content copyright, © 2011-2026. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

Sunday, March 31, 2024

TI-30Xa Algorithms: Linear Regression

 TI-30Xa Algorithms: Linear Regression


Welcome to the March 2024 installment of TI-30Xa Algorithms.



Linear Regression with a TI-30Xa?


Today’s task is to fit bi-variate data to the line:


y = m * x + b


with the TI-30Xa. What? This calculator does not have a linear regression mode. Yes, with it is possible. We are going to use the technique shown in by the TI-36 Solar Guidebook from 1985 (see Source below). The TI-36 Solar was part of Texas Instruments’ line in the late 1980s and the early 1990s.


You can read my review on the TI-36 Solar from September 26, 2020 here:

https://edspi31415.blogspot.com/2020/09/retro-review-ti-36-solar.html


Where the TI-36 Solar only had one memory register, the TI-30Xa has three memory registers, and they are going to come in handy here.



Procedure


Caution: Be sure the calculator is on the entire time. Turning off the calculator will clear out statistics mode.


1. Enter the y data. Store the mean (y-bar) into memory register 2. Store the population deviation (σy) into memory register 3.


Keystrokes:

Mean of y-data: [ 2nd ] [ x^2 ] {x-bar} [ STO ] [ 2 ]

Population of y-data: [ 2nd ] [ ÷ ] { σxn } [ STO ] [ 3 ]


2. Clear the stat registers and enter the x data. As we are entering the x data, use memory register 1 to calculate Σxy.


Keystrokes:


Clear Stat Registers: [ 2nd ] [ 7 ] {CSR}


1st Point:

x1 [ × ] y1 [ = ] [ STO ] [ 1 ]

x1 [ Σ+ ]


Every point there after:

x_i [ × ] y_i [ = ] [ 2nd ] [ RCL ] {SUM} [ 1 ]

x_i [ Σ+ ]



3. Calculate the slope, and replace Σxy with the slope.


m = ( y-bar * Σx – Σxy) / ( x-bar * Σx - Σx^2)


Keystrokes:

[ ( ] [ RCL ] [ 2 ] [ × ] [ 2nd ] [ ( ] [ - ] [ RCL ] [ 1 ] [ ) ]

[ ÷ ] [ ( ] [ 2nd ] [ x^2 ] [ × ] [ 2nd ] [ ( ] [ - ] [ 2nd ] [ ) ] [ = ] [ STO ] [ 1 ]


4. Calculate the y-intercept, replace y-bar with the y-intercept.


b = -m * x-bar + y-bar


Keystrokes:

[ RCL ] [ 1 ] [ +/- ] [ × ] [ 2nd ] [ x^2 ] [ + ] [ RCL ] [ 2 ] [ = ] [ STO ] [ 2 ]


5. Calculate the correlation. If the correlation is close to -1 or +1, the linear fit will be excellent.


r = m * σx / σy


Keystrokes:

[ RCL ] [ 1 ] [ × ] [ 2nd ] [ ÷ ] [ ÷ ] [ RCL ] [ 3 ] [ = ]


6. Use slope (m) and intercept (b) to predict x and y values:


y’ = m * x0 + b

Keystrokes: [ RCL ] [ 1 ] [ × ] x0 [ + ] [ RCL ] [ 2 ] [ = ]


x’ = (y0 – b) / m

Keystrokes: [ ( ] y0 [ - ] [ RCL ] [ 2 ] [ ) ] [ ÷ ] [ RCL ] [ 1 ] [ = ]


Key Map


[ RCL ] [ 1 ]: first Σxy, then m

[ RCL ] [ 2 ]: first y-bar, then b

[ RCL ] [ 3 ]: σy

[ 2nd ] [ x^2 ]: x-bar

[ 2nd ] [ ÷ ]: σxn



Example


Fit a line to the data:


X

Y

12

100

13

98.7

14

97.1

16

94.9

18

92.6

20

90



1. Enter the y data. Store the mean (y-bar) into memory register 2. Store the population deviation (σy) into memory register 3.


100 [ Σ+ ]

98.7 [ Σ+ ]

97.1 [ Σ+ ]

94.9 [ Σ+ ]

92.6 [ Σ+ ]

90 [ Σ+ ] (display n = 6)



Mean of y-data: [ 2nd ] [ x^2 ] [ STO ] [ 2 ] (y-bar = 95.55)


Population of y-data: [ 2nd ] [ ÷ ] [ STO ] [ 3 ] (σy = 3.465424457)



2. Clear the stat registers and enter the x data. As we are entering the x data, use memory register 1 to calculate Σxy.


Keystrokes:


Clear Stat Registers: [ 2nd ] [ 7 ] {CSR}


12 [ × ] 100 [ = ] [ STO ] [ 1 ]

12 [ Σ+ ]


13 [ × ] 98.7 [ = ] [ 2nd ] [ RCL ] [ 1 ] (SUM 1)

13 [ Σ+ ]


14 [ × ] 97.1 [ = ] [ 2nd ] [ RCL ] [ 1 ] (SUM 1)

14 [ Σ+ ]


16 [ × ] 94.9 [ = ] [ 2nd ] [ RCL ] [ 1 ] (SUM 1)

16 [ Σ+ ]


18 [ × ] 92.6 [ = ] [ 2nd ] [ RCL ] [ 1 ] (SUM 1)

18 [ Σ+ ]


20 [ × ] 90 [ = ] [ 2nd ] [ RCL ] [ 1 ] (SUM 1)

20 [ Σ+ ]


RCL 1: Σxy = 8827.7

[ 2nd ] [ x^2 ]: x-bar = 15.5



3. Calculate the slope, and replace Σxy with the slope.


[ ( ] [ RCL ] [ 2 ] [ × ] [ 2nd ] [ ( ] [ - ] [ RCL ] [ 1 ] [ ) ]

[ ÷ ] [ ( ] [ 2nd ] [ x^2 ] [ × ] [ 2nd ] [ ( ] [ - ] [ 2nd ] [ ) ] [ = ] [ STO ] [ 1 ]


Slope: m = -1.230526316


4. Calculate the y-intercept, replace y-bar with the y-intercept.


[ RCL ] [ 1 ] [ +/- ] [ × ] [ 2nd ] [ x^2 ] [ + ] [ RCL ] [ 2 ] [ = ] [ STO ] [ 2 ]


Intercept: b = 114.6231579


5. Calculate the correlation.


[ RCL ] [ 1 ] [ × ] [ 2nd ] [ ÷ ] [ ÷ ] [ RCL ] [ 3 ] [ = ]


Correlation: r = -0.999092386


The line is:


y = -1.230526316 * x + 114.6231579



6. Predict values.


If x = 15, predict the y value (y’):


[ RCL ] [ 1 ] [ × ] x0 [ + ] [ RCL ] [ 2 ] [ = ]

y’ = 96.16526316


If y = 95, predict the x value (x’):


[ ( ] y0 [ - ] [ RCL ] [ 2 ] [ ) ] [ ÷ ] [ RCL ] [ 1 ] [ = ]

x’ = 15.94696322



Source


Alley, Chris M., Brenda M. Cornitius, et al. TI-36 Solar Guidebook Texas Instruments Incorporated. Dallas, TX. 1985, 1986, 1987. pp. 4.6 – 4.13



Eddie


All original content copyright, © 2011-2024. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

Sunday, May 16, 2021

TI-NSpire CX II and TI-84 Plus CE: Enhanced Graphing Table

TI-NSpire CX II and TI-84 Plus CE:  Enhanced Graphing Table


Introduction


The program TABLEYX allows the user to enter a function, not only store it for graphing, but also display an analytic table.  Results are stored in lists so they can be used for further analysis.  


Both the TI-NSpire CX II (.tns) and TI-84 Plus CE (.8xp) version can be downloaded here.


TI-NSpire CX Version






Table of contents:

1.1  The Notes Page 

1.2  Calc Page:  run tableyx() here

1.3  Graph Page:  it should update automatically each time tableyx() is run

14.  Table Page:  updates when tableyx() is executed

1.5  Program Listing


Lists:

xlist:  x coordinates

ylist:  y(x)

dislist:  Euclidean distance from (0,0) to (x,y)

arclist:  Arclength of y(x) from 0 to x

derlist:  Derivative at (x,y)

intlist:  Integral of y(x) from 0 to x


Program:


Define tableyx()=

Prgm

:© set approximate mode

:setMode(5,2)

:© main program

:Request "y(x)? ",y(x)

:Request "Δx? ",dx

:Request "Number of steps? ",n

:seq(i,i,0,dx*n,dx)→xlist

:seq(y(i),i,0,dx*n,dx)→ylist

:seq(∫(y(x),x,0,i),i,0,dx*n,dx)→intlist

:seq(nDerivative(y(x),x=i),i,0,dx*n,dx)→derlist

:seq(approx(arcLen(y(x),x,0,i)),i,0,dx*n,dx)→arclist

:√(xlist^(2)+ylist^(2))→dislist

:Disp "Done.  See the next page for results."

:EndPrgm


TI-84 Plus CE Version


When the program ends:


Press [ graph ] to see the graph.


Press [ stats ], select Edit... to see the lists in a list editing format.


Lists:

L1:  x coordinates

L2:  y(x)

L3:  Euclidean distance from (0,0) to (x,y)

L4:  Derivative at (x,y)

L5:  Integral of y(x) from 0 to x


Program:


Float

Radian

Input "Y(X)=",Str1

String>Equ(Str1,Y₁)

Input "CHG X? ",D

Input "NO OF STEPS? ",N

seq(I,I,0,D*N,D)→L₁

seq(Y₁(I),I,0,D*N,D)→L₂

√(L₁²+L₂²)→L₃

seq(nDeriv(Y₁(X),X,I),I,0,D*N,D)→L₄

seq(fnInt(Y₁(X),X,0,I),I,0,D*N,D)→L₅

ClrHome

Disp "RESULTS","L₁: X","L₂: Y","L₃: DIST FROM (0,0)","L₄: D/DX Y(X)","L₅: INTEGRAL FROM X=0","PRESS STAT, EDIT"

Pause 

SetUpEditor L₁,L₂,L₃,L₄,L₅



Eddie


All original content copyright, © 2011-2021.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 



Saturday, September 28, 2019

fx-260 Solar Algorithms Part I

fx-260 Solar Algorithms Part I

All results are shown to screen accuracy. 

Sphere:  Surface Area and Volume

With the radius r,
the surface area is S = 4 * π * r^2
the volume area is V = 4/3 * π * r^3

Algorithm:
r  [SHIFT] (Min) [ x² ] [ × ] [EXP](π) [ × ] 4 [ = ]    // surface area is displayed
[ × ] [ MR ] [ ÷ ] 3 [ = ]   // area is displayed

M = r

Example:
Input:
r = 3.86

Results:
3.86  [SHIFT] (Min) [ x² ] [ × ] [EXP](π) [ × ] 4 [ = ]   
Surface Area = 187.2338956

[ × ] [ MR ] [ ÷ ] 3 [ = ] 
Volume = 204.9076123

Monthly Payment of a Mortgage or Auto Loan

Input:
A = amount of the mortgage/loan
I = annual interest rate
N = number of months

The monthly payment can be found by:
PMT = ( 1 - (1 + I/1200)^-N) / (I/1200)

Algorithm:
I [ ÷ ] 1200 [ = ] [SHIFT] (Min)   // stores I/1200 into M
1 [ - ] [ ( ] 1 [ + ] [ MR ] [ ) ] [ x^y ] N [ +/- ] [ = ]
[SHIFT] (1/x) [ × ] [ MR ] [ × ] A [ = ]     // monthly payment

Example:
Input: 
I = 4  (4%)
N = 360
A = 85000

Result:
4 [ ÷ ] 1200 [ = ] [SHIFT] (Min)   // stores I/1200 into M
1 [ - ] [ ( ] 1 [ + ] [ MR ] [ ) ] [ x^y ] 360 [ +/- ] [ = ]
[SHIFT] (1/x) [ × ] [ MR ] [ × ] 85000 [ = ]     // monthly payment

PMT = 405.8030014   ($405.80)
(I/1200 = M = 3.333333333E-03)

Electromagnetic Field Strength 

Given the EIRP (effective isotropic radiated power) of a microwave (in Watts), we can calculate the following:

Power Flux Density: 
S = EIRP / (4 * π * d^2)   (W/m^2,  d = distance from the wave source in meters)

Electric Field:
E = √(30 * EIRP) /  d   (W/m)

Magnetic Field:
H = √(EIRP / (480 * π^2 * d^2) )  (A/m)

Algorithm:

Calculating Power Flux: 
EIRP [ ÷ ] [ ( ] 4 [ × ] [EXP](π) [ × ]  d [ x² ] [ ) ] [ = ]

Calculating Electric Field: 
[ ( ] EIRP [ × ] 30 [ ) ] [SHIFT] (√) [ ÷ ] 0.5 [ = ]

Calculating Magnetic Field:
[ ( ] EIRP [ ÷ ] [ ( ] 480 [ × ] [EXP](π) [ x² ] [ × ] d [ x² ] [ ) ] [ ) ] [ √ ] [ = ]

Example:
Input:
EIRP = 1800 W
d =  0.5 m   (distance)

Results:

Calculating Power Flux: 
1800 [ ÷ ] [ ( ] 4 [ × ] [EXP](π) [ × ]  0.5 [ x² ] [ ) ] [ = ]
Power Flux: 572.9577951 W/m^2

Calculating Electric Field: 
[ ( ] 1800 [ × ] 30 [ ) ] [SHIFT] (√) [ ÷ ] 0.5 [ = ]
Electric Field: 464.7580015 W/m

Calculating Magnetic Field:
[ ( ] 1800 [ ÷ ] [ ( ] 480 [ × ] [EXP](π) [ x² ] [ × ] 0.5  [ x² ] [ ) ] [ ) ] [ √ ] [ = ]
Magnetic Field: 1.232808888 A/m

Source:  Barue, Gerardo.  Microwave Engineering: Land & Space Radiocommunications John Wiley & Sons, Inc.  Hoboken, NJ  ISBN 978-0-470-08966-5 2008

Slope and Intercept with Two Points

Given two points of a line (x1, y1) and (x2, y2) we can find the slope (a) and y-intercept (b) of the general linear equation y = a*x + b.

The trick is to use the rectangular to polar conversion to find the slope:
θ = atan((y2 - y1)/(x2 -x1))
tan θ = (y2 - y1)/(x2 -x1) = slope = a

Once the slope is found, we can solve for the y-intercept:
y = a*x + b
b = y - a*x

Algorithm:
[ ( ] x1 [ - ] x2 [ ) ] [SHIFT] (R→P) [ ( ] y1 [ - ] y2 [ ) ] [ = ] [SHIFT] (X<>Y) [ tan ]
// slope is displayed

[ × ] x1* [ +/- ] [ + ] y1* [ = ]
// intercept is displayed

*x2 and y2 can be used instead

Example:
(x1, y1) = (8, 5.5)
(x2, y2) = (4, 9.5)

Result:
[ ( ] 8 [ - ] 4 [ ) ] [SHIFT] (R→P) [ ( ] 5.5 [ - ] 9.5 [ ) ] [ = ] [SHIFT] (X<>Y) [ tan ]

Slope: -1

[ × ] 8 [ +/- ] [ + ] 5.5 [ = ]

Slope: 13.5


Tomorrow will be Part II. 

Eddie

All original content copyright, © 2011-2019.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

Wednesday, August 8, 2018

HP 35S: Intersection Point of a Quadrilateral


HP 35S: Intersection Point of a Quadrilateral

Introduction

Let A, B, C, and D be four vertices of a quadrilateral, with two lines:

Line AC connects points A and C.
Line BC connects points B and D.



Designate the following points as:

A:  (ax, ay)
B:  (bx, by)
C:  (cx, cy)
D:  (dx, dy)

The center point (px, py) can be found by the following formulas:

px = (IBD – IAC)/(SAC – SBD)
py = SAC * px + IAC

Where:

Slope:
SAC = (cy – ay) / (cx – ax)
SBD = (dy – by) / (dx – bx)

Intercept:
IAC = ay – SAC * ax
IBD = by – SBD * bx

You can see the derivation of these formulas here:  https://edspi31415.blogspot.com/2017/08/geometry-intersection-point-of.html

Program  (Pedro Daniel Leiva)

The following program calculates the point – developed by Pedro Daniel Leiva. I used the recall arithmetic available on the HP 35S to shorten the program.  Program listed here with permission. 

Variables Used:

R_A = ax
R_B = ay
R_C = bx
R_D = by
R_E = cx
R_F = cy
R_G = dx
R_H = dy
R_I = SAC
R_J = SBD
R_K = IAC
R_L = IBD
R_P = px
R_Y = py

Program:

I001 LBL I
I002 SF 10
I003 ENTER XA^YA  \\ EQN
I004 STO B
I005 x<>y
I006 STO A
I007 ENTER XB^YB  \\ EQN
I008 STO D
I009 x<>y
I010 STO C
I011 ENTER XC^YC \\ EQN
I012 STO F
I013 x<>y
I014 STO E
I015 ENTER XD^YD  \\ EQN
I016 STO H
I017 x<>y
I018 STO G
I019 CF 10
I020 RCL F
I021 RCL - B     \\ [RCL] [ - ] ( B )
I022 RCL E
I023 RCL - A  \\ [RCL] [ - ]  ( A ) 
I024 ÷
I025 STO I
I026 STO P  \\ advanced storage to calculate px to save steps
I027 RCL× A
I028 +/-
I029 RCL+ B
I030 STO K
I031 RCL H
I032 RCL - D
I033 RCL G
I034 RCL – C
I035 ÷
I036 STO J
I037 STO – P
I038 RCL × C
I039 +/-
I040 RCL + D
I041 STO L
I042 RCL – K
I043 RCL ÷ P
I044 STO P
I045 ENTER
I046 RCL × I
I047 RCL + K
I048 STO Y
I049 x<>y
I050 RTN

50 steps

Instructions:

At each prompt, enter the x point, press [ENTER], enter the y point, press [ R/S ].  The result shows py on the Y stack, and px on the X stack.

Example:

A:  (0, 8)
B:  (11, 12)
C:  (10, 4)
D:  (3, 5)

Results:

py = 6.2353
px = 4.4118

Eddie


 All original content copyright, © 2011-2018.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.  Please contact the author if you have questions.

Saturday, August 12, 2017

Geometry: The Intersection Point of a Quadrilateral

Geometry: The Intersection Point of a Quadrilateral




The Setup

We are given four points, A, B, C, and D, as four Cartesian coordinates.  We connect the four points, starting with A, in a clockwise form to form a quadrilateral.  We will designate each points as the coordinates:

A:  (ax, ay)
B:  (bx, by)
C:  (cx, cy)
D:  (dx, dy)

Draw a line from one corner to the opposite corner.  This results in two lines: AC and DB.  The two lines (show above in lime green) meet at point P.  The goal is determine the coordinates of P.

Slope

We know the equation of the line is y = m*x + b, where m is the slope and b is the y-intercept. Note that:

y = m*x + b
y – m*x = b

In geometry, the slope of a line containing two points is generally defined as:

m = (change in y coordinates)/(change in x coordinates) = Δy/Δx = (y2 – y1)/(x2 – x1)

The slope of AC:   SAC = (cy – ay)/(cx – ax)

The slope of BD:  SBD = (dy – by)/(dx –bx)

The Intercept

We can easily deduce that solving the general equation of the line y = m*x + b for the intercept yields b = y – m*x.  If follows that:

The intercept of AC:  IAC = cy – SAC * cx = ay – SAC *ax

The intercept of BD:  IBD = by – SBD * bx = dy – IBD *dx

Finding the Intersection Point

Now that the slopes and intercepts are determined, we can form the following system of equations:

(I) y = SAC * x + IAC
(II) y = SBD * x + IBD

Solving for x and y will find our intersection point P (px, py).  Subtracting (II) from (I) (see above):

0 = (SAC – SBD) * x + (IAC – IBD)

We can solve for x.

-(IAC – IBD) = (SAC – SBD) * x
(-1*IAC - -1*IBD) = (SAC – SBD) * x
(-IAC + IBD) = (SAC – SBD) * x
(IBD – IAC) = (SAC – SBD) * x

Hence:

x = px = (IBD – IAC)/(SAC – SBD)

It follows that we determine y by either equation (I) or (II):

y = py = SAC * px + IAC = SBD * px + IBD


Our desired coordinates of point P are found.

Eddie

This blog is property of Edward Shore, 2017.
x

Trigonometry Reduction Formula and Solving Simple Arcsine and Arccosine Equations

Trigonometry Reduction Formula and Solving Simple Arcsine and Arccosine Equations Some Background and Periodic Reduction Formulas ...