Sunday, April 23, 2017

HP Prime and TI-84 Plus CE: Shallow Wave Analysis

HP Prime and TI-84 Plus CE:  Shallow Wave Analysis

Introduction



The program H2OWAVES calculates wave speed, impedance, and wave flux for shallow ocean waves.  The following are assumed:

1. The criteria of λ < D/20 is assumed where λ is the length of the wave.
2. The water assumed to be 0°C, where the density (ρ) is 1,000 kg/m. 
3. SI units are used.  For gravity, g = 9.80665 m/s^2 is used.

Formulas Used

Wave Speed (m/s):  v = √(g * D)
Wave Impedance (Mks):  Z = ρ * v
Wave Energy Flux (W/m):  I = (ρ * g * H)^2/(2 * Z)
Maximum Possible Length (m):  λ = 20 * D

HP Prime Program H2OWAVES

EXPORT H2OWAVES()
BEGIN
// EWS 2017-04-21
// Shallow Wave Analysis
// for D/L<1/20
// SI Units

LOCAL D,H;
LOCAL v,Z,I;

INPUT({D,H},
"Wave Analysis",
{"D: ","H: "},
{"Depth (m)","Wave Height (m)"});

v:=√(9.80665*D);
Z:=1000*v;
I:=(9806.65*H)^2/(2*Z);

PRINT();
PRINT("Wave speed (m/s): "+v);
PRINT("Impedance (Mks): "+Z);
PRINT("Wave Flux (W/m): "+I);

RETURN {v,Z,I};

END;

TI-84 Plus CE Program H2OWAVES

"EWS 2017-04-23"
"SHALLOW WAVES"
"D<F/20"
Disp "SHALLOW WAVES"
Input "DEPTH (M): ",D
Input "HEIGHT (M): ",H
√(9.80665*D)→V
1000*V→Z
(9806.65*H)^2/(2*Z)→I
Disp "WAVE SPEED (M/S):",V
Disp "IMPEDANCE (WKS):",Z
Disp "WAVE FLUX (W/M):",I

Example

Input: 
Depth:  3.2 m
Height:  0.49 m

Output:
Wave Speed: 5.601899678 m/s
Impedance:  5601.899678 Wks
Wave Flux:  2060.953478 W/m

Source:

Ingard, K.U. Fundamental of Waves and Oscillations Cambridge University Press:  New York 1988.  IBSN 0 521 32734

Surf’s up!  Eddie


This blog is property of Edward Shore, 2017.

Wednesday, April 19, 2017

HP Prime and TI-84 Plus CE: Simple Logistic Regression

HP Prime and TI-84 Plus CE:  Simple Logistic Regression

The program SIMPLOGI attempts to fit two lists of data (X, Y) to the equation:

y = 1 / (A + B*e^(-x))

by using the translation:  X’ = e^-X and Y’ = 1/Y and performing linear regression analysis on X’ and Y’.   This is good for all data except when y = 0.

HP Prime Program SIMPLOGI

EXPORT SIMPLOGI(L1,L2)
BEGIN
// EWS 2017-04-18

LOCAL S:=SIZE(L1);
LOCAL L0:=MAKELIST(1,X,1,S);
L1:=e^(−L1);
L2:=1/L2;

LOCAL M1,M2,M3;
M1:=list2mat(CONCAT(L0,L1),S);
M1:=TRN(M1);
M2:=list2mat(L2,S);
M2:=TRN(M2);
M3:=CAS.LSQ(M1,M2);


RETURN {"Y=1/(A+Be^(−X))",M3};

END;

TI-84 Plus CE Program SIMPLOGI

Disp "LOGISTIC FIT"
Disp "Y=1/(A+B*e^(­X))"
Input "X: ",L
e^(­L)→L
Input "Y: ",L
1/L→L
LinReg(a+bx) L,L
Disp "A=",a
Disp "B=",b

Example

Data:  (X’ and Y’ are provided for reference)

X
Y
X’ = e^(-X)
Y’ = 1/Y
0.5
0.384
0.6065306597
2.604166667
1.0
0.422
0.3678794412
2.369668246
1.5
0.450
0.2231301601
2.222222222
2.0
0.468
0.1353352832
2.136752137
2.5
0.480
0.0820849986
2.083333333

X = {0.5, 1, 1.5, 2, 2.5}, Y = {0.384, 0.422, 0.45, 0.468, 048}

Results (Matrix [ [ A ]. [B ] ]):

A = 2.00185929
B = 0.9942654005

Hence y = 1 / (2.00185929 + 0.9942654005*e^(-x))

Eddie



This blog is property of Edward Shore, 2017

Wednesday, April 12, 2017

Approximating y = sin x (0 to 90 degrees, 0 to pi/2 radians)



Approximating y = sin x (0 to 90 degrees, 0 to pi/2 radians)


Calculation

I used the HP Prime to fit polynomials to data by using the vandermonde and LSQ commands.

vandermonde(vector):  creates the matrix consisting of rows [ 1, (n_i), (n_i)^2, (n_i)^3, …, (n_i)^(n-1) ] where the vector has n elements for each i.  Available from the Math-Matrix-Create submenu.

LSQ(X, y):  returns the coefficients [ [a_0], [a_1], [a_2], … , [a_n] ], the minimum norm least squares vector from the system X*a=y.  In this case, the vector a can also be estimated by the operation (X^T X)^-1 X^T y.  Available from the Math-Matrix-Factorize submenu.

Case 1:  Four Points of Data

Fit cubic polynomial to the following data.  Remember we are working with the range of 0° ≤ x ≤ 90° or 0 ≤ x ≤ π/2 radians

X
sin(x)
0
30°
1/2 = 0.5
60°
√3/2 ≈ 0.866025403785
90°
1

Example 1:  Full precision approximation

y = 1.78098409219E-2 x – 1.99435471445E-5 x^2 – 6.05408712068E-7 x^3

Note:  E-n stands for 10^(-n).

Absolute maximum error, data measured in 5° tick marks:  0.002371558429
Absolute maximum error, data measured in 1° tick marks:  0.002392465593



Example 2:  If we round all coefficients to six digits, we get:

y = 0.017810 x – 0.000020 x^2 – 0.000001 x^3

Absolute maximum error, data measured in 5° tick marks:  0.2881 

In comparison between Example 1 and Example 2, keeping the decimal places makes a big difference. 



Example 3:  Let’s see if we do better with using radians instead of degrees.

X
sin(x)
0
0
π/6
1/2 = 0.5
π/3
√3/2 ≈ 0.866025403785
π/2
1

y = 1.02042871863 x – 0.065470803224 x^2 – 0.113871899065 x^3

Maximum absolute error, data measured in π/36 radian tick marks: 0.002371558428
Maximum absolute error, data measured in π/180 radian tick marks: 0.002392465661

The maximum error in Example 3 matched Example 1.

Example 4:  Round the coefficients to six digits:

y = 1.020429 x – 0.065471 x^2 – 0.113872 x^3

Maximum absolute error, data measured in π/36 radian tick marks:  0.002371292924
(2 decimal places)

The difference between Example 2 and Example 4 is that less information is “lost” when rounding the coefficients to a set amount of digits, in this case, 6.

Case 2:  Seven Points of Data

x (degrees)
x (radians)
sin(x)
0
0
15°
π/12
(√6 - √2)/4 ≈ 0.258819045102
30°
π/6
1/2 = 0.5
45°
π/4
√2/2 ≈ 0.707106781185
60°
π/3
√3/2 ≈ 0.866025403785
75°
5π/12
(√6 + √2)/4 ≈ 0.965925826288
90°
π/2
1

Example 5:  Full Precision – Degrees

y = 1.74539026131E-2 x – 1.00636910048E-7 x^2 – 8.79821584089E-7 x^3 – 1.93973162632E-10 x^4 + 1.66950110845E-11 x^5 – 2.72879457224E-14 x^6

Absolute maximum error, data measured in 5° tick marks:  1.2072093E-6
(pretty darn good)

Example 6:  Full Precision – Radians

y = -6.98792887569E-12 + 1.0000349642 x – 3.30435720904E-4 x^2 – 0.165486304503 x^3 – 2.09062241321E-3 x^4 + 1.03087220879E-2 x^5  - 9.65423458482E-4 x^6

Maximum absolute error, data measured in π/36 radian tick marks:  0.00049429473
(3 decimal places)

I think the degrees approximation wins.  But what if we round the radians version (Example 6) to 6 decimal places?

Example 7:  6 Decimal Places – Radians

y = 1.000035 x – 0.00033 x^2 – 0.165486 x^3 – 0.002091 x^4 + 0.010309 x^5 – 0.000965 x^6

Maximum absolute error, data measured in π/36 radian tick marks:  9.03153E-6

Interesting result here, and a nice one at that!



Eddie

This blog is property of Edward Shore, 2017

Monday, April 10, 2017

HP Prime: Fick Cardiac Output (The Blog Turns Six!)



HP Prime:  Fick Cardiac Output  (The Blog Turns Six!)

A Special Note

Happy sixth birthday to my mathematics blog!   And a big reason why blog has turned six on April 11, 2017 is because of all of you readers!  Words can’t explain how appreciated I am. 

Thank you!  Cheers to everyone!

Fun fact:  The most popular blog entry is my TI-36X Pro review (my fourth blog entry, 4/27/2011).  Link:  http://edspi31415.blogspot.com/2011/04/ti-36-pro-review.html

Now let’s get to today’s subject. 

Fick Cardiac Output Equations

The program FICK will calculate:

* CO: Cardiac Output (L/min)
* SV: Stroke Volume (ml)
* CI:  Cardiac Index (L/(min/m^2))
* SI:  Stroke Index (ml/m^2)

Given the following inputs:

* Ca:  Arterial blood oxygen (O2) content percentage
* CvO2:  Venous blood oxygen (O2) content percentage
* VO2:  Oxygen compulsion (in ml per pure oxygen gas per minute, STPD)
* HR:  Heart Rate in beats per minute (BPM)
* Height in cm
* Weight in kg

STPD: Standard Temperature Pressure Density

Conversion factors:  1 in = 2.54 cm, 12 in = 1 ft, 1 lb = 0.45359237 kg

Formulas: 

CO = VO2 / (10 * (Ca - CvO2))
SV = CO * 1000/HR
CI = CO/BSA
SI = SV/BSA

BSA:  body surface area, measured in cm^3.  There are several formulas, but the Fick program uses the simple approximation formula:

BSA = √(weight * height)/60

HP Prime Program FICK

EXPORT FICK()
BEGIN
// Fick Cardiac Output
// HP 65, 1972
// EWS 2017-04-10

// inputs
LOCAL ca,cv,vo,hr,h,w;
INPUT({ca,cv,vo,hr,h,w},
"Fick Cardiac Output",
{"Ca O_2:","C_v O_2:","VO_2:","HR:",
"Height:","Weight:"},
{"Arterial blood (%)",
"Venous blood (%)",
"O_2 compulsion (ml/min)",
"Heart Rate (BPM)",
"Height (cm)",
"Weight (kg)"});

// calculation
LOCAL co:=vo/(10*(ca-cv));
LOCAL sv:=co*1000/hr;
// simple BSA
LOCAL bsa:=√(w*h)/60;
LOCAL ci:=co/bsa;
LOCAL si:=sv/bsa;

// output
PRINT();
PRINT("Cardiac Output (l/min)");
PRINT(co);
PRINT("Stroke Volume (ml)");
PRINT(sv);
PRINT("Cardiac Index (L/(min/m^2))");
PRINT(ci);
PRINT("Stroke Index (ml/m^2)");
PRINT(si);

END;

Example:

Inputs:



* Ca:  19%
* CvO2:  15%
* VO2:  250 ml/min
* HR:  64
* Height: 5 ft 11 in, 180.34 cm
* Weight 196 lb, 88.90410452 kg

Results:

* CO: 6.25 L/min
* SV: 97.65625 ml
* CI:  2.96158586825 L/(min/m^2)
* SI:  46.2747791914 ml/m^2

Source:

Hewlett Packard.  HP-67/97 User’s Library Solutions: Cardiac Corvallis, OR 1976  pg. 20

Here’s to many more years!

Eddie

This blog is property of Edward Shore, 2017.

HP Prime and TI-84 Plus CE: Shallow Wave Analysis

HP Prime and TI-84 Plus CE:  Shallow Wave Analysis Introduction The program H2OWAVES calculates wave speed, impedance, and w...