Showing posts with label HP 17BII. Show all posts
Showing posts with label HP 17BII. Show all posts

Thursday, May 30, 2019

HP Prime and HP 17BII: Trapezoid Rule Using Distinct Points

HP Prime and HP 17BII: Trapezoid Rule Using Distinct Points



Introduction

We can estimate the area of any surface by the use of sums and integral.  In calculus, we usually are given a function f(x), but here we are using measurements from one end to the other at various intervals. 

Technically, the intervals between each measurement do not have to be equal length.  However, having intervals of equal length makes things a lot easier, and in this blog entry, we assume they are. 

We have various methods to estimate the area.  One of the easiest ways is the Trapezoid Rule:

Area ≈ h/2 * ( y_1 + y_n + 2 * Σ( y_k , k, 2, n-1 ) )

Where:

h = interval length
y_k = length of each measurement, there are  n measurements
y_1 and y_n:  measurement of lengths at each end, respectively

Another rule to estimate area is the Simpson's Rule:

Area ≈ h/3 ( y_0 + y_n + 4 * Σ( y_k, k, 1, n-1, 2) + 2 * Σ( y_k, k, 2, n-2, 2) )

The program presented here uses the Trapezoid Rule. 

HP Prime Program AREAHGT

Two arguments:  h, a list of measurements

EXPORT AREAHGT(h, ms)
BEGIN
// h:  increment between measurements
// ms: list of measurements
// 2019-05-09 EWS
LOCAL k,n:=SIZE(ms);
RETURN h/2 * (ms(1) + ms(n) + 2 * Σ( ms(k), k, 2, n-1 ));
END;

HP 17BII+ (Silver)/HP 17BII Solver:  Trapezoid Rule

First:  define a SUM list named MS.  The solver uses that list to get the reference measurements.

Solver:

AREAHGT: AREA = 0 * L(N:SIZES(MS)) + H÷2 * (ITEM(MS:1) + ITEM(MS:G(N)) + 2 * Σ(K:2: G(N)-1: 1: ITEM(MS:K) )

Example

h = 0.5

MS:
y_1 = 1174
y_2 = 1078
y_3 = 979
y_4 = 984
y_5 = 810
y_6 = 779
y_7 = 800
y_8 = 852
y_9 = 966

Area:  3676

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.

Tuesday, March 26, 2019

HP 17BII and HP 27S: Quadratic Formula

HP 17BII and HP 27S:  Quadratic Formula


The following solver equations solve the quadratic equation

A*x^2 + B*x + C = 0

by the famous Quadratic Formula

x = (-B ± √(B^2 - 4*A*C) ) / (2*A)

Define D as the discriminant:  D = B^2 - 4*A*C

If A, B, and C are real numbers and:

D<0, the roots are complex conjugates

D≥0, the roots are real roots

Quadratic Equation:  Real Roots Only

QUAD:X=INV(2*A)*(-B+SQRT(B^2-4*A*C)*SGN(R#))

Input Variables:
A:  coefficient of X^2
B:  coefficient of X
C:  constant
R#:  -1 or 1

Output Variables: 
X:  root

Example:  2X^2 + 3X - 5 = 0

Input:
A: 2
B: 3
C: -5
R#: 1 (or any positive number)

Output:
X = 1

Input:
R#: -1

Output:
X = -2.5

Quadratic Equation:  Real or Complex Roots
(Let (L) and Get (G) functions required)

QUAD:0*(A+B+C+L(D:B^2-4*A*C)+L(E:2*A))
+IF(S(X1):IF(D<0:-B÷G(E):(-B+SQRT(D))÷G(E))-X1:0)
+IF(S(X2):IF(D<0:SQRT(ABS(D))÷G(E):(-B-SQRT(D))÷G(E))-X2:0)

 Input Variables:
A:  coefficient of X^2
B:  coefficient of X
C:  constant

Output Variables:
D:  Discriminant 
If D<0:  X1:  real part, X2:  imaginary part
If D≥0:  X1:  real root 1, X2:  real root 2

Example 1:  -3*X^2 + 8*X - 1= 0

Input:
A: -3
B: 8
C: -1

Output:
D = 52
X1 = 0.1315
X2 = 2.5352

Roots:  x = 0.1315, x = 2.5352

Example 2:  3*X^2 + 5*X + 3 = 0

Input: 
A: 3
B: 5
C: 3

Output:
D = -11
X1 = -0.8333
X2 = 0.5528

Roots:  x = -0.8333 ± 0.5528i

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. 

Sunday, March 24, 2019

HP 17BII and HP 17BII+: Finance Solver Equations

HP 17BII and HP 17BII+:  Sales Tax, Substantial Presence Test, Automobile Purchase, Principal Interest Property Tax & Insurance (PITI), Retirement Accounts

Note:  Some equations have the L (Let) and G (Get) functions, which are not available on the brown keyboard of the 17BII+ (around 2003). 

Sales Tax:  Determine the total amount of taxable items and non-taxable items.

AMT=NTAX+TXBL*(1+R%÷100)

AMT:  Total Amount
NTAX:  Items not subject to sales tax
TXBL:  Items subject to sales tax
R%:  sales tax rate

Example 1:  A company purchases equipment which costs $99.99, which was subject to 9.5% sales tax, which includes $139.99 of services.  The services are not subject to sales tax.  What is the total invoice? 

Input:
NTAX:  139.99
TXBL: 99.99
R%:  9.5(%)

Output:
AMT = 249.48

The total of the invoice is $249.48.

Example 2:  During an audit, a company finds an invoice with the total of $236.40 (amount), and the invoice listed non-taxable services of $146.50.  The company lives in a county where the sales tax is 8.75%.  What is the amount of taxable items? 

Input:
NTAX:  146.50
R%:  8.75(%)
AMT:  236.40

Output:
TXBL = 82.67

The amount of taxable items on the invoice is $82.67.

Substantial Presence Test

For more information about the substantial presence test, please click here:  http://edspi31415.blogspot.com/search?q=substantial+presence+

This equation uses Let and Get. 

SPT=IF(L(X:DDAYS(D:12.31+FP(100*D)÷100:1)>183:DATE(D:183):DATE(1.01+(FP(100*D)+.0001)÷100:IP(183-G(X)÷3)))

STP:  Number of days calculated for the Substantial Presence Test
D:  Date (in the format DD.MMYYYY)

Example 1:

D:  1.052019 (1/5/2019),  SPT = 7.072019 (7/7/2019)

Example 2:

D:  6.182008 (6/18/2008), SPT = 12.182008 (12/18/2008)

Example 3:

D:  9.262018 (9/26/2018), SPT = 6.012019 (6/1/2019)

Example 4:

D:  7.102017 (7/10/2017), SPT = 5.062018 (5/6/2018)

Financing the Purchase of an Automobile

This equation deals with the purchase of an automobile. 

AUTO:PRICE*(1-DISC%*.01)*(1+STAX%*.01)-DOWN=PMT*USPV(I%÷12:YRS*12)

PRICE: Sticker price of the automobile
DISC%:  Discount percent
STAX%: Sales tax rate
DOWN:  Down payment (amount)
PMT:  Payment of the loan
I%:  Interest rate of the loan
YRS: Number of years of the loan

Example 1:  The sticker price of a car is $28,000.00.  A discount of 15% is offered.  The car is subject to 10% sales tax.  The dealer offers a 6-year loan at 4.5%.  With $2,000, what is the monthly payment?

Input: 
PRICE: 28000.00
DISC%: 15
STAX%:  10
DOWN: 2000
I%:  4.5
YRS: 6

Output:
PMT = 383.83

The monthly payment is $383.83. 

Example 2:  Assuming the same facts from Example 1, expect the buyer wants to pay no more than $350.00 a month.  What is the required down payment?

Input: 
PRICE: 28000.00
DISC%: 15
STAX%:  10
I%:  4.5
YRS: 6
PMT: 350.00

Output:
DOWN = 4131.42

The down payment needs to be $4,131.42.

Real Estate:  Principal Interest Property Tax & Insurance (PITI)

Determine the total payment of mortgage when considering property tax and property insurance. 

PITI=MORT÷USPV(I%÷12:YRS*12)+(PROP$+INS$)÷12

PITI:  Payment including principal, interest, property tax, and insurance
MORT:  Mortgage amount, price of the property
I%:  Annual interest rate
YRS: Number of the years of the mortgage
PROP$:  Annual property tax
INS$:  Annual property insurance

Example:  A buyer purchases a home with a price of $200,000.00.  The amount is to be financed.  The loan lasts for 30 years and 5% interest rate.  There is annual property tax of $1,200.00 with insurance of $395.95.  What is the buyer's PITI?

Input:
MORT: 200000.00
I%:  5
YRS: 30
PROP$:  1200.00
INS$:  395.95

Output:
PITI = 1206.64

The buyer's PITI is $1,206.64. 

Retirement Accounts:  Future Value and Earned Untaxed Dividends

Determine the future value and untaxed dividends of tax-free retirement accounts (IRS/Keogh).

There are two versions, the second uses Let (L) and Get (G) functions.

Version 1:
IRA: VAL*0+DIV*0+IF(S(VAL):USFV(I%:YRS)*PMT*(1+I%÷100)-VAL:0)+IF(S(DIV):(USFV(I%:YRS)*(1+I%÷100)-YRS)*PMT-DIV:0)

Version 2:
IRA:(VAL+DIV+L(X:USFV(i%:YRS)*(1+I%÷100)))*0+IF(S(VAL):G(X)*PMT-VAL:(G(X)-YRS)*PMT-DIV)

Input Variables:
I%:  Annual Interest Rate
YRS:  Number of Years
PMT:  Annual Payment

Output Variables:
VAL:  Tax Free Value of the Retirement Account
DIV:  Total Untaxed Dividends Earned

Remember, these are untaxed amounts.

Example:
I%:  6.88
PMT:  1000.00
YRS: 40

Output (Results):
VAL = 206811.01
DIV = 166881.01

Source:
Tony Hutchins, Luiz Vieria, and Gene Wright "HP 12C Platinum Solutions Handbook"  Hewlett Packard.  Revised 03.04  2004

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.

Tuesday, July 18, 2017

Expanding Linear Regression

Expanding Linear Regression


Introduction – Linear Regression

All scientific calculators that have two-variable dimensions has curve fitting.  The most (and universal) curve fitting mode is linear regression.   Linear regression attempts to model bivariate data ((x,y)) to a line by the equation:

y = a + bx

Where a is the y-intercept (ITC) and b is the slope (SLP).  The correlation coefficient, r, is calculated by:

r = SXY / √(SX2 * SY2) where
SX2 = Σ(x – μx)^2
SY2 = Σ(y – μy)^2
SXY = Σ( (x – μx)*(y – μy) )
μx = mean of x values, μy = mean of y values

Source:  HP 17B II Financial Calculator Owner’s Manual, Corvallis, OR  1989.

The best fits are were |r| = 1, or as close to 1 as we can get.  If r is close to 0, the first is not good.  Note that the formula for correlation does not involve the slope or intercept.  We can use this to our advantage.

“Linearize” the Equation

If you can “linearize” equation, we can use the linear regression mode to fit a variety of curves.  The ultimate goal is of course:

y = a + bx

Now, most calculators use the form for linear equations.  However, some switch the a and b around and use the form, like the TI-30X IIS, 

y = ax + b

Hewlett Packard calculators has the b for the intercept and m for slope. 

For clarity, I will use the form Y = ITC + SLP*X. 

  
Calculator Comparison

To demonstrate how we can use the linear regression to fit a variety of curves, I use two calculators:



Sharp EL-W516T which offers 7 regressions.

TI-30X IIS which offers just linear regression.  I use the TI-30X IIS to use the linearized form.

[screen shot of the calcs] 

Sharp EL-W516T
TI-30X IIS
SLP
B
a
ITC
A
b
Linear Regression Equation
y = a + bx
y = ax + b

Screen shots are generated from a Casio fx-CG50. 


Logarithmic Regression:  y = a + b ln x



Translation to Linear:  This is pretty simple, we already have the form that we need, except we note that we have ln x instead of x.  Set the following variables as such:

X = ln x, Y = y, a = ITC, b = SLP

Example data set:
x
y
X = ln x  (8 decimal places)
1.0
2.00
0
1.3
3.00
0.2623643
1.7
4.15
0.5306283
2.3
5.34
0.8329091
2.8
6.10
1.0296194
3.5
7.00
1.252763

To use the linear regression mode, enter the data as such:  (ln x, y).  Everything else remains the same.

Logarithmic Regression Results:
ITC = a = 1.990614146
SLP = b = 4.003372076
r = 0.99905634

Comparing results between using the Logarithmic regression with the Sharp EL-W516T and the Linear regression with the TI-30X IIS, I get the same results.




Exponential Regression:  y  = a*e^(b*x)



Translation to linear: 

y = a*e^(b*x)
ln y = ln (a*e^(b*x))
ln y = ln a + ln(e^(b*x))
ln y = ln a + b*x

We got our form of Y = ITC + SLP*X where:
X = x, Y = ln y, a = e^ITC, b = SLP

When using the linear regression mode, enter data as (x, ln y).  When calculating a, note that

ITC = ln a
e^ITC = a

Example data set:
X
y
Y = ln y  (8 decimal places)
1.0
109.2
4.693181
1.3
363.0
5.8944028
1.7
1795.6
7.4930945
2.3
19794.3
9.8931493
2.8
146260.8
11.893147
3.5
2405208.5
14.693147

Results:
ITC = 0.693829923;  a = 2.001365951
SLP = b = 3.99773169
r = 0.999999992

Inverse Regression: y = a + b/x



Translation to Linear:  Like logarithmic regression, we pretty much have the equation pretty much set, with the exception of 1/x instead of x.  Hence:

X = 1/x, Y = y, a = ITC, b = SLP


 When using the linear regression mode, enter data as (1/x, y). Everything else remains.

Example data set:
X
y
X = 1/x  (8 decimal places)
1.0
6.00
1
1.3
5.55
0.7692308
1.7
5.16
0.5882353
2.3
4.86
0.4347826
2.8
4.73
0.3571429
3.5
4.58
0.2857143

Results:
a = ITC = 4.005529472
b = SLP = 1.993191341
r = 0.999733184

Power Regression:  y = a*x^b



Translation to Linear:  X = ln x, Y = ln y, A = e^a, b

y = a*x^b
ln y = ln (a*x^b)
ln y = ln a + ln(x^b)
ln y = ln a + b * ln x

So we have the following: X = ln x, Y = ln y, ITC = ln a, SLP = b.

In the linear regression mode, enter data as (ln x, ln y). Also, a = e^ITC. 

Example data set:
x
y
X = ln x
Y = ln y
1.0
3.95
0
1.3737156
1.3
6.76
0.2623643
1.9110229
1.7
11.56
0.5306283
2.4475509
2.3
21.09
0.8329091
3.048799
2.8
31.40
1.0296194
3.4468079
3.5
49.00
1.252763
3.8918203

Results:
ITC = 1.379195052; a = e^ITC = 3.971703326
SLP = b = 2.007158681
CORR = r = 0.999991481
   

Table of Linear Regression Equivalents to Curve Fitting


Regression

X

Y

ITC

SLP

Logarithmic: y = a + b * ln x

ln x

y

a

b

Exponential: y = a*e^(b*x)

x

ln y

e^a

b

Inverse: y = a + b/x

1/x

y

a

b

Power: y = a*x^b

ln x

ln y

e^a

b

General Exponential: y = a * b^x

x

ln y

e^a

e^b

Simple Logistic: y = 1/(a + b*e^(-x))

e^(-x)

1/y

a

b

Square Root Linear: y = √(a + b*x)

x

y^2

a

b

Cosine: y = a + b*cos(ω(x – ϕ))

With

ϕ = the point (x) nearest to zero where the trough or peak begins

ω = (2*π)/period (radians) or

ω = 360°/period (degrees)

cos(ω(x – ϕ))

y

a

b


Eddie


This blog is property of Edward Shore, 2016

RPN HP 12C: Fibonacci and Lucas Sequences

  RPN HP 12C: Fibonacci and Lucas Sequences Golden Ratio, Formulas, and Sequences Let φ be the Golden Ratio: φ = (1 + √5) ÷ 2...