## Monday, July 15, 2024

### Firmware Updates: Numworks and HP Prime

Firmware Updates:   Numworks and HP Prime

Good morning.  Just a quick update:

Numworks:   Version 23.

Highlights:  Derivatives, Search Interval for Solving Equations

HP Prime:  Firmware 15008 (Beta)

Highlights:  Memory leak fixes, STRING fixes, Greek letters are now case-sensitive, Copying a value with nested exponents doesn't rearrange parenthesis

Take care,

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, July 13, 2024

### TI-84 Plus CE and Casio fx-CG 50: Mean Squared Error

TI-84 Plus CE and Casio fx-CG 50: Mean Squared Error

Introduction

The mean square error computes the mean distance from observed (y) versus predicted (y’) values. With the n data points, the standard formula for mean squared error (MSE) is calculated as:

MSE = 1 / n * Σ((y_i – y’_i)^2 for i=1 to n)

Where:

n = number of data points

y = observed points

y’ = predicted points. Any regression can be used, but the linear regression is typically used (y = a + b * x).

When MSE is small, (as closed to zero as possible), the better the data fits the regression curve. MSE is sensitive to how much data points stray from the regression line. [see Source]

TI-84 Plus CE Program: MSE

How to retrieve the statistical variables and the apostrophe character:

a: [ vars ], 5, [ → ], [ → ], 2

b: [ vars ], 5, [ → ], [ → ], 3

n: [ vars ], ,5 ,1

‘: [ 2nd ] [ apps ] <angle>, 2

Lists used:

L1 = x data

L2 = y data

L3 = y’ (predicted y) data

Casio fx-CG 50

The Casio fx-CG 50 (and other modern Casio graphing calculators such as the fx-9750GIII/9860GIII) has a MSe variable (Mean Square Error) included in the statistics variables. However, Casio’s calculation of Mse vary depending on the regression model selected. For the linear regression mode, Mse is calculated with the following formula:

Mse = 1 / (n – 2) * Σ((y_i – y’_i)^2 for i=1 to n)

Apparently the are different approaches.

.

Examples (with the Presented Formula)

Linear Regression is assumed (y = a + b * x, a = y-intercept, b = slope). Results are shown using the MSE program (TI-84 Plus CE).

Set 1:

 L1 = x L2 = y 1 1.035 2 1.076 3 1.112 4 1.400 5 1.558 6 1.827

a: 0.7652666667

b: 0.1626857143

MSE: 0.0066101841

Set 2:

 L1 = x L2 = y 40 385 41 349 40 376 41 358 39 333 38 326 39 371 40 350

a: 22.1

b: 8.4

MSE: 306.85

Source

Encord. “Mean Square Error”. Encord Computer Vision Glossary. 2023. Retrieved May 25, 2024. https://encord.com/glossary/mean-square-error-mse/

Next post: Saturday, July 20, 2024

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, July 7, 2024

### Numworks: Drawing Simple Shapes with Pyplot

Numworks: Drawing Simple Shapes with Pyplot

Welcome to a special edition of our blog.

The goal of today’s blog is provide templates to draw simple shapes such as ellipses, circles, rectangles, squares, equilateral triangles, and 45-45-90 right triangles. Adjust the position, screen size, and colors as you see fit.

The module is used is pyplot.

Ellipses and Circles with drawellipse.py

Draw an ellipse given the length of x and y radii. If x and y are equal, a circle is drawn. The screen is set up to fit the proportion of the 320 x 220 screen. The vertical axis ranges from y = -44 to y = 44 while the horizontal axis ranges from x = -64 to x = 64. The ellipse is centered at (0,0).

Numworks script: https://my.numworks.com/python/ews31415/drawellipse

Script: drawellipse.py

from math import *
from matplotlib.pyplot import *

print("Draw an ellipse\nusing pyplot")
a=eval(input("x axis? "))
b=eval(input("y axis? "))

# set axis
axis((-64,64,-44,44))

# set points
tl=[i/128*2*pi for i in range(129)]
xl=[a*cos(i) for i in tl]
yl=[b*sin(i) for i in tl]

# draw the ellipse
c='purple'
plot(xl,yl,c)
show()

Rectangles and Squares with drawrect.py

Draw a rectangle given its horizontal length (h) and vertical length (v). If the horizontal and vertical lengths are equal, a square is drawn. The rectangle is centered at (0, 0). The screen is set up to fit the proportion of the 320 x 220 screen. The vertical axis ranges from y = -44 to y = 44 while the horizontal axis ranges from x = -64 to x = 64.

Numworks script: https://my.numworks.com/python/ews31415/drawrect

Script: drawrect.py

from math import *
from matplotlib.pyplot import *

print("Draw a rectangle\nusing pyplot")
h=eval(input("horiz. length? "))
v=eval(input("vert. length? "))

# set axis
axis((-64,64,-44,44))

# set points
xl=[-h/2,h/2,h/2,-h/2,-h/2]
yl=[v/2,v/2,-v/2,-v/2,v/2]

# color
c='green'

# draw rectangle
plot(xl,yl,c)
show()

Equilateral Triangles with drawtrieq.py

Draws an equilateral (60-60-60) triangle. Enter the length of the side (s). The base is set on the x-axis. The screen is set up to fit the proportion of the 320 x 220 screen. The vertical axis ranges from y = -44 to y = 44 while the horizontal axis ranges from x = -64 to x = 64.

Numworks script: https://my.numworks.com/python/ews31415/drawtrieq

Script: drawtrieq.py

from math import *
from matplotlib.pyplot import *

print("Draw an equilateral triangle\nusing pyplot")
s=eval(input("side length? "))

# set axis
axis((-64,64,-44,44))

# set points
t=s*sqrt(3)/2
xl=[-s/2,s/2,0,-s/2]
yl=[0,0,t,0]

# draw the triangle
c='brown'
plot(xl,yl,c)
show()

45-45-90 Degree Right Triangles with drawtrit.py

Draws an 45-45-90 degree right triangle. Enter the length of the one of the legs (s), not the hypotenuse. The base is set on the x-axis. The screen is set up to fit the proportion of the 320 x 220 screen. The vertical axis ranges from y = -44 to y = 44 while the horizontal axis ranges from x = -64 to x = 64.

Numworks Script: https://my.numworks.com/python/ews31415/drawtrirt

Script: drawtrit.py

from math import *
from matplotlib.pyplot import *

print("Draw a 45-45-90 triangle\nusing pyplot")
s=eval(input("short length? "))

# set axis
axis((-64,64,-44,44))

# set points
xl=[-s/2,s/2,-s/2,-s/2]
yl=[0,0,s,0]

# draw the triangle
c='blue'
plot(xl,yl,c)
show()

Enjoy and I hope you find these scripts useful in your drawing scripts.

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, July 6, 2024

### HP 12C: Hyperbolic Sine and Cosine, and their Inverses

HP 12C: Hyperbolic Sine and Cosine, and their Inverses

Introduction

The following program calculates four hyperbolic functions:

sinh x = (e^x – e^(-x)) / 2

cosh x = (e^x + e^(-x)) / 2

arcsinh x = ln(x + √(x^2 + 1))

arccosh x = ln(x + √(x^2 - 1)) (principal arccosh x)

HP 12C Program: sinh x, cosh x, arcsinh x, arccosh x

Step #: Step Code: [ keys ]

# sinh x: GTO 01, R/S

01: __, 43, 22: [ g ] e^x

02: __, 43, 36: [ g ] LST x

03: __, __, 16: [ CHS ]

04: __, 43, 22: [ g ] e^x

05: __, __, 30: [ - ]

06: __, __, _2: [ 2 ]

07: __, __, 10: [ ÷ ]

08: 43, 33, 00: [ g ] GTO 00

# cosh x: GTO 09, R/S

09: __, 43, 22: [ g ] e^x

10: __, 43, 36: [ g ] LST x

11: __, __, 16: [ CHS ]

12: __, 43, 22: [ g ] e^x

13: __, __, 40: [ + ]

14: __, __, _2: [ 2 ]

15: __, __, 10: [ ÷ ]

16: 43, 33, 00: [ g ] GTO 00

# arcsinh x: GTO 17, R/S

17: __, __, 36: [ ENTER ]

18: __, __, 36: [ ENTER ]

19: __, __, _2: [ 2 ]

20: __, __, 21: [ y^x ]

21: __, __, _1: [ 1 ]

22: __, __, 40: [ + ]

23: __, 43, 21: [ √ ]

24: __, __, 40: [ + ]

25: __, 43, 23: [ g ] LN

26: 43, 33, 00: [ g ] GTO 00

# arccosh x: GTO 27 R/S

27: __, __, 36: [ ENTER ]

28: __, __, 36: [ ENTER ]

29: __, __, _2: [ 2 ]

30: __, __, 21: [ y^x ]

31: __, __, _1: [ 1 ]

32: __, __, 30: [ - ]

33: __, 43, 21: [ √ ]

34: __, __, 40: [ + ]

35: __, 43, 23: [ g ] LN

36: 43, 33, 00: [ g ] GTO 00

Instructions

1. Enter x

2. To calculate, press [ g ] GTO ##, then press [ R/S ].

* GTO 01 R/S: sinh x

* GTO 09 R/S: cosh x

* GTO 17 R/S: arcsinh x

* GTO 27 R/S: arccosh x

Examples

(Fix 4)

 x sinh x cosh x -0.64 -0.6846 1.2119 0.59 0.6248 1.1792 1.23 1.5645 1.8568 3.74 21.0371 21.0609

Note: arccosh(1.2119) returns 0.64

Source

Selby, Samuel M. Ph. D. Sc. D. CRC Standard Mathematics Tables: Nineteenth Edition. The Chemical Rubber Co. Cleveland, OH. 1971. pp. 202, 211

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

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)

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

If min(Y) ≤ 0, then:

Q = min(Y) -1

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!

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

 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

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.

### Firmware Updates: Numworks and HP Prime

Firmware Updates:   Numworks and HP Prime Good morning.  Just a quick update: Numworks:   Version 23.   Highlights:  Derivatives, Search Int...