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

Tuesday, December 26, 2023

HP15C: A Corrected Floor Function by Werner

HP15C: A Corrected Floor Function by Werner



A Corrected Floor Function



On November 25, 2023, I posted floor and ceiling functions for the HP 15C, DM42, and HP 27S calculators.  I also posted the code on the Museum of HP Calculators (MoHPC).


Werner informed me that the floor code was inaccurate for x=-0.5.   In fact, the code is inaccurate for all x values from -1 to 0.  


The corrected code that Werner presented, by permission, on the MoHPC forum is:


Key Code : Key


__, 43, 44 : INT

42, _4, 25:  x<> I

__, 43, 36:  LST x

__, 42, 44:  FRAC

43, 30, _2:  TEST (x<0?)

42, _5, 25:  DSE I   (decreases I, always skips)

__, __, 16:  CHS  (nop)

__, __, 33:  R↓

42, _4, 25:  x<>I


This code works for all real values.   


For the ceiling function, use the identity:   ceil(x) = -floor(-x).  


   

MoHPC thread:  

https://www.hpmuseum.org/forum/thread-20766-post-182065.html#pid182065


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. 


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. 


Sunday, August 1, 2021

Casio fx-115ES Plus: Ten Tips

 Casio fx-115ES Plus:  Ten Tips


This blog entry covers both the original and the current 2nd Edition of the Casio fx-115 ES Plus.  Here are ten things to help you know about some of the advanced features of the fx-115 ES Plus, including some things to watch out for.  


I believe this also covers the fx-991 ES Plus 2nd Edition (NOT the Classwiz).  


Tip 1:  Integer Division and Modulus


Find the quotient and remainder of a division problem by pressing [ALPHA] [ []/[] ] (÷R).   We can use this calculate the modulo of two positive numbers (use caution with negative numbers).


Example 1:  364 mod 20 = 4

364÷R20 returns 18, R = 4

(18 * 20 + 4 = 364)


Example 2:  178.5 mod 18.5 = 12 

178.5÷R18.5 returns 9,R=12

(9 * 18.5 + 12 = 178.5)


Tip 2:  Solving Quadratic Equations Also Calculates the Extrema Point


Solving quadratic equations in EQN mode will present the point of the parabola's extrema point (minimum or maximum).  Keep on pressing [ ↓ ] or [ = ].


[ Mode ],  5:  EQN,  3:  aX^2+bX+c=0


Example 1:  4 * x^2 + 13 * x + 5 = 0

[ 4, 13, 5]

X1 = (-13+√89)/8   (MthIO mode)

X2 = (-13-√89)/8

X-Value Minimum = -13/8

Y-Value Minimum = -89/16


Example 2:  -2 * x^2 + 5 * x + 10 = 0

[-2, 5, 10]

X1 = (5+√105)/4

X2 = (5-√105)/4

X-Value Maximum = 5/4

Y-Value Maximum = 105/8


Please note that results and coefficients are not stored in variables.  This goes for all the equations in EQN mode, including finding roots of a polynomial and solving simultaneous equations.  


Tip 3:  Solving Quadratic Inequalities


The Inequality mode solves inequalities for quadratic and cubic equations.  


[ MODE ], [ ↓ ], 1: INEQ,  1 for quadratic equation/2 for cubic equation, select inequality:


1:  >0

2:  <0

3:  ≥0

4:  ≤0


Example:  Solve x^3 + 2 * x - 3 > 0

[1, 0, 2, -3], option 2

Result:  1<X


Tip 4:  The Percent Function


The percent function ( [ SHIFT ] [ ( ] (%) ) just divides the argument by 100.  This can lead to puzzling results when working addition and subtraction problems involving percent.


8 + 10% returns 8.1   (10% converts it to 0.1)

8 - 10% returns 7.9


To add and subtract percents properly, do this instead:


8(1 + 10%) returns 8.8

8(1 - 10%) returns 7.2


Tip 5:  Limited Powers in Complex Mode


In complex mode (CMPLX), the only powers available to be calculated are x^2 and x^3.   To take any complex number to any real power will require the use of De Moivre's formula:


(x + yi)^n = r^n * cos θ + i * r^n * sin θ


My suggestion to use COMP mode, with the Rec and Pol conversions.  In CMPLX mode, rectangular/polar conversions do not store results.  In COMP mode, rectangular/polar conversions store results in the following variables:


X:  x, r

Y:  y, θ


Tip 6:  Solve Equations for Any Variable


We can use the general solver in COMP mode to solve for any variable.  The syntax is:


equation, variable;  press [ SHIFT ], [ CALC ] (SOLVE)


If variable is omitted, the variable to be solved for assumed to be X.


If the equation does not contain an equals sign (=), the solver finds the root for equation, assuming equation=0.


The entries and results are stored in variables. 


In Radians mode:

Example 1: y = x * sin x  with y =0.5

We are solving for x, so we can eliminate the variable argument.


Y=X*sin(X), [ SHIFT ], [ CALC ]

Enter 0.5 for Y

Enter a guess for X, I chose 1.

Result:  X = 0.7408409551, L-R = 0


Example:  2 * a - b = 3 * c, solve for b when a = 2 and c = -1.

2A-B=3C, B, [ SHIFT ], [ CALC ]

Enter 2 for A

Enter -1 for C

Enter a guess for B, I chose 1 (again).

Result:  B = 7, L-R = 0


Caution:  Some equations can not be solved on the fx-115 ES Plus.  In particular, involving integrals and derivatives.  


Tip 7:  The Repeating Decimal Bar


I think this may be only calculator (yet), that allows the use to easily type in a bar to represent repeating decimals.  


Example:

1.45454545454545454545....   can be typed with 1.45 with the bar over the 45, or 1, [ . ], [ ALPHA ], [ √ ] ( bar ) 45


Pressing [ = ] returns 16/11 (assuming MthIO is set).  Repeated uses of [ S←→D ] gives 1.(45), 1.454545455, 16/11.


Tip 8:  Integer Part and Greatest Integer Function (Floor)


Int ( [ ALPHA ] [ + ] ):  Returns the integer part of a number


Intg ( [ALPHA] [ - ] ):  Returns the floor function of a number, the largest integer that does not exceed the given number.  


Example 1:

Int(-12.96) returns -12

Intg(-12.96) returns -13


To find the (calculator) fractional part of a number, enter n - Int(n).  


Tip 9:  Use CALC to Formula Evaluation


In addition to the Table mode, using [ CALC ] in COMP mode allows the user to evaluate a formula using different expressions.   As long as you keep pressing [ = ], the prompting for variables and calculations repeat.  The latest values are updated in the memory registers.


Expressions may take the form of:


variable = expression


To results are stored in the designated variable.


Example:   Evaluate for y when x = 0.2, x = 0.7, and x = 1.2 when y = x^3 + 15 * log x

Y=X^3+15*log(X)   

[ CALC ]

Enter 0.2 for X, [ = ]

Result #1: -10.49255007, [ = ]

Enter 0.7 for X, [ = ]

Result #2: -2.6665294, [ = ]

Enter 1.2 for X, [ = ]

Result #3:  -0.5402813093 


Press [ AC ] to exit.


Tip 10:  Previous Answers are Stored Two-Deep in COMP Mode


In COMP mode, we have both Ans and PreAns ([ALPHA], [ Ans ]).  PreAns recalls the answer from two calculations ago.  


Be careful, switching modes with most likely clear the PreAns register (zero).  Also, PreAns is only available in COMP mode.


Bonus:  Checking the fx-115ES Plus 2nd Edition's ID  (2nd Edition only)


You can see the calculator's ID along with a bar code which allows to test whether the calculator is a genuine Casio calculator.  


I hope you find these tips helpful,


Eddie


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

Basic vs. Python: Circle Inscribed in Circle [HP 71B, Casio fx-CG 100]

Basic vs. Python: Circle Inscribed in Circle Calculators Used: Basic: HP 71B Python: Casio fx-CG 100 Introduction ...