Saturday, April 13, 2024

HP Prime: Hagen-Poiseuille Law

HP Prime: Hagen-Poiseuille Law


The Hagen-Poiseuille Law relates flow of water with the change in pressure in the pipe:


Q = K × D^4 × ΔP / (μ × L) where:


K = constant = π / 128 (dependent on the pipe’s diameter)

D = diameter of the pipe (in m)

L = length of the pipe (in m)

ΔP = change in pressure (in Pa)

Q = flow rate (in m^3/s)

μ = viscosity of water (Pa a)



Short Table of Viscosity of Water


Temperature

Viscosity of Water (mPa s)

5 °C (41 °F)

1.5182

10 °C (50 °F)

1.3059

15 °C (59 °F)

1.1375

20 °C (68 °F)

1.0016

25 °C (77 °F)

0.89

30 °C (86 °F)

0.7972


Note that 1 Pa s = 1,000 mPa s


The program references the above table for certain temperatures. The program asks for temperature in degrees Celsius (°C). If any other temperature is entered, the empirical formula known as the Vogel-Fulcher-Tammann Equation is used:


μ = 0.02939 × e^( 507.88 K ÷ (T K – 149.3 K))

= 0.02939 × e^( 507.88 K ÷ ((T °C + 273.15) K – 149.3 K))

= 0.02939 × e^( 507.88 ÷ (T + 123.85))


Equations


Calculating flow:

Q = (π × D^4 × ΔP)/(128 × μ × L)



Calculating Pressure Change:

ΔP = Q × μ × L × 128/(D^4 × π)


HP Prime Code: Hagen-Poiseuille Law


EXPORT HAGEN()

BEGIN

// 2024-02-22 EWS



// local variables

LOCAL ch1;

LOCAL u,t,d,l,p,q;

LOCAL t1,t2,t3;



// list of temps

t1:={"5°C","10°C","15°C",

"20°C","25°C","30°C","Other"};

t2:={1.5182,1.3059,1.1375,

1.0016,0.89,0.7972};

t3:={5,10,15,20,25,30};

// inputs

INPUT({{t,t1},d,l,{ch1,{"ΔPressure",

"Flow Rate"}}},

"Hagen-Poisuelle Law",

{"t:","d:","l:","Solve for:"},

{"Temp of water (ºC)","Pipe Diameter (m)",

"Pipe Length (m)"});



// temp to viscosity

// from table

IF t≤6 THEN

u:=t2(t)/1000;

t:=t3(t);

ELSE

// empirical formula

INPUT(t,"Enter temp in °C","t:");

u:=0.02939*e^(507.88/(t+123.85))/1000;

END;



PRINT();

PRINT("RESULTS:");

PRINT("Temperature: "+STRING(t)+" °C");

PRINT("Viscosity = "+STRING(1000*u)+" mPa s");



// solve for pressure

IF ch1==1 THEN

INPUT(q,"Enter flow rate","q:","m^3/s");

p:=q*u*l*128/(d^4*π);

PRINT("ΔPressure = "+STRING(p)+" Pa");

RETURN {t,u,p};

END;



// solve for flow rate

IF ch1==2 THEN

INPUT(p,"ΔPressure:","Δp:","Pa");

q:=(π*d^4*p)/(128*u*l);

PRINT("Flow Rate = "+STRING(q)+" m^3/s");

RETURN {t,u,q};

END;

END;



Examples


Example 1:

Temp = t = 20°C

Flow = q = 0.5 m^3/s

Solve for Δp

Results:

Viscosity = μ = 1.0016 mPa s

Pressure Change = Δp = 199.261988751 Pa


Example 2:

Temp = t = 10°C

Pressure Change = Δp = 150 Pa

Result:

Viscosity = μ = 1.3059 mPa s

Flow = q = 0.28868299137 m^3/s


Example 3:

Temp = t = 33°C

Flow = q = 0.36 m^3/s

Solve for Δp

Results:

Viscosity = μ = 0.748935277403 mPa s

Pressure Change = Δp = 107.277076309 Pa



Sources


Lauga, Eric. Fluid Mechanics: A Very Short Introduction. Oxford University Press: Oxford, UK 2022. pp. 36-37


“Fluid of Viscosity” Wikipedia. https://en.wikipedia.org/wiki/Viscosity Retrieved February 5, 2024.


“Viscosity of Liquids and Gases” and “Viscosity of Water” HyperPhysics. http://hyperphysics.phy-astr.gsu.edu/hbase/Tables/viscosity.html Retrieved February 8, 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.

Thursday, April 11, 2024

Numworks Updates

Numworks Updates


Apologies that I have not done anything with Numworks in what seems to be forever. 


The current official software is Version 22:

*  Polar and algebraic form of complex numbers are displayed in the expanded results in Calculator mode

* Chi-Square test added to the Inference app

*  Better navigation of the Elements (Periodic Table) app

*  The toolbox button also can escape the toolbox without selecting a command or function


More information:

https://www.numworks.com/calculator/update/version-22/


Version 23 is in beta stage and some the intended offerings are:

*  1st and 2nd Derivative Plots in the Grapher app

*  f' and f'' notation for derivative

* Change in notion of polar and parametric functions, also become accessible in the variables menu

* Python:  The distance function becomes available Turtle module 


More information:

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


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

Swiss Micros SM32: Simulating a Choose Menu

Swiss Micros SM32: Simulating a Choose Menu


The following technique should work for the HP 33S and HP 35S, but most likely HP 32S/32SII due to the lack of memory (you could shorten or eliminate the messages, I suppose.).


What Is Needed


  • We will need at least two labels.
  • The user flags as needed. For the DM32, the user flags are from Flag 0 to Flag 4. This allows for up to five choices.
  • A choice variable. This variable holds the user’s choice from the menu. The algorithm presumes that the user will always enter a valid choice.
  • Clever calculation, as we start with the reference value in the X stack.
  • Flag 10, which allows us to display the choices and messages.



General Algorithm Format


LBL 1 (run the algorithm here)

CF 0 through CF 4 (as needed)

SF 10 ( [ |→ ] {FLAGS} {SF} [ . ] 0 )

“introduction message” (if desired)

PSE (follow each string with a pause)



LBL 2 (menu and main calculation)

“#a (description)”

PSE

“#b (description)”

PSE

INPUT CV (choice variable)


RCL CV

#a

x=y?

Value_a


RCL CV

#b

x=y?

INPUT α


STO α (store a reference value for future use)


(calculation)


CF 0, CF 1, CF 2, CF 3, CF 4 (clear all flags used)

CF 10

“RESULT =“ (if desired)

PSE (if desired)

VIEW (variable with result)

GTO (Lbl 1) or RTN


Notes: 

  • #a, #b, … corresponding flags, 0 – 4.
  • CV: choice variables (i.e. C, H, etc.)
  • α: reference value used
  • Choice #b demonstrates how we can allow the user to input their own value.


Entering Strings


Setting Flag 10 turns equation evaluation off. Now each typed “equation” now acts as a string. Enter strings by:


1. Pressing the right shift key [ |→ ], or the blue shift key on the DM32, then [ ST0 ] { EQN }.

2. Letters are entered by pressing [ RCL ] { letter }. Numbers can be entered as well. The equals key is entered by pressing [ |→ ]/[ blue shift ] [ ← ] { = }. The screen is 12 characters long before it scrolls. Note: We do not have the period or the question mark as available characters.

3. Press [ ENTER ] to go on to the next line.



Choice Variable


The choice variable is a pointer to the reference value. There is a one-on-one correspondence between the choice value and the reference value.


For example, say H is the choice variable and reference values are assigned as follows:


H = Choice Variable

Reference Value

1

13.5

2

14.7

3

16.1

If the user selects option 1, then 13.5 is placed on the X stack ready for calculation.

If the user selects option 2, then 14.7 is placed on the X stack ready for calculation.

If the user selects option 3, then 16.1 is placed on the X stack ready for calculation.



Example: Impedance of Transmission Lines


The characteristic impedance of transmission lines of a coaxial line is:


Z = K / √ε × log( D / L ) where:


K = √μ0 / (2 × π × √ε0 × log e) ≈ 138.059528959

D = inner diameter of outer conductor

L = outer diameter of inner conductor

ε = relative permittivity of dielectric medium (E)


The program give us three choices for the dielectric medium:


Material/Choice Variable ( C )

ε

1: Polythene (Flag 1)

2.3

2: Plexiglass (Flag 2)

3.2

3: Your Own (Flag 3)

Enter the ε of the material of your choice at the E? prompt


K is a constant that consists of the following scientific constants:


Vacuum Permeability

μ0 = 1.566370614 × 10^-6 H/m


Vacuum Permittivity

ε0 = 8.854187817 × 10^-12 F/m


Values are taken from the HP Prime, Software Version 2.1.14730 (2023 04 13).


SM32 Code

(Note: This should work on both the HP 33S and HP 35S; and the HP 35S can contain all the code in one label with the correct GTO commands)


// comment


// main program and initialization

T01 LBL T

T02 CF 1

T03 CF 2

T04 CF 3

T05 SF 10

T06 “TRANS-LINE IMP”

T07 PSE


// menu and calculation

M01 LBL M

M02 “REL PERMIT”

M03 PSE

M04 “1 POLYTHENE”

M05 PSE

M06 “2 PLEXIGLASS”

M07 PSE

M08 “3 YOUR OWN”

M09 PSE

M10 INPUT C


// set the flag based on the choice variable

M11 RCL C

M12 1

M13 x=y?

M14 SF 1


M15 RCL C

M16 2

M17 x=y?

M18 SF 2


M19 RCL C

M20 3

M21 x=y?

M22 SF 3


// enter reference value based on choice variable

M23 FS? 1

M24 2.3


M25 FS? 2

M26 3.2


M27 FS? 3

M28 INPUT E

M29 STO E


// calculation

M30 SQRT

M31 1/x

M32 138.059528959

M33 ×

M34 INNER DIAM

M35 PSE

M36 INPUT D

M37 OUTER DIAM

M38 PSE

M39 INPUT L

M40 ÷

M41 LOG

M42 ×

M43 STO Z


// clean up: clear all the flags for the next calculation

M44 CF 1

M45 CF 2

M46 CF 3

M47 CF 10

M48 VIEW Z

M49 STOP

// press R/S to do another problem

M50 GTO T




Examples

Let D = 0.68 in and L = 0.195 in.


Choice 1: Polythene. Resistance: 49.3835 Ω

Choice 2: Plexiglass. Resistance: 41.8669 Ω

Choice 3: ε = 1.95. Resistance: 53.6325 Ω



Source

Hewlett-Packard Company. HP-46 sample applications. Loveland, CO. February 1,1975. Part No. 00046-90018. pg. 26



Hope you find this useful,

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

Radius and Apothem of Regular Polygons

Radius and Apothem of Regular Polygons


On this blog, let’s calculate the lengths of a regular polygon’s radius, apothem, and area knowing only the side length and internal angle.



A regular polygon is a polygon in which every side has an equal length, and every internal angle is equal.


Let x be the length of one side of the regular polygon, and θ be the internal angle of the polygon where:


θ = (n – 2) / n × 180°




The radius (r) of the regular polygon is a line segment from a vertex to the center of the polygon. The radius bisects the vertex, therefore cutting the internal angle in half.

The apothem (a) is a line segment from the center of the polygon to the center of the polygon’s line segment. If we extend the apothem beyond the border, the apothem splits the length of the side segment in half.

Zooming in, a right triangle is formed between the radius, apothem, and half of the polygon line segment.


By trigonometry:


tan (θ / 2) = a / (x / 2)

a = (x / 2) × tan (θ / 2)


and


cos (θ / 2) = (x / 2) ÷ r

r = x / (2 × cos (θ / 2))


Knowing the apothem, the area of the regular polygon is:


area = perimeter × a / 2


where the perimeter = n × x


Then:


area = (n × x) × a / 2

= 1 / 2 × n × x × a

= 1 / 2 × n × x × (x / 2 × tan(θ / 2))

= 1 / 4 × n × x^2 × tan(θ / 2)



Another Formula for an Area’s Regular Polygons


The area of a regular polygon is often stated as:


area = 1 / 4 × n × x^2 / (tan (180° / n)) = 1 / 4 × n × x^2 × cot (180° / n))


We can show that the two formulas for area are equivalent:


Note that:

θ = (n – 2) / n × 180°

θ = 180° - 360° / n

Divide both sides by 2:

θ / 2 = 90° - 180° / n

180° / n = 90° - θ / 2 [ I ]




Observe that the trigonometric identity, for any angle α:

tan(90° - α) = 1 / tan(α) = cot(α)

and

cot(90° - α) = 1 / cot(α) = tan(α) [ II ]


Then:

area = 1 / 4 × n × x^2 × tan(θ / 2)

= 1 / 4 × n × x^2 × cot(90° - θ / 2) [ II ]

= 1 / 4 × n × x^2 × cot(180° / n) [ I ]

= 1 / 4 × n × x^2 / tan(180° / n) [ I ]


In Summary:

Internal Angle: θ = (n – 2) / 2 × 180°

Apothem: a = (x / 2) × tan (θ / 2)

Radius: r = x / (2 × cos (θ / 2))

Area = 1 / 4 × n × x^2 × tan(θ / 2) = 1 / 4 × n × x^2 / tan(180° / n)

(Note: 180° = π radians)



Table of Apothem and Radius, with side length of 1


n

θ (in degrees)

θ / 2 (in degrees)

a (to 5 decimal places)

r (to 5 decimal places)

3

60

30

0.28868

0.57735

4

90

45

0.5

0.70711

6

120

60

0.86603

1

8

135

67.5

1.20711

1.30656

12

150

75

1.86603

1.93185


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, March 31, 2024

TI-30Xa Algorithms: Linear Regression

 TI-30Xa Algorithms: Linear Regression


Welcome to the March 2024 installment of TI-30Xa Algorithms.



Linear Regression with a TI-30Xa?


Today’s task is to fit bi-variate data to the line:


y = m * x + b


with the TI-30Xa. What? This calculator does not have a linear regression mode. Yes, with it is possible. We are going to use the technique shown in by the TI-36 Solar Guidebook from 1985 (see Source below). The TI-36 Solar was part of Texas Instruments’ line in the late 1980s and the early 1990s.


You can read my review on the TI-36 Solar from September 26, 2020 here:

https://edspi31415.blogspot.com/2020/09/retro-review-ti-36-solar.html


Where the TI-36 Solar only had one memory register, the TI-30Xa has three memory registers, and they are going to come in handy here.



Procedure


Caution: Be sure the calculator is on the entire time. Turning off the calculator will clear out statistics mode.


1. Enter the y data. Store the mean (y-bar) into memory register 2. Store the population deviation (σy) into memory register 3.


Keystrokes:

Mean of y-data: [ 2nd ] [ x^2 ] {x-bar} [ STO ] [ 2 ]

Population of y-data: [ 2nd ] [ ÷ ] { σxn } [ STO ] [ 3 ]


2. Clear the stat registers and enter the x data. As we are entering the x data, use memory register 1 to calculate Σxy.


Keystrokes:


Clear Stat Registers: [ 2nd ] [ 7 ] {CSR}


1st Point:

x1 [ × ] y1 [ = ] [ STO ] [ 1 ]

x1 [ Σ+ ]


Every point there after:

x_i [ × ] y_i [ = ] [ 2nd ] [ RCL ] {SUM} [ 1 ]

x_i [ Σ+ ]



3. Calculate the slope, and replace Σxy with the slope.


m = ( y-bar * Σx – Σxy) / ( x-bar * Σx - Σx^2)


Keystrokes:

[ ( ] [ RCL ] [ 2 ] [ × ] [ 2nd ] [ ( ] [ - ] [ RCL ] [ 1 ] [ ) ]

[ ÷ ] [ ( ] [ 2nd ] [ x^2 ] [ × ] [ 2nd ] [ ( ] [ - ] [ 2nd ] [ ) ] [ = ] [ STO ] [ 1 ]


4. Calculate the y-intercept, replace y-bar with the y-intercept.


b = -m * x-bar + y-bar


Keystrokes:

[ RCL ] [ 1 ] [ +/- ] [ × ] [ 2nd ] [ x^2 ] [ + ] [ RCL ] [ 2 ] [ = ] [ STO ] [ 2 ]


5. Calculate the correlation. If the correlation is close to -1 or +1, the linear fit will be excellent.


r = m * σx / σy


Keystrokes:

[ RCL ] [ 1 ] [ × ] [ 2nd ] [ ÷ ] [ ÷ ] [ RCL ] [ 3 ] [ = ]


6. Use slope (m) and intercept (b) to predict x and y values:


y’ = m * x0 + b

Keystrokes: [ RCL ] [ 1 ] [ × ] x0 [ + ] [ RCL ] [ 2 ] [ = ]


x’ = (y0 – b) / m

Keystrokes: [ ( ] y0 [ - ] [ RCL ] [ 2 ] [ ) ] [ ÷ ] [ RCL ] [ 1 ] [ = ]


Key Map


[ RCL ] [ 1 ]: first Σxy, then m

[ RCL ] [ 2 ]: first y-bar, then b

[ RCL ] [ 3 ]: σy

[ 2nd ] [ x^2 ]: x-bar

[ 2nd ] [ ÷ ]: σxn



Example


Fit a line to the data:


X

Y

12

100

13

98.7

14

97.1

16

94.9

18

92.6

20

90



1. Enter the y data. Store the mean (y-bar) into memory register 2. Store the population deviation (σy) into memory register 3.


100 [ Σ+ ]

98.7 [ Σ+ ]

97.1 [ Σ+ ]

94.9 [ Σ+ ]

92.6 [ Σ+ ]

90 [ Σ+ ] (display n = 6)



Mean of y-data: [ 2nd ] [ x^2 ] [ STO ] [ 2 ] (y-bar = 95.55)


Population of y-data: [ 2nd ] [ ÷ ] [ STO ] [ 3 ] (σy = 3.465424457)



2. Clear the stat registers and enter the x data. As we are entering the x data, use memory register 1 to calculate Σxy.


Keystrokes:


Clear Stat Registers: [ 2nd ] [ 7 ] {CSR}


12 [ × ] 100 [ = ] [ STO ] [ 1 ]

12 [ Σ+ ]


13 [ × ] 98.7 [ = ] [ 2nd ] [ RCL ] [ 1 ] (SUM 1)

13 [ Σ+ ]


14 [ × ] 97.1 [ = ] [ 2nd ] [ RCL ] [ 1 ] (SUM 1)

14 [ Σ+ ]


16 [ × ] 94.9 [ = ] [ 2nd ] [ RCL ] [ 1 ] (SUM 1)

16 [ Σ+ ]


18 [ × ] 92.6 [ = ] [ 2nd ] [ RCL ] [ 1 ] (SUM 1)

18 [ Σ+ ]


20 [ × ] 90 [ = ] [ 2nd ] [ RCL ] [ 1 ] (SUM 1)

20 [ Σ+ ]


RCL 1: Σxy = 8827.7

[ 2nd ] [ x^2 ]: x-bar = 15.5



3. Calculate the slope, and replace Σxy with the slope.


[ ( ] [ RCL ] [ 2 ] [ × ] [ 2nd ] [ ( ] [ - ] [ RCL ] [ 1 ] [ ) ]

[ ÷ ] [ ( ] [ 2nd ] [ x^2 ] [ × ] [ 2nd ] [ ( ] [ - ] [ 2nd ] [ ) ] [ = ] [ STO ] [ 1 ]


Slope: m = -1.230526316


4. Calculate the y-intercept, replace y-bar with the y-intercept.


[ RCL ] [ 1 ] [ +/- ] [ × ] [ 2nd ] [ x^2 ] [ + ] [ RCL ] [ 2 ] [ = ] [ STO ] [ 2 ]


Intercept: b = 114.6231579


5. Calculate the correlation.


[ RCL ] [ 1 ] [ × ] [ 2nd ] [ ÷ ] [ ÷ ] [ RCL ] [ 3 ] [ = ]


Correlation: r = -0.999092386


The line is:


y = -1.230526316 * x + 114.6231579



6. Predict values.


If x = 15, predict the y value (y’):


[ RCL ] [ 1 ] [ × ] x0 [ + ] [ RCL ] [ 2 ] [ = ]

y’ = 96.16526316


If y = 95, predict the x value (x’):


[ ( ] y0 [ - ] [ RCL ] [ 2 ] [ ) ] [ ÷ ] [ RCL ] [ 1 ] [ = ]

x’ = 15.94696322



Source


Alley, Chris M., Brenda M. Cornitius, et al. TI-36 Solar Guidebook Texas Instruments Incorporated. Dallas, TX. 1985, 1986, 1987. pp. 4.6 – 4.13



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.

Trigonometry Reduction Formula and Solving Simple Arcsine and Arccosine Equations

Trigonometry Reduction Formula and Solving Simple Arcsine and Arccosine Equations Some Background and Periodic Reduction Formulas ...