Showing posts with label mean. Show all posts
Showing posts with label mean. Show all posts

Saturday, January 17, 2026

BASIC vs. Python: Mean and Standard Deviation by an Iterative Method

BASIC vs. Python: Mean and Standard Deviation by an Iterative Method



Calculators Used:

BASIC: Sharp EL-5500 III

Python: Casio fx-CG 100


Introduction


The following code calculates the sum, mean, and standard deviation of a data set. The method that will be used is from voidware.com, which suggests an iterative method, as follows (Voidware):


M_0 = 0, S_0 = 0, n = 0


Loop with data point X:

M_n+1 = M_n + (X – M_n) ÷ (n + 1)

S_n+1 = S_n + (X – M_n) × (X – M_n+1)

n = n + 1


When all the data as been tabulated:

S = √(S ÷ (n – 1))


M: mean

S: standard deviation


Source

“Standard Deviation” Voidware. http://www.voidware.com/sd.htm Website was last updated in 2018. Last Retrieved July 4, 2025.



BASIC: Sharp EL-5500 III



10 PRINT "ONE VAR STATS"

12 CLEAR

30 INPUT "DATA? "; X

32 E=M+(X-M)*(N+1)

34 S=S+(X-M)*(X-E)

36 N=N+1

38 M=E

40 U=U+X

42 INPUT "MORE? (1=YES) "; C

44 IF C=1 THEN 30

60 S=√(S/(N-1))

70 PRINT "# DATA= "; N

72 PRINT "SUM= "; U

74 PRINT "MEAN= "; M

76 PRINT "STD DEV= "; S

78 END



Notes:

CLEAR: clears all the variables A-Z and resets their values to zero

PRINT: pauses the screen while the message is displayed



Python: Casio fx-CG 100

(Can be we used with any calculator with Python)



# one var stat without the math module

# voidware.com/sd.htm



def onevar(data):

  # set up

  m,s,u,n=0,0,0,0

  for i in data:

    e=m+(i-m)/(n+1)

    s+=(i-m)*(i-e)

    n+=1

    m=e

    u+=i

  s=(s/(n-1))**0.5

  return [n,u,m,s]



Notes:

We can store multiple values to variables at once. Example:

var4, var3, var2, var1 = value1, value2, value3, value4



Storage Arithmetic:

s+=expression -> s=s+expression

s-=expression -> s=s-expression

s*=expression -> s=s*expression

s/=expression -> s=s/expression



Example



Data set:

n = 1: x = 105

n = 2: x = 107

n = 3: x = 86

n = 4: x = 96

n = 5: x = 113



Data Structure: [105, 107, 86, 96, 113]



Results:

# DATA: 5 (N)

SUM: 507 (U)

MEAN: 101.4 (M)

STD DEV: 10.54988151 (S)


Eddie


All original content copyright, © 2011-2026. 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.


The author does not use AI engines and never will.



Saturday, February 8, 2025

RPN with HP 15C & DM32: Min, Max, Midrange, Log Mean

RPN with HP 15C & DM32: Min, Max, Midrange, Log Mean



Introduction


These set of programs calculates four statistics:


(1) Minimum

(2) Maximum

(3) Midrange = (minimum + maximum) / 2

(4) Log Mean, using the maximum and minimum points. The general formula is:


log mean(T1, T2) = (T2 – T1) / ln(T2 / T1)


The program also enters data points into the statistics registers, allowing for one-variable statistics to be performed.



DM 32 Code


Initialization: LBL I


I01 LBL I

I02 STO M

I03 STO N

I04 CLΣ

I05 Σ+

I06 RTN


Enter data, maximum on the Y stack, minimum on the X stack: LBL T


T01 LBL T

T02 STO J

T03 Σ+

T04 RCL M

T05 RCL J

T06 x<y?

T07 STO M

T08 RCL N

T09 RCL J

T10 x>y?

T11 STO N

T12 RCL N

T13 RCL M

T14 STOP

T15 GTO T


Midrange: LBL M


M01 LBL M

M02 RCL N

M03 RCL+ M

M04 2

M05 ÷

M06 RTN


Log-Mean – Use maximum and minimum to determine the log-mean: LBL L


L01 LBL L

L02 RCL N

L03 RCL- M

L04 RCL N

L05 RCL÷ M

L06 LN

L07 ÷

L08 RTN



Variables Used:


J: temporary value

M = minimum

N = maximum


Instructions:


Step 1: Enter the first point and start the process by executing label I.

Step 2: Enter subsequent points and execute label T. The minimum is shown on the X stack, and the maximum is shown on the Y stack.

Step 3: To calculate the midrange, execute label M. To calculate the log mean, execute label L.



HP 15C Code


Initialization: LBL A


001

42, 21, 11

LBL A

002

44, 0

STO 0

003

44, 8

STO 8

004

44, 9

STO 9

005

44, 32

CLΣ

006

45, 0

RCL 0

007

49

Σ+

008

43, 32

RTN



Enter data, maximum on the Y stack, minimum on the X stack: LBL B


009

42, 21, 12

LBL B

010

44, 0

STO 0

011

49

Σ+

012

45, 8

RCL 8

013

45, 0

RCL 0

014

43, 30, 8

TEST 8, x<y?

015

44, 8

STO 8

016

45, 9

RCL 9

017

45, 0

RCL 0

018

43, 30, 7

TEST 7, x>y?

019

44, 9

STO 9

020

45, 9

RCL 9

021

45, 8

RCL 8

022

31

R/S

023

22, 12

GTO B



Midrange: LBL C


024

42, 21, 13

LBL C

025

45, 8

RCL 8

026

45, 40, 9

RCL + 9

027

2

2

028

10

÷

029

43, 32

RTN



Log-Mean – Use maximum and minimum to determine the log-mean: LBL D


030

42, 21, 14

LBL D

031

45, 9

RCL 9

032

45, 30, 8

RCL - 8

033

45, 9

RCL 9

034

45, 10, 8

RCL ÷ 8

035

43, 12

LN

036

10

÷

037

43, 32

RTN



Variables Used:


R0: temporary value

R8 = minimum

R9 = maximum



Statistical variables used (as default):


R2 = n

R3 = Σx

R4 = Σx^2

R5 = Σy

R6 = Σy^2

R7 = Σxy


Instructions:


Step 1: Enter the first point and start the process by executing label A.

Step 2: Enter subsequent points and execute label B. The minimum is shown on the X stack, and the maximum is shown on the Y stack.

Step 3: To calculate the midrange, execute label C. To calculate the log mean, execute label D.


Examples


Example 1:


0.2322

0.8252

0.8005

0.9262


Maximum: 0.9262

Minimum: 0.2322

Midrange: 0.5792

Log Mean: 0.5016


Example 2:


96

54

29

64

48

27


Maximum: 96

Minimum: 27

Midrange: 61.5

Log Mean: 54.3945




Sources


Volk, William. Engineering Statistics With A Programmable Calculator. McGraw-Hill Book Company: New York. 1982. pp. 8-9. ISBN 0-07-067552-X.


“Logarithmic Mean” Wikipedia. Last updated September 30, 2024. https://en.wikipedia.org/wiki/Logarithmic_mean. Last retrieved October 10, 2024.



Until next time,


Eddie


All original content copyright, © 2011-2025. 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, January 25, 2025

Casio fx-991CW: The Spreadsheet

Casio fx-991CW: The Spreadsheet



Welcome to the Casio fx-991CW segment, which is planned to be every last Saturday of the month for 2025!



Spreadsheet


Screenshots are used the classpad.net website which contains the fx-991CW emulator.


The Casio fx-991CW has a Spreadsheet mode. The spreadsheet is 45 rows and 5 columns. The spreadsheet has a memory capacity of 2,380 bytes. The spreadsheet has basic spreadsheet functions. Data is saved as long as the calculator is in the Spreadsheet mode. Individual results can be stored in the calculator’s memory registers A, B, C, D, E, F, x, y, and z.


The spreadsheet of the fx-991CW can only contain numerical data. There are no labels.


Auto Calc is assumed to be on.


fx-991CW:  Selection of the Spreadsheet mode



Sum, Mean, and Count of a Range of Cells


The sum of a range: = Sum( α# : β# )

The arithmetic mean of all the numbers in a range: = Mean( α# : β# )

The count of all cells that have a value stored: = Sum( α# : β# ) ÷ Mean( α# : β# )


The count has to be constructed because there is no count function in the fx-991CW. Since Sum is Σx and Mean is Σx / n. Hence count, or n, is: Count = Sum / Mean = Σx / (Σx / n) = Σx * (n / Σx) = n.


The Sum, Count, and the colon character ( : ) are found in the Catalog.


The Catalog key in the Spreadsheet mode

Example:



A

B

1

45

88

2

25

76

3

93

39


fx-991CW:  Sum, Mean, and Count – Spreadsheet


Min, Max, and Statistical Range of a Range of Cells


The minimum value of a range of cells: = Min( α# : β# )

The maximum value of a range of cells: = Max( α# : β# )

The statistical range of a range of cells: = Max( α# : β# ) - Min( α# : β# )


Example:



A

B

1

45

88

2

25

76

3

93

39


fx-991CW:  Min, Max, and Range - Spreadsheet




Multiply a Range of Cells with a Constant Rate



We can apply a formula to a range of cells through the Tools menu. The Fill Formula dialogue:

Fill Formula

Fill = (start the formula with the cell you are currently at)

Range : α# : β#

> Confirm


To make a cell absolute, attack a dollar sign, to both the column letter and row number. The dollar sign ( $ ) is in the Catalog.


Example:



A

B

1


0.85

2

59.95


3

42.75


4

73.95



fx-991CW:  multiplying a range with a constant



Storing a Cell’s Value


Exiting the Spreadsheet mode or turning the calculator off will erase the contents of the Spreadsheet. A way to store values permanently is to store the cell’s contents in one of the variables (A – F, x, y, z). To store a value:


1. Go to the cell.

2. Press the [ VARIABLE ] button.

3. Select a variable and press [ EXE ].

4. Select Store.


The value is now stored in the variable, which can be used in other modes. Unlike the spreadsheet, values stored in values are kept until a reset.


fx-991CW:  storing a value in a variable



I hope you find this helpful.


Until next time,


Eddie


All original content copyright, © 2011-2025. 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.

Python – Earth’s Radius and Gravity in US Units

Python – Earth’s Radius and Gravity in US Units Introduction The following script, gravus2.py, estimates the Earth’s gravity i...