Saturday, June 22, 2024

Curve Fitting: Adjusting Data Points (feat. HP 14B and HP Prime)

 Curve Fitting: Adjusting Data Points


Graphs are generated with the HP Prime emulator software.



A Curve Fitting Problem


Problem:


We have an investment project, which at the beginning will cost us 50,000 (insert the currency of your choice). Through analysis, the projected cash flows at the beginning of each term are shown here:



Period (beginning of)

Cash Flow

1

-50000

2

-3000

3

9000

4

16000

5

18000

6

21000


What is the projected cash flow at the beginning of period 7?


We could easily use linear regression, but the problem is, the data itself does not easily fit a line. So we can just use another regression model and that’s simple, right? Not quite, since two of the cash flows are negative.


Approach


Most calculators have at least the following curve fitting regressions:


Model

Transformed

X’ =

Y’ =

True B =

Linear

Y = B + M * X

Y = B + M * X

X

Y

B

Exponential

Y = B * exp(M *X)

ln(Y) = ln(B) + M * X

X

ln(Y)

exp(B)

Logarithmic

Y = B + M * ln(X)

Y = B + M * ln(X)

ln(X)

Y

B

Power

Y = B * X^M

ln(Y) = ln(B) + M * ln(X)

ln(X)

ln(Y)

exp(B)


A lot of them rely on a transition of data to use a translated linear regression model. After the parameters slope (M) and y-intercept (B) are calculated, any adjustments are made to find the correct curve fitting parameters.


The statistical calculations operate on real numbers. If we try to fit an exponential, logarithmic, or power fit on data with non-positive numbers, we are going to have a problem because the natural logarithmic function returns non-real numbers in the transition process.


Still the data does not fit a linear regression line as good as the other regression curves. This calls for an adjustment of data. In essence, we are going to subtract out the minimum value of either the x or y data, or both “minus one”. Conceptually:


If min(X) ≤ 0, then:

P = min(X) -1

X_adj = X – P


If min(Y) ≤ 0, then:

Q = min(Y) -1

Y_adj = Y – Q


Why the “minus 1”?


If we only subtract the minimum, the lowest adjust amount would be 0. But ln(0) approaches negative infinity, which most calculators would not work with.


If we subtract the minimum minus one, the lowest adjusted amount would be 1. ln(1) =0. Beautiful!


Example: Adjusting the Raw Data


Raw data:

X

Y

1

-50000

2

-3000

3

9000

4

16000

5

18000

6

21000


min(X) = 1 > 0. No adjustment is needed.

min(Y) = -50000 ≤ 0. An adjustment is needed.


Let Q = min(Y) – 1 = -50000 – 1 = -50001


Adjusted data:


X

Y

Y’ = Y – Q

ln(Y’) (fix 3)

1

-50000

1

0

2

-3000

47001

10.758

3

9000

59001

10.985

4

16000

66001

11.097

5

18000

68001

11.127

6

21000

71001

11.170


Let’s fit the adjusted curve.


Keep in mind that:


Y’ = Y – Q

Y’ = Y - -50001

Y’ = Y + 50001

Y = Y’ – 50001





Fitting the Curve


Determine which one of the four regressions: linear, exponential, logarithmic, or power bets fits the adjusted data points. Predict the actual revenue (Y) for period 7.


Here is the data. We are going to use the data sets X and Y’.



X

Y

Y’ = Y – Q , (Q = -50001)

1

-50000

1

2

-3000

47001

3

9000

59001

4

16000

66001

5

18000

68001

6

21000

71001


Correlation Coefficients:


Model

Correlation (fix 4)

Linear

0.8477

Exponential

0.6772

Logarithmic

0.9520

Power

0.8290


Calculations were made with a HP 14B calculator. The best fit has absolute value of the correlation closest to 1. Correlations near -1 or +1 are better than correlations near 0.


The best fit is the logarithmic fit. Hence the curve fit is:


Y’ ≈ 9618.6378 + 38498.9034 * ln(X)





Remember that Y’ = Y + 50001. Then:


Y + 50001 ≈ 9618.6378 + 38498.9034 * ln(X)

Y ≈ -40382.3262 + 38498.9034 * ln(X)


To predict for X = 7:

Y ≈ -40382.3262 + 38498.9034 * ln(7)

Y ≈ 34533.0807


The beginning of period 7 will have the project cash flow of about $34,533.



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.

Saturday, June 15, 2024

Calculated Industries Qualifier Plus IIIFx: Logarithm, Exponential, Square Root

Calculated Industries Qualifier Plus IIIFx: Logarithm, Exponential, Square Root



Introduction


Say we have a financial calculator such as Calculated Industries Qualifier Plus IIIFx (or the Pocket Real Estate Master or another pocket basic financial calculator). Note that this calculator does not have the following functions: natural logarithm (ln x), exponential function (e^x), and square root (√). No problem. We can use the time value of money keys.


The relationship between present value (PV), future value (FV), periodic interest rate (I%), and number of periods (N) is determined as:


FV = PV * (1 + I% / 100) ^ N


For the natural logarithm and exponential, start by dividing both sides by PV:


FV / PV = (1 + I% / 100) ^ N


Let PV = 1 and equate 1 + I% / 100 = e (e ≈ 2.71828182846…)


Then:

1 + I% / 100 = 2.71828182846

I% / 100 = 1.71828182846

I% = 171.828182846


Since financial calculators are usually set to 2 decimal places, for most instances, we can use the approximation with reasonable accuracy:


I% ≈ 171.82818



Then we have:


FV / 1 = (1 + 171.82818 / 100) ^ N →


FV ≈ e^N and ln FV ≈ N


Now for square root:


Let’s start with the same basic relationship:


FV / PV = (1 + I% / 100) ^ N


Let PV = 1, and N be 0.5 since √x is x^0.5 for x≥0.


Let x = 1 + I% / 100. Solving for I%:


x = 1 + I% / 100

x – 1 = I% / 100

100 * (x – 1) = I%


FV ≈ √x

FV / 1 = ((100 * (x – 1)) ^ 0.5


We can use this to build similar relationships with powers and roots.






Procedures and Examples


Procedure for ln(x):

Set the following variables:

P/Y = 1

Loan Amt = 1*

Int = 171.82818

FV = x

Solve for Term


Estimate ln 55.5.


P/Y = 1

Loan Amt = 1*

Int = 171.82818

FV = 55.5

Solve for Term


Result (Term): 4.02


Procedure for e^x:

P/Y = 1

Loan Amt = 1*

Int = 171.82818

Term = x

Solve for FV.


Estimate e^2.


P/Y = 1

Loan Amt = 1

Int = 171.82818

Term = 2

Solve for FV


Result (FV): 7.39



Procedure for √x:

P/Y = 1

Loan Amt = 1*

Term = 0.5

Int = 100 * (x – 1)

Solve for FV


Example: Estimate √84.


P/Y = 1

Loan Amt = 1

Term = 0.5

Int = 100 * (84 – 1) = 8300

Solve for FV


Result (FV): 9.17


*Note: Loan Amt (PV) is entered as -1 on graphing calculator TVM solvers.



Note: Please do not try this on the HP 12C or the BA Plus II, because on those calculators, the variable N is rounded up to the near highest integer.


Enjoy this hack and until next time,


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.

Saturday, June 8, 2024

Casio fx-4000P - The Programs I took on Vacation

 Casio fx-4000P - The Programs I took on Vacation


I was on vacation in Atascadero last May 2024 at a car conference with my partner. I may not have classic cars, but I do have classic calculators. Here the programs I took with me in Casio fx-4000P.
I also took my HP 45 with me as well.


Total: 448 bytes out of 550 bytes ( ^ => x^y)


Prog 0: Quadratic Equation: Po Shen way: x^2 + B * x + C = 0, built for real roots (39 steps)


“ B “ : ? → B : “C” : ? → C : B² ÷ 4 – C → W ◢ -B ÷ 2 - √W ◢ Ans + 2 × √W


Prog 1: Law of Cosines - Side Z (45 steps)


Deg : “X” : ? → X : “Y” : ? → Y : “C” : ? → C : X² + Y² – 2 × X × Y × cos C : √Ans → Z


Prog 2: Law of Cosines - Angle C (49 steps)


Deg : “X” : ? → X : “Y” : ? → Y : “Z” : ? → Z : ( X² + Y² – Z² ) ÷ ( 2 × X × Y ) : cos^-1 Ans → C


Prog 3: Area of Triangle – Heron’s Formula (55 steps)


X” : ?→X : “Y” : ?→Y : “Z” : ?→Z : (X + Y + Z) ÷ 2→S : √( S×(S – X)×(S – Y)×(S – Z))


Prog 4: Speed of Sound in Dry Air (53 steps)

All constants, γ, R, M are taken care of in the formula, T = temp in °F

Conversions: 1 m/s = 2.236936 mph, 20.04503702 * 2.236936 = 44.83946493


T “ : ?→T : 5÷9 × (T – 32) + 273.15 : 20.04503702 * √Ans : 2.236936 * Ans → S


Prog 5: Horizontal Curve Analysis Given Central Angle and Radius (52 steps)

I = central angle, R = radius, L = arc length, C = chord length


Deg : “I” : ?→I : “R” : ?→R : “L=” ◢ Ï€×R×I ÷ 180 → L ◢ “C=” ◢ 2×R× sin(I ÷ 2) → C


Prog 6: D = Displacement of a Cylinder (in) (36 steps)

B = bore (in), S = stroke (in), N = number of cylinders


“B” : ? → B : “S” : ? → S : “N” : ? → N : Ï€ × B² × S × N ÷ 4 → D


Prog 7: Tire Size (in) (36 steps)

S = section width (mm), A = aspect ratio, R = rim diameter (S, A, R → )


“S” : ? → S : “A” : ? → A : “R” : ? → R : S × A ÷ 1270 + R → T


Prog 8: Air Pressure for height up to 36,089 ft above sea level (inHg) (45 steps)

This is with constants already completed (g, M, R, etc.)


H” : ?→H : 29.92126 × (1 - 6.875 × 10^-6 × H) x^y 5.255876329 → P


Prog 9: Breaking Distance in Feet Given the Car’s Velocity in Miles Per Hour (35 steps)


V” : ? → V : V × 22 ÷ 15 : Ans × 1.5 + Ans² ÷ 45.04367 → D


Source:

“Breaking Distance” Wikipedia. Last Edited March 30, 2024. Accessed April 29, 2024.

https://en.wikipedia.org/wiki/Braking_distance


Hagberg Media AB. “Stopping distance = reca2tion distance + breaking distance” 2024.

Accessed April 29, 2024. https://korkortonline.se/en/theory/reaction-braking-stopping/


Just for fun,

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.


Saturday, June 1, 2024

Order of Operations: The Pesky Math Problem from the Internet [ 6 ÷ 2(1 + 2) ]

Order of Operations: The Pesky Math Problem from the Internet



Perhaps the World’s Most Problematic Math Problem


You’ve seen this, we all seen this, it’s the math problems that’s put all calculators in jeopardy, it’s the dreaded:


6 ÷ 2(1 + 2)


Is it 1 or is it 9? No matter what we answer, the debate still rages on and on. Why? Because not everyone agrees with the order of operations. And the problem lies with implied multiplication.


Seeing that this issues comes up multiple times of the HP Museum of Calculators (latest can be seen at [Source 5]), it’s time to input my two dollars into the subject. (It was two cents but the price went up due to inflation.)



What is Implied Multiplication?


Implied multiplication occurs when two or more quantities, often with or without a numeric coefficient, are combined with one or more variables without explicit multiplication symbols (*, ⋅, or ×). It is implied that when this notation is used, the quantities are to be added.


Examples:


xy is implied to mean x * y


2x is implied to mean 2 * x


3rs is implied to mean 3 * r * s


If there are two or more quantities and at least one of them is surrounded by parenthesis, this is also implied multiplication.


Examples:


The following are implied to mean 2 * 6:

2(6)

(2)6

(2)(6)


4(x)y is implied to mean 4 * x * y.


Implied multiplication is also known as juxtaposition. [Source 2]


Infix multiplication is multiplication with symbols (*, ⋅, or ×).


Where is implied multiplication in the order of operations?


PEMDAS vs PEJMDAS


PEMDAS and PEJMDAS are the two major order of operations.


In PEMDAS, also known as BODMAS in some parts of the world, put implied multiplication (juxtaposition) on the same level as infix multiplication and division. The video by The How and Why of Mathematics serves an excellent video to explain the difference and the potential problems that can be encountered. [Source 1]



PEMDAS


PEMDAS stands for:

P: parenthesis

E: exponents (and roots) (one-argument functions such as sin, int, abs and log are included)

MD: all multiplication and division, left to right

AS: all addition and subtraction, left to right


Similarly, BODMAS stands for:

B: brackets (serves as the same function as parenthesis)

O: operations (exponents, roots, one-argument functions such as sin, int, abs, and log)

DM: all division and multiplication, left to right

AS: all addition and subtraction, left to right


For this blog post, I will refer to this sequence as PEMDAS.


PEJMDAS


PEJMDAS moves implied multiplication to a higher priority:

P: parenthesis

E: exponents (and roots) (one-argument functions such as sin, int, abs and log are included)

J: multiplication by juxtaposition (implied multiplication), left to right

MD: infix multiplication and division, left to right

AS: all addition and subtraction, left to right


Examples


Problem 1: 48 / 2 * 3


PEMDAS:

48 / 2 * 3

24 * 3

72


PEJMDAS:

48 / 2 * 3

24 * 3

72


Here there is no difference because the multiplication is infix.


Problem 2: 48 / 2 (3)


PEMDAS:

48 / 2 (3)

24 (3)

72


PEJMDAS:

48 / 2 (3)

48 / 6

8


Notice in PEJMDAS the implicit multiplication, as marked by two numbers juxtaposed next to each other separated by parenthesis, takes priority.


Problem 3: 100 – 5 (2 + 3)


PEMDAS:

100 – 5 (2 + 3)

100 – 5 (5)

100 – 25

75


PEJMDAS:

100 – 5 (2 + 3)

100 – 5 (5)

100 – 25

75


Here we arrive at the same problem because subtraction has the lower priority than implication in both cases.


Problem 4: 100 / 5 (2 + 3)


PEMDAS:

100 / 5 (2 + 3)

100 / 5 (5)

20 (5)

100


PEJMDAS:

100 / 5 (2 + 3)

100 / 5 (5)

100 / 25

4


In PEJDMAS, implied multiplication has priority over division.



Conclusion – Which Method Reigns Supreme? Should we Even use Implied Multiplication?


I’m not usually a fan of the phrase “pick a lane”, but for the sake of consistency, I’ll make an exception. I would prefer the world to pick either PEMDAS or PEJMDAS and stick to it as a universal rule. It seems like PEJMDAS might get the favor since more mathematicians, scientists, and professionals prefer it. I view the PEMDAS vs PEMJDAS as similar to the way the world views which are the standard scientific units:


PEMDAS: ft, sec lbs (United States, especially in the education field)

PEJMDAS: m, sec, kg


Having grown up in the United States, it will take me a bit to adjust to PEJMDAS from PEDMAS.


I’m also in favor of just using additional multiplication, parenthesis, and perhaps using a fraction bar to make problems much clearer. To borrow a suggestion from Tony Barlow, a mathematician who tested the ill-fated never-released TI-88:


“Kill Implied Multiplication. Kill Implied Multiplication. Kill Implied Multiplication.” [2]


Disallowing implied multiplication allows us to avoid two potential problems:


1. In calculators with CAS capabilities and in Python, we are allowed variable names with more than one character (rate, chg, pts). If implied multiplication is allowed with variable names with more than one character, and “ratepts” is typed, do I mean “rate * pts”, the entire variable “ratepts”, or something else like “r * a * t * e * p * t * s”?


2. This makes it clear when we mean function calls, which thankfully is usually understood. But to someone who is unfamiliar with functions, something like “sin(x)” may mean “sin * x” or “ s * I * n * x” to them. “f(x)” may be misinterpreted as “f * x”.


Calculators with the classic AOS (algebraic operating system, postfix system), RPN (Reverse Polish Notation), or Chain operation do not deal with implied multiplication:


AOS: In all cases, the multiplication and parenthesis keys must be explicitly pressed. (Examples: TI-30 series, Casio fx-260 series)


RPN: RPN is a parenthesis-less operating system. (Examples: Almost all HP calculators, all Swiss Micros calculators)


Chain: Everything entered in the Chain operating system is done how you enter the keys. Therefore, these calculators don’t even deal with the order of operations, accuracy is completely up to you. (Examples: all basic four-function calculators)


I hope you find this blog entry helpful, and hopefully one day, we have a universal solution.



This is not the only issue with the order of operations, another issue is where to place the unary operator of negation, but that’s for another day.


Eddie


Sources


[1]

The How and Why of Mathematics. “The Problem with PEMDAS: Why Calculators Disagree” August 5, 2019. Accessed April 15, 2024. Video. https://www.youtube.com/watch?v=4x-BcYCiKCk


[2]

Wright, Gene. “HHC 2022: TI-88 Part 1: History and Go / No Go Decision” September 14, 2022. Accessed April 15, 2024. https://www.youtube.com/watch?v=wl16wzmn3wA Video. (Refer to time stamp 13:24).


[3]

“Multiplication” Wikipedia. Edited April 17, 2024. Accessed April 21, 2024. https://en.wikipedia.org/wiki/Multiplication


[4]

“Order of Operations” Wikipedia. Edited April 19, 2024. Accessed April 19, 2024. https://en.wikipedia.org/wiki/Order_of_operations


[5]

“What is the correct result?” Museum of HP Calculators. Thread started on March 18, 2024. https://www.hpmuseum.org/forum/thread-21474.html



Next Post: June 8, 2024



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.

HP 71B Basic and Casio fx-CG 100: Weighted Random Sample

HP 71B Basic and Casio fx-CG 100: Weighted Random Sample Introduction In calculators, it is fairly easy to generate a rand...