Saturday, June 29, 2024

TI 30Xa Algorithms: Solving Monic Quadratic Polynomials Quickly

 TI 30Xa Algorithms: Solving Monic Quadratic Polynomials Quickly


We all know about the tried and true Quadratic Formula to solve quadratic equations. However, it is not the only way to tackle such problems.



Today’s blog is covers a way to quickly get the roots of the quadratic equation:


x^2 + p * x + q = 0


I am focusing on monic quadratic polynomials today. A polynomial is a monic polynomial if the leading coefficient is 1. In this instance, the coefficient of the x^2 term is 1. I’m also going to work with quadratic equations that have real roots.



Deviation


Please see the source article as the derivation and method is explained by the author Po-Shen Loh (https://www.poshenloh.com/quadraticdetail/). This method has also been developed by Viete and other classic mathematicians. Here I attempt to explain a derivation of this method.


Let r1 and r2 be the two roots of the polynomial and x^2 + p * x + q factors to:

x^2 + p * x + q = (x – r1) * (x – r2)


Expanding (x – r1) * (x – r2):

(x – r1) * (x – r2) = x^2 + (-r1 -r2) * x + r1 * r2


Then:

p = - r1 – r2 ⇒ r1 + r2 = -p

q = r1 * r2


Let one of the roots be defined as: [see Source]

r1 = -p/2 + u

Then:

r1 + r2 = -p

-p/2 + u + r2 = -p

r2 = -p/2 + u


And:

r1 * r2 = q

(-p/2 + u) * (-p/2 - u) = q

p^2/4 – u^2 = q

- u^2 = q – p^2/4

u^2 = p^2/4 – q

u = ±√(p^2/4 – q)


And the roots are:

r1 = -p/2 + √(p^2/4 – q)

r2 = -p/2 - √(p^2/4 – q)


x = -p/2 ± u


Note:

r1 = -p/2 + u

r1 – 2 * u = -p/2 + u – 2 * u

r1 – 2 * u = -p/2 – u

r1 – 2* u = r2



We can verify the above result with the quadratic equation:


x = (-p ± √( p^2 – 4 * q)) / 2

x = -p/2 ± √( p^2 – 4 * q) / 2

x = -p/2 ± √(( p^2 – 4 * q) / 4)

x = -p/2 ± √(( p^2/4 – q)

x = -p/2 ± u




TI-30Xa Algorithm: Quadratic Equation


Assumption: The roots are real (not complex).


Keystrokes:

p [ STO ] 1

q [ STO ] 2

[ ( ] [ RCL ] 1 [ x^2 ] [ ÷ ] 4 [ - ] [ RCL ] 2 [ ) ] [ √ ] (u)

[ - ] [ RCL ] 1 [ ÷ ] 2 [ = ] (r1, root 1)

[ ± ] [ - ] [ RCL ] 1 [ = ] (r2, root 2)


Memory registers used: M1 = p, M2 = q


Examples


Example 1: x^2 – 3*x – 4 = 0


p = -3, r = -4


3 [ ± ] [ STO ] 1

4 [ ± ] [ STO ] 2

[ ( ] [ RCL ] 1 [ x^2 ] [ ÷ ] 4 [ - ] [ RCL ] 2 [ ) ] [ √ ] (u = 2.5)

[ - ] [ RCL ] 1 [ ÷ ] 2 [ = ] (root 1, x = 4)

[ ± ] [ - ] [ RCL ] 1 [ = ] (root 2, x = -1)


x = 4, -1


Example 2: x^2 – 24*x + 135 = 0

p = -24, r = 135


24 [ ± ] [ STO ] 1

135 [ STO ] 2

[ ( ] [ RCL ] 1 [ x^2 ] [ ÷ ] 4 [ - ] [ RCL ] 2 [ ) ] [ √ ] (u = 3)

[ - ] [ RCL ] 1 [ ÷ ] 2 [ = ] (root 1, x = 15)

[ ± ] [ - ] [ RCL ] 1 [ = ] (root 2, x = 9)


x = 15, 9


Example 3: x^2 + 10*x + 24 = 0

p = 10, r = 24

10 [ STO ] 1

24 [ STO ] 2

[ ( ] [ RCL ] 1 [ x^2 ] [ ÷ ] 4 [ - ] [ RCL ] 2 [ ) ] [ √ ] (u = 1)

[ - ] [ RCL ] 1 [ ÷ ] 2 [ = ] (root 1, x = -4)

[ ± ] [ - ] [ RCL ] 1 [ = ] (root 2, x = -6)


x = -4, -6



Source


Loh, Po-Shen. “Quadratic Method: Detailed Explanation” Updated August 6, 2021. Retrieved May 19, 2024. https://www.poshenloh.com/quadraticdetail/


Until next time, have a great day. For the Americans, have a safe and sane Fourth of July. See you July 6!


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 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.

Swiss Micros DM41X and Casio fx-CG 50: Minor Head Loss

Swiss Micros   DM41X and Casio fx-CG 50: Minor Head Loss Introduction When a fluid, such as water, is flowing in a pipe system, ene...