Showing posts with label ceiling function. Show all posts
Showing posts with label ceiling function. Show all posts

Saturday, November 25, 2023

HP 15C, DM42, HP 27S: Floor and Ceiling Functions

HP 15C, DM42, HP 27S:   Floor and Ceiling Functions


(Updated on 12/22/2023 - see note below for the HP 15C versions)


Notes :


HP 15C: includes  HP 15C, Original, Limited, and Collector's Edition, and apps

DM42: includes HP 42S, DM42, Free42, Plus42




Introduction:  Floor and Ceiling Functions


The floor and ceiling functions are two common functions that transfers a number to an integer.   



Floor Function



Floor:   The greatest integer that is less than or equal to x.  A common symbol for floor is |_x_| and a function call is floor(x).


Let int(x) be the integer part function (sometimes labeled intg(x) or lp(x)), and frac(x) be the fractional part function (sometimes labeled fp(x)).


#  x is an integer

If frac(x) = 0, then return floor(x) =  x     


# x is not an integer

If x ≥ 0, then return floor(x) = int(x)

If x < 0, then return floor(x) = int(x) - 1


Per the function.wolfram.com web page: an equivalent using the modulus function for floor(x) is:


floor(x) = x - x mod 1


Examples:


floor(2.8) = 2

floor(6) = 6

floor(-2.8) = -3



Ceiling Function


Ceiling:  The least integer that is greater than or equal to x.  A common symbol for ceiling is |-x-| (except the horizontal lines are the top) and a function call is either ceil(x) or ceiling(x).  


#  x is an integer

If frac(x) = 0, then return ceil(x) =  x     


# x is not an integer

If x ≥ 0, then return ceil(x) = int(x) + 1

If x < 0, then return ceil(x) = int(x) 


Per the function.wolfram.com web page: an equivalent using the modulus function for floor(x) is:


ceil(x) = x + (-x) mod 1


Examples:

ceil(2.8) = 3

ceil(6) = 6

ceil(-2.8) = -2



Calculator Code:  HP 15C, DM 42, HP 27S



HP 15C


This program is NOT accurate for -1 < x < 0 (such as x = -0.5).  Gratitude to Werner for alerting me of this.  (12/22/2023)


Three labels are used:

D:  floor function

E:  ceiling function

1:  used in calculation for both  (roll stack down one extra time when frac(x)≠0)


step #:  key code : key


000:  42, 21, 14:  LBL D

001:  __, __, 36:  ENTER

002:  __, 42, 44:  FRAC

003:  __, 43, 20:  x=0

004:  __, 22, _1:  GTO 1

005:  __, __, 33:  R↓

006:  __, 43, 44:  INT

007:  43, 30, _3:  TEST 3  (x≥0)

008:  __, 43, 32:  RTN

009:  __, __, _1:  1

010:  __, __, 30:  -

011:  __, 43, 32:  RTN


012:  42, 21, 15:  LBL E

013:  __, __, 36:  ENTER

014:  __, 42, 44:  FRAC

015:  __, 43, 20:  x=0

016:  __, 22, _1:  GTO 1

017:  __, __, 33:  R↓

018:  __, 43, 44:  INT

019:  43, 30, _2:  TEST 2 (x<0)

020:  __, 43, 32:  RTN

021:  __, __, _1:  1

022:  __, __, 40:  +

023:  __, 43, 32:  RTN


024:  42, 21, _1:  LBL 1

025:  __, __, 33:  R↓

026:  __, 43, 32:  RTN






DM42/Free 42/HP 42S


00 { 16-Byte Prgm }

01▸LBL "FLOOR"

02 ENTER

03 ENTER

04 1

05 MOD

06 -

07 RTN

08 END


00 { 15-Byte Prgm }

01▸LBL "CEIL"

02 ENTER

03 +/-

04 1

05 MOD

06 +

07 RTN

08 .END.



HP 27S


FLOOR=X-MOD(X:1)


CEIL=X+MOD(-X:1)



Sources


Wolfram Research, Inc.   "Floor Function".  Path:  Integer Functions > Floor[z] > Representations through equivalent functions > With related functions.   Retrieved October 30, 2023.


https://functions.wolfram.com/IntegerFunctions/Floor/27/01/05/



Wolfram Research, Inc.   "Ceiling Function".  Path:  Integer Functions > Ceiling[z] > Representations through equivalent functions > With related functions.   Retrieved October 30, 2023.


https://functions.wolfram.com/IntegerFunctions/Ceiling/27/01/05/




Eddie


All original content copyright, © 2011-2023.  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, January 9, 2022

Fun With The HP 27S

Fun With The HP 27S


Notes:


*  The HP 27S is set to FIX 4


*  Since none of the formulas have trigonometric functions, they can also be programmed on the HP 17B and HP 17BII+


Partial Fraction Decomposition


(A ∙ x + B)÷((x + C) ∙ (x + D)) = R÷(x + C) + S÷(x + D)


Inputs:  A, B, C, D

Outputs:  R, S


Formula:


PARTFRAC2:(A+B+C+D)×0=IF(S(R):(B-C×A)÷(D-C)-R:(B-D×A)÷(C-D)-S)


Example:  (4 ∙ x + 3) ÷ ((x - 5) ∙ (x + 1))

A = 4, B = 3, C = -5, D = 1

Results:  R = 3.8333, S = 0.1667


Use that the 0×(var1+var2+...) to set an order of variables in the solver.  


2 x 2 Simultaneous Equations


A ∙ x + B ∙ y = C

D ∙ x + E ∙ y = F


The solutions are:


x = (C ∙ E - B ∙ F) ÷ (A ∙ E - B ∙ D)

y = (A ∙ F - C ∙ D) ÷ (A ∙ E - B ∙ D)


Formula:


SIM2X2:0×(A+B+C+D+E+F+L(M:A×E-B×D))=IF(S(X):(C×E-B×F)÷G(M)-X:(A×F-C×D)÷G(M)Y)


Example:  2x + 3y =5, -3x + 8y = -8

A = 2, B = 3, C = 5, D = -3, E = 5, F = -8

Results:  X = 2.5789, Y = -0.0526


Floor Function


floor(x):  the greatest integer less than or equal to x


floor(x):

If frac(x) = 0 Then return x

 Else If x≥0, then return intg(x) else return intg(x)-1


Formula:


FLOOR=IF(FP(X)=0:X:IF(X>=0:IP(X):IP(X)-1))


Examples:

X = 2.38, FLOOR = 2.0000

X = -9.21, FLOOR = -10.0000


Ceiling Function


ceil(x):  the least integer greater than or equal to x


ceil(x):

If frac(x) = 0 Then return x

  Else If x≥0, then intg(x)+1 else return intg(x)


Formula:


CEIL=IF(FP(X)=0:X:IF(X>=0:IP(X)+1:IP(X)))


Examples:

X = 2.38, CEIL = 3.0000

X = -9.21, CEIL = -9.0000


Rydberg Formula


The Rydberg formula measures the light's wavelength when an electron moves between energy quantum numbers (from higher to lower levels).  The Rydberg formula is to be used for simple atoms only, and is most used for hydrogen atoms.


1/λ = R ∙ Z^2 ∙ (1/n1^2 - 1/n2^2)


R = Rydberg's Constant ≈ 1.097373157 × 10^7 m^(-1)

Z = atomic number, 1 for hydrogen

n1, n2:  energy levels


Formula:


RYDBERG:INV(L)=1.09737316E7×SQ(Z)×(INV(SQ(N1))-INV(SQ(N2)))


N2 > N1


Example:

The energy of an hydrogen election from level 4 to level 2.  Z = 1

Z =1,  N1 = 2, N2 = 4

Result:  L = 4.8601E-7


Source:

Helmenstine, Todd. "What Is the Rydberg Formula and How Does It Work?" ThoughtCo, Aug. 28, 2020, https://www.thoughtco.com/what-is-the-rydberg-formula-604285   Retrieved November 4, 2021



Moment of Inertia - Circular Ring


D$OUT:  outside diameter

D$IN:  insider diameter.  For a circle, set D$IN = 0

I: moment of inertia


Formula:


I=PI×(D$OUT^4-D$IN^4)÷64


Examples:


Circular Ring:

D$OUT = 6.2, D$IN = 1.9;  I = 71.8935


Circle:

D$OUT = 6.2, D$IN = 0; i = 72.5332


Source:

"Properties Of Annual Sections" HP-19C/HP-29C Solutions: Civil Engineering  Hewlett-Packard.  1977



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


RPN HP 12C: Fibonacci and Lucas Sequences

  RPN HP 12C: Fibonacci and Lucas Sequences Golden Ratio, Formulas, and Sequences Let φ be the Golden Ratio: φ = (1 + √5) ÷ 2...