Saturday, July 20, 2024

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, energy is lost from the flow due to friction. This loss is known as head loss. The equation presented here is an equation to determine head loss occurring in pipe bends and joints (entrances and exits), which is categorized as minor loss. Minor losses are typically summarized with major losses to determine total head loss.


A formula for minor head loss is stated as:


h = C * v^2 / (2 * g)


where:

h = head loss (m)

C = coefficient

v = velocity of the fluid (m/s)

g = Earth’s gravity = 9.80665 m/s^2 (2 * g = 19.6133 m/s^2)

C = head loss coefficient (see table below)


Type # for C

Value

1. Sharp Exit

1

2. Protruding Entrance

0.8

3. Sharp Entrance

0.5

4. Round Entrance

0.1


If we fit the above table like so:


Type # for C

Value

1

1

2

0.8

3

0.5

4

0.1


Fortunately, the data above (and only the data above) can fit into the quadratic equation:

y = -0.05 * x^2 – 0.05 * x + 1.1 = -0.05 * (x^2 + x) + 1.1


where x is the type number and y is the corresponding coefficient. The assignment of type numbers is arbitrarily.


In the code for the DM41X, I use the polynomial to grab the required coefficient of the user’s choice, mapping choice 1 to C =1 for sharp exit, mapping choice 2 to C = 0.8 for protruding entrance, and so on. I got really lucky because the quadratic equation presented a perfect fit (r^2 = 1). In programming it can serve as alternative way to retrieve coefficient values (but the fit has to be perfect or near perfect with minor adjustments).



Swiss Micros DM41X Code: HEADLOS

(HP 41C compatible, no modules needed)


01 LBL^T HEADLOS

02 LBL 00

03 ^T SHARP EXIT

04 AVIEW

05 PSE

06 PSE

07 ^T PROTRUDING

08 AVIEW

09 PSE

10 PSE

11 ^T 3 SHARP ENT.

12 AVIEW

13 PSE

14 PSE

15 ^T 4 ROUND ENT.

16 AVIEW

17 PSE

18 PSE

19 ^T TYPE?

20 PROMPT

21 INT

22 STO 00 (comparison: reject if the entry is negative or greater than 5)

23 X<=0?

24 GTO 00

25 5

26 X<=Y?

27 GTO 00

28 RCL 00

29 X↑2

30 RCL 00

31 +

32 -20

33 /

34 1.1

35 +

36 ^T VEL. <M/S>?

37 PROMPT

38 X↑2

39 *

40 19.6133

41 /

42 ^T HEAD LOSS=

43 ARCL X

44 RTN

45 END


Casio fx-CG 50 Program HEADLOSS


Menu “TYPE”, “SHARP EXIT”, 1, “PROTRUDING”, 2, “SHARP ENTRANCE”, 3, “ROUND ENTRANCE”, 4

Lbl 1: 1 → C: Goto 5

Lbl 2: 0.8 → C: Goto 5

Lbl 3: 0.5 → C: Goto 5

Lbl 4: 0.1 → C: Goto 5

Lbl 5

“VELOCITY (M _| S)”? → V ( _| is the fraction character [ []/[] ] )

C × V² ÷ 19.6133 → H

“HEAD LOSS:”

H


Example


For the velocity, v = 10.5 ft/s ≈ 3.2004 m/s:


Type

Head Loss (h)

1. Sharp Exit

0.5222

2. Protruding Entrance

0.4178

3. Sharp Entrance

0.2611

4. Round Entrance

0.0522



Sources


Ajmera, Benna. “Engineering Formulas” Quick Study Academic. BarCharts, Inc. 2014


“Minor Losses in Pipes and Ducts“ Ansys. 2020. https://courses.ansys.com/wp-content/uploads/2020/09/Lesson-4-Minor-Losses-in-Pipes-and-Ducts-Handout.pdf Retrieved June 6, 2024.



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.

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

More information:  https://www.numworks.com/calculator/update/version-23/


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

More information:  https://www.hpmuseum.org/forum/thread-22020.html



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


Download the program here: https://drive.google.com/file/d/1toVMgznJOGdaK4uhvfrcvvb3t__D9yJD/view?usp=drive_link


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




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.

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