Post Reply 
[VA] SRC#005- April, 1st Mean Minichallenge
04-12-2019, 09:54 PM
Post: #18
RE: [VA] SRC#005- April, 1st Mean Minichallenge
Hello Valentin,
Sorry for being a bit late and thanks for the interesting challenge.
I learned a lot about "mean" calculations (and about HP 15c prgramming). I always wondered how the geometric mean is connected to the other means.

Here is my solution for the HP 15C:
Code:
001  LBL A        | 42,21,11  # Mean calculation subroutine, expects data in Matrix A and k in x
002  2            |        2
003  -            |       30 
004  STO 8        |    44  8  # STO  p = k - 2
005  MATRIX 1     | 42,16, 1  # Reset matrix indices
006  CLR_Sum      |   42  32
007  LBL .0       | 42,21,.0
008  RCL A        |   45  11  # Get matrix element
009  RCL 8        |    45  8
010  x=0          |   43  20
011  GTO .1       |    22 .1
012  y^x          |       14  # p is not 0
013  GTO .2       |    22 .2
014  LBL .1       | 42,21,.1  # p is 0 (=geometric mean)
015  R_down       |       33
016  x=0          |   43  20  # Check, whether xi is 0 
017  RTN          |   43  32  # If yes, finished
018  LN           |   43  12  
019  LBL .2       | 42,21,.2
020  SUM+         |       49
021u RCL A        |   45  11  # Next element (note the user mode u)
022  GTO .0       |    22 .0
023  E(X)         |    43  0  # Get the average
024  RCL 8        |    45  8
025  x=0          |   43  20  # Check, whether p is 0
026  GTO .1       |    22 .1
027  1/x          |       15  # p is not 0
028  y^x          |       14
029  RTN          |   43  32
030  LBL .1       | 42,21,.1  # p is 0 (=geometric mean)
031  R_down       |       33
032  e^x          |       12
033  RTN          |   43  32
034  LBL B        | 42,21,12  # Helper function for solving Mp(A) = pi
035  GSB A        |   32  11
036  PI           |   43  26
037  -            |       30
Here the geometric mean is also calculated with the intrinsic averaging functions of the calculator. In the case k=2 the ln(xi) are summed and afterwards e^x of the average is calculated. The relative error of the method compared to the standard calculation using the products is 4.6e-10 for the values you used.
The value for the geometric mean calculated by the logarithmic summation is:
M2=4.322471149

The value calculated by multiplication is
M2=4.322471151

Here are the values for the requested parameters:
M-2.019 = 1.313123100
M0.61 = 1.979834390
M5/2 = 6.238885591
MPi = 8.981253690

The solution of Mp=pi is calculated by the sequence
Code:
1
ENTER
2
SOLVE B
My solution for p is p=1.554252433 or k =3.554252433.

Best regards
Bernd
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: [VA] SRC#005- April, 1st Mean Minichallenge - Bernd Grubert - 04-12-2019 09:54 PM



User(s) browsing this thread: 1 Guest(s)