Monday, August 28, 2023

HP 15C Collector's Edition: Some Thoughts and Hidden Modes

HP 15C Collector's Edition:   Some Thoughts and Hidden Modes



On May 2, 2023, Moravia announced the return on the HP 15C programming scientific calculator.  An initial limited run  calculators were available that were delivered in July. Thankfully, another set of calculators will be available for order and delivery starting the end of September 2023.









Hopefully this will be true in future production runs, but in the initial run, the HP 15C came in a box, a Thank You card,  with a leather case and a printed manual.    I love the larger font and the clarity of the text of the Owner's Handbook.   The handbook is an extension of the original HP 15C Manual along with an introduction from Wlodek Mier-Jedrzejowicz and Gene Wright.  


You can download both the Manual and new edition of the Advanced Functions Handbook from the HP Calculator Literature website:


Manual:  https://literature.hpcalc.org/items/2258

Advanced Functions Handbook:  https://literature.hpcalc.org/items/2259


The compliment to Manual, the Advanced Functions Handbook goes into detail on several of the HP 15C's advanced features:  


Solving Equations:   The best ways for using the SOLVE command, and how the SOLVE feature finds roots of equations.  This section also includes a section of finding the derivative (approximate slope) of a function and a financial time-value-of-money program.


Integration:  The accuracy of the integral function and handling more difficult integral problems.  In general, the accuracy and the time of integration is tied to the fixed decimal settings.


Complex Numbers:  The internal workings of the complex mode (Flag 8), including solving equations and integrations.


Matrices:  LU Decomposition, constructing identity matrices, and least-squares calculations.


Programming:  No More Pause Bug


The PSE bug has been fixed!  We can use the pause command to heart's content and the display won't flash off.  


Back of the Calculator





The back of the HP 15C has a plate that has the following information:  statistics registers, some conversions, a table of error, test, and matrix codes, how the ISG (increment skip if greater than) and DSE (decrement skip if equal) commands work, and the stack effects on several two-result commands.


The Keyboard


The battery compartment, which contains the two CR2032 batteries needed to power the HP 15C is held by a small screw.  Thankfully, no special screwdriver is required, a small household or computer screwdriver should do the trick.


The keyboard, for me, is responsive.  The keys give a nice, quiet click when they are pressed.  I'm comfortable holding the calculator and letting my thumbs type on the keyboard efficiently.




Hidden Modes


Already, the HP 15C Collector's Edition has additional memory over the previous editions:


*  A maximum of 99 memory registers, 78 uncommitted registers at default setting

*  A maximum of 672 steps


We have some Easter Eggs on the HP 15C Collector's Edition.   There are two hidden modes on the HP 15C:


HP 15.2 Mode:  This mode ups the maximum of memory registers to 195, with 174 uncommitted registers at default setting.    Pressing [ g ] ( MEM ) at the beginning will show "19174 00-0", as there really isn't enough room to display the total amount of uncommitted registers.  I have my calculator in 15.2 mode and so far, this calculator works as well as the default HP 15 mode.  Switching back to 15 mode will preserve as much memory as allowed, excessive memory will be lost.  


HP 16 Mode:  This modes accesses a possible-beta version of the HP 16C calculator.   The HP 16C calculator was a popular computer programmer's calculator which emphasizes on bit manipulation, base conversions, and Boolean logic.   I worked a little bit on this mode, and there was a few problems when working in decimal integer mode.     More information on the HP 16C calculator here:  https://www.hpmuseum.org/hp16.htm


How do we switch the hidden modes on the Collector's Edition?


1.  With the calculator off: hold the [ g ], [ ENTER ], and [ ON ] keys.   This gets the calculator into test mode.

2.  Press [ 4 ].  Option 4 will not appear on the screen.

3.  Set your mode:

   * [ e^x ] for the original HP 15C Collector's Edition mode

   * [ 1/x ] for the expanded 15.2 mode  (not manufacturer supported)

   * [ 7 ] for the HP 16C mode (not manufacturer supported)


Caution:  The 15.2 and 16 modes are not manufactured supported.  Enter at your own risk.  For me, I have used the 15.2 mode and the calculator works fine.  The original mode still has plenty of memory.  


Discussion on the hidden modes starts about page 17 of this thread:

https://www.hpmuseum.org/forum/thread-19886-page-17.html



Final Thoughts


Welcome back, HP 15C!  Knock on wood the HP 15C once again becomes mainstream like it's long time financial cousin the HP 12C.

Need help with RPN (Reverse Polish Notation)?  Check out the RPN Programming tutorial series (which was done for the previous HP 15C Limited Edition) which starts here:  http://edspi31415.blogspot.com/2011/11/hp-15c-programming-tutorial-part-1.html

(Just keep in mind the pause bug that was present in the Limited Edition has been fixed in the Collector's Edition.)


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, August 27, 2023

Casio fx-9750GIII and Swiss Micros DM42: Bijections

Casio fx-9750GIII and Swiss Micros DM42:  Bijections



Bijection - Three Problems 



I have a subscription to Brilliant (brillant.org, this is not a paid ad), where I am taking courses of probability, quantitative finance, and quantum mechanics.  


Today's blog is dealing with bijections, a technique to solve a class of counting problems.   A counting problem calculates the number of ways an event, such as distributing pieces of candy among a group of people, can happen.  


Here, I am working with three types of problems:


Problem 1:  How many positive integer solutions are possible of the equation:


A + B + C + ... = M


M = sum of the integers A, B, C, etc.

M > A, M > B, M > C.  


Problem 2:  How many positive integer solutions are possible of the equation:


A + B + C + ... ≤ M


M = sum of the integers A, B, C, etc.

M > A, M > B, M > C.  


Problem 3:  How many ways can distribute a set amount of balls into a set of urns?  Assume that the urns do not have to have an equal amount of balls.  


Similar problem would be:


How many ways to distribute candy among a population of people?  


How many ways to give a deck of cards from a deck to a table full of players, given that each card is randomly distributed?  Assume that the players do not have equal amount of cards.  



The programs on this blog uses two different approaches.   The program for the fx-9750GIII uses a prompt approach while the program for the DM42 uses a direct approach.  



Casio fx-9750GIII Program:  BIJECT


Code:

"EWS 2023-06-12"

0 → S

ClrText


Menu "BIJECTIONS","A+B+C+...=M",1,"A+B+C+...≤M",2,"BALLS IN URNS",3


Lbl 2

1 → S

Lbl 1

"# OF VARIABLES"? → B

V + S - 1 → V

"SUM (POS. INTEGER)"? → M

Goto 4


Lbl 3

"# OF URNS"? → V

V - 1 → V

"# OF BALLS"? → M

Lbl 4

(M + V) nCr V → S

"# SOLUTIONS = "

S


Notes:


The character # is from the character map (CHAR) of the default program menu in program editing mode (Mode B).


The combination function is displayed as a bold C.  I have nCr in the code listing for clarity.



Swiss Micros DM42 Program:  BIJECT


Code also works for HP 42S, Plus42, Free42


Code:

00  {14-Byte Prgm}

01  LBL "BIJECT"

02  +

03  LAST x

04  COMB

05  END


Stack Set Up:


Y:  number of dividers

X:  number of balls


Set up the stack for the three types of problems.


Problem 1:

Y:   number of variables - 1

X:  sum


Problem 2:

Y:  number of variables

X:  sum


Problem 3:

Y:  number of urns - 1

X: number of balls



Examples


Problem 1:  How many positive integer solutions are possible of the equation:


A + B + C = 20


Number of variables:  3

Sum:  20


Number of dividers:  2   (the number of plus signs in the equation)


Number of solutions:  nCr(20 + 2, 20) = 231



Problem 2:  How many positive integer solutions are possible of the equation:


A + B + C ≤ 20


Number of variables:  3

Sum:  20


Number of dividers:  3   


Since we are allowing for A, B, and C to add up to less than 20, add a slack variable, S, to "catch" any deficit to make the sum 20.   Therefore, we are really solving:


A + B + C + S = 20   


In listing the solutions, S is ignored. 


Number of solutions:  nCr(20 + 3, 20) = 1,771



Problem 3:  How many ways can distribute 40 balls in to 6 urns?


Set the urns in a line, and imagine a divider in between each urn.


urn 1 | urn 2 | urn 3 | urn 4 | urn 5 | urn 6


Number of dividers: 5

Number of balls:  40


Number of distributions:  nCr(40 + 5, 40) = 1,221,759


Try listing all possible distributions.




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, August 26, 2023

Scientific Calculators: Maxima and Minima

Scientific Calculators: Maxima and Minima



Introduction



This blog entry covers four calculators:


Casio fx-991CW

Casio fx-991EX Classwiz

Texas Instruments TI-36X Pro

Texas Instruments TI-30X Pro Math Print


Here is how to find extremum of any general function f(x) and g(x).   This method will tell you where the extremum is located, but not whether the extremum is a minimum or a maximum.  


The extremum of a function can be found by finding the root of the function's derivative:


d/dx f(x) = 0


The steps required are:


1.  Solve d/dx f(x) = 0 to get x.  

2.  Calculate y.  This is easier if we can store the function in f(x) or g(x).


Two methods to find the x point of extremum:


1.  Extremum using f(x) (or g(x))

2.  Extremum using direct entry method



The example used is to find the extremum of e^(sin x) with an initial guess x=1.  We'll be focusing on the x point only.  





Casio fx-991CW 


Either method can be used.   In the Solver Mode, the function button ( [f(x)] ) is available to define f(x) (or g(x)).   Since we are finding a root, we don't have to include the "=0" at the end.


The equation to be used in the solver is:


d/dx( f(x) ) | x = x      (MathIO input)


f(x) can be referenced or typed directly, like:


d/dx( e^(sin(x)) ) | x = x



Casio fx-991EX Classwiz


The direct entry method must be used.  The accuracy may vary for the last digits.  Not as accurate as the fx-991CW. 


Note:  Extremum for quadratic and cubic equations (fx-991CW only) are automatically calculated through the Solver-Polynomial feature of both the fx-991CW and fx-991EX.  





Texas Instruments TI-36X Pro and TI-30X Pro MathPrint



Either method can be used.   f(x) (and g(x) for the TI-30X Pro MathPrint), is edited through the [table] key.   When the function is edited, press [ 2nd ] [ mode ] (quit) to exit the table.    To enter Numeric Solver Mode, press [ 2nd ] [ sin sin^-1 ] (num-solv).  


The solver has the format:

[ ] = [ ]


In this case, we will need to include the 0 on either side of the template.  


Finding extremum is fairly simple.



For the example, the extremum e^(sin x) around x = 1 is x = π/2 (≈ 1.570796327).  


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. 


Monday, August 21, 2023

Retro Review: Texas Instruments Galaxy 40sx

Retro Review: Texas Instruments Galaxy 40sx







Quick Facts


Model:  Texas Instruments Galaxy 40sx

Company:  Texas Instruments

Years:  1991  (early 1990s)

Type:  Scientific

Power:  Solar Power

Display:  1 line, 10 digits

Memory Register:  1

Operating System:  Algebraic (prefix, AOS)



Features


The TI-Galaxy 40 sx is a landscape, scientific calculator which has the basic scientific calculator features plus several extras:


*  Trigonometry.  There are two angle modes: degrees and radians. 

*  1-variable statistics

*  Polar/Rectangular Conversion

*  Powers, Roots, Logarithms, Exponentials

*  Factorial of positive integers to 69

*  Scientific notation and cancellation of the scientific notation view mode

*  Two single-operation macros


The calculator is protected by a hard slide case, which slides on and off.  


The [ -x ] is the change sign key. 


The Galaxy 40 sx is the solar-powered version of the Galaxy 40 sx.  



Parenthesis


When the parenthesis keys [ ( ] and [ ) ] are pressed, the calculator keeps track of open parenthesis on the screen.   


For example:   (( 2 + 1.8 ) ÷ 3 )^3 ≈ 2.032296296


[ ( ]        [Screen:    (    One open level.]

[ ( ]        [Screen:   ( (   Two open levels.]

2 [ + ]

1.8 [ ) ]  [Screen:  ) flashes, then shows 3.8.  One open level left.]

[ ÷ ] 3 

[ ) ]         [Screen:  1.266666667]

[ 2nd ] (y^x)

3 [ = ]    [Screen:  2.032296296]



Fractions


The Galaxy 40sx has an emphasis on fractions:


[ |- ]:  Euclidean Division.    This function divides two integers and shows the quotient and remainder.


Example:

148 [ |- ] 39 [ = ] :    Q:  3   R : 31



Entering Fractions:


[ u ]:   Unit (whole number)


[ / ]:  Fraction key.  Enter the numerator, press [ / ], then enter the denominator.


Example:

Enter 5 4/9.   5 [ u ] 4 [ / ] 9 [ = ]:    5 u 4/9


[ F<>D ]:  Fraction/Decimal Conversion.  The algorithm is not perfect as if has a hard time converting many digits to fractions.   For example:  1.666666667 does not convert to 5/3.   0.142857143 does not convert to 1/7.  Your mileage may vary. 


[ F→A b/c ]:  Converts an improper fraction to a mixed fraction.  


Example:

427/19.   427 [ / ] 19 [ F→A b/c ]:  22 u 9/19


[ SIMP ]:  Simplify fractions.  When N/D→n/d appears on the left hand the screen, the displayed fraction can be simplified.  You can choose the factor or let the calculator choose the factor. 


To choose the factor, press [ SIMP ], enter a factor, then press [ = ].


To have the calculator choose the factor, press [ SIMP ], then press [ = ].


In either case, you can view the factor used by pressing [ 2nd ] [ SIMP ] (DIV).  To continue simplifying, press [ x<>y ] to get the fraction back on the screen.  


Example:  Let the calculator choose the factor.

24/88.  

[ SIMP ] [ = ]:   12/44.   [ 2nd ] [ SIMP ] (DIV):  2

[ x<>y ]

[ SIMP ] [ = ]:   6/22.   [ 2nd ] [ SIMP ] (DIV):  2

[ x<>y ]

[ SIMP ] [ = ]:   3/11.   [ 2nd ] [ SIMP ] (DIV):  2


A fraction is irreducible when N/D→n/d is no longer on the screen.



Memory Arithmetic



The Galaxy 40sx has one memory register.   


[ STO ]:  Store number into the memory register.


[ RCL ]:  Recall the number from the memory register.


[ SUM ]:  Adds the number to the memory register.  (STO+)


[ 2nd ] [ STO ] (EXC):  Exchanges the number in the memory with the contents of the memory register.  



Single-Operation Macros



The Galaxy 40sx has two single-operation macros: OP1 and OP2.   The operations can be stored are:


[ + ] n :  Addition

[ - ] n :  Subtraction

[ × ] n :  Multiplication

[ ÷ ] n : Division

[ y^x ] n : Power

[ ˣ√  ] n :  Roots (principal roots)


Storing each macro will also display any arithmetic operation, which is nice.  


Pressing [ 2nd ] (<OP1) or (<OP2) clears the macro.   


This allows for repeated calculations.


Example:  Square 4, 7, and 11.

[ AC/ON ] [ 2nd ] [ x^2 ] (y^x) [ OP1 ]

4 [ OP1 ]:   Display  1    16   (answer: 16,  1st step)

7 [ OP1 ]:   49  

11 [ OP1 ]:  121


Note:  When executing macros, there is a number on the left that indicates the number of times [ OP1 ] or [ OP2 ] has been pressed repeatedly, until 10 or more digits of the answer is displayed.   I find that potentially confusing.  



Final Thoughts 



I like the keyboard.   I wish the calculator had a full-simplification function as an option.   I would also love to see the SIMP key double as a prime factorization of an integer.   The parenthesis tracker and operation macros are nice.  


The calculator works best in full light and has some extra features above the basic scientific calculator.  



Source


Datamath.  "Texas Instruments Galaxy 40sx"  Last Updated December 5, 2001.  Retrieved August 14, 2023.  http://www.datamath.org/Sci/Galaxy/TI40_Galaxy.htm


The manual that can be downloaded is in Dutch.  



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, August 20, 2023

HP 42S and DM42: Multiplying Huge Positive Integers

HP 42S and DM42: Multiplying Huge Positive Integers





Introduction


The program LRG× multiplies to two large integers, allowing answers to extend beyond 12 digit capacity.  The product is shown in the alpha register.  How is this possible?  One way is to split the multiplier and multiplicand (also known as factors) into groups of digits.   This method is quite a complex process.  I will demonstrate with a simple example.




The Process Explained



Multiply: 


4,257 × 3,698 = 15,742,386


There are four digits in each of the factors (n = 4).


Split the numbers into groupings of two digits (n ÷ 2 =2).  Note that I use four registers to store the groups.   Memory registers R2 and R4 represent hundreds (10^2) while memory registers R1 and R3 represent units (10^0).


4257 = 42 × 10^2 + 57 

3698 = 36 × 10^2 + 98


R2 = 42, R1 = 57

R4 = 36, R3 = 98


Let memory register R5 be the units part of the product, up to 9999 (4 digits).   Let memory register R6 represent the part of the product 10,000 and above.  


On to the multiplication: 


Multiply R2 and R4, and store the results in R6.  In this case, 42 × 36 = 1512, which will R6 carry.   Memory register R6 represent ten-thousands (10^4) since R2 really is 4200 and R4 is really 3600, hence 4200 × 3600 = 15120000 = 1512 × 10^4.


Next multiply R1 and R3, then store the result in R5.   57 × 98 = 5586.   


We now have to take care of the cross product, which will represent hundreds (10^2).   This is done by the calculations of R2 × R3 + R4 × R1, which is 42 × 98 + 57 × 36 = 6168.  Note that this represents 6168 × 10^2 = 616800 = 610000 + 6800.  Add 61 to R6 (because R6 represents ten-thousands) and 6800 to R5.


In this example, the sums we have so far are:

R6 = 1573

R5 = 12386


R5 can only have four digits, we must carry over the 10000  (hence add 1 to R6, and drop the 1 from R5), to have a final result of:


R6 = 1573 + 1 = 1574

R5 = 2386


The answer is 15742386  (past R6 and R5 together).


Note:  Had R5 be less than 1000, R5 had to have four digits requiring a padding of zeroes (i.e. 712 becomes 0712, 16 become 0016).  


The program transfers R6 then R5 to the alpha register so the answer reads a long integer.   





In essence what we have done is:


4257 = 42 × 100 + 57 

3698 = 36 × 100 + 98


4257 × 3698 

= (42 × 10^2 + 57) × (36 × 10^2 + 98)

= (42 × 10^2 × 36 × 10^2) + (57 × 98) + (42 × 10^2 × 98 + 57 × 36 × 10^2)

= (1512 × 10^4) + 5586 + (4116 × 10^2 + 2052 × 10^2)

= (1512 × 10^4) + 5586 + (6168 × 10^2)

= 15120000 + 5586 + 616800

= 15742386


The program LRG× has larger unit digit capacity, up to 8 digits.   



HP 42S/Swiss Micros DM42 (including Free42 and Plus 42) Program:  LRG×


Raw file:  largemultiply.raw


Download the program here: https://drive.google.com/file/d/1KMCyGSSGeBvg0zT8UWvf4_uEaCVTfRwt/view?usp=sharing


Program Code:



00 { 156-Byte Prgm }

01▸LBL "LRG×"

02 ALL

03 XEQ 17

04 STO 02

05 XEQ 18

06 STO 01

07 R↓

08 XEQ 17

09 STO 04

10 XEQ 18

11 STO 03

12 RCL 02

13 RCL× 04

14 STO 06

15 RCL 01

16 RCL× 03

17 STO 05

18 RCL 01

19 RCL× 04

20 RCL 02

21 RCL× 03

22 +

23 ENTER

24 ENTER

25 XEQ 17

26 STO+ 06

27 LASTX

28 FP

29 8

30 10↑X

31 ×

32 STO+ 05

33 RCL 05

34 8

35 10↑X

36 X>Y?

37 GTO 16

38 ÷

39 ENTER

40 ENTER

41 IP

42 STO+ 06

43 R↓

44 FP

45 8

46 10↑X

47 ×

48 STO 05

49 GTO 16

50▸LBL 17

51 4

52 10↑X

53 ÷

54 IP

55 RTN

56▸LBL 18

57 LASTX

58 X<>Y

59 -

60 4

61 10↑X

62 ×

63 RTN

64▸LBL 16

65 CF 29

66 CLA

67 ARCL 06

68 8

69 RCL 05

70 X≠0?

71 GTO 21

72 8

73 GTO 22

74▸LBL 21

75 LOG

76 1

77 +

78 IP

79 -

80▸LBL 22

81 STO 07

82 X=0?

83 GTO 19

84▸LBL 20

85 48

86 XTOA

87 DSE 07

88 GTO 20

89▸LBL 19

90 ARCL 05

91 AVIEW

92 SF 29

93 .END.




Notes:


The program LRG× takes two integers from the stack.  This is meant to work on positive, non-zero integers.  


Flag 29 is the thousands separator flag.  Setting flag 29 turns them on while clearing it turns them off. In order to allow the alpha register have the long integer, flag 29 is cleared.


Memory register R5 represents units while R6 represents the part in hundred-millions.  


The program switches the display to ALL mode.  





Examples


Try these examples:  


54,195,365 × 40,857,695 = 2,214,297,693,583,675


12,068,999 × 50,245,126 = 606,408,375,448,874


50,700,600 × 33,800,020 = 1,713,681,294,012,000


58,763,110 × 6,758,999 = 397,179,801,726,890



Source


Hoffman, Dean and Mohler, Lee.   Mathematical Recreations for the Programmable Calculator  Hayden Book Company, Inc.   Rochelle Park:  New Jersey.  1982.  pp 146-166.  



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, August 19, 2023

Casio fx-991CW and TI-30X Pro MathPrint: Arc Length of f(x)

Casio fx-991CW and TI-30X Pro MathPrint:  Arc Length of f(x)



Here is a tip for calculus class.  



Calculating The Arc Length of f(x)



The arc length of f(x) is defined as:


∫( √( 1 + (f'(x))^2 ) dx, x = a to x = b)



With the two function memory, f(x) and g(x), on the Casio fx-991CW and TI-30X Pro MathPrint, we can calculate arc length with the expression:  


∫( √( 1 + (g(x))^2 ) dx, x = a to x = b)


where g(x) = d/dx f(x)





Setup Instructions



Casio fx-991CW


To set up f(x) and g(x):


1.  Press [ f(x) ], select Define f(x) to define the function.  Press [ EXE ] to register it. 

2.  Press [ f(x) ], select Define g(x) to define the derivative.  Press [ EXE ] to register it.  

3.  Recall f(x) and g(x) by pressing [ f(x) ] and selecting the function.



Derivative: 


g(x)  =  ( (f(x + h) - f(x) )/h     [h is sufficiently small, like 0.001]


The integral function on the fx-991CW does not allow to have the derivative command in the integrand.  Therefore, the definition of the derivative must be used.  



TI-30X Pro MathPrint


To set up f(x) and g(x):


1.  Press [ table ].   Select Add/Edict Func.

2.  Edit f(x), then press [ enter ].

3.  Edit g(x), enter the derivative.  Press [ enter ].

4.  Press [ 2nd ] (quit) to exit Table mode. 

5.  Recall f(x) and g(x) by pressing [ table ] and selecting the function.


Derivative: 


g(x)  =  ( (f(x + h) - f(x) )/h     [h is sufficiently small, like 0.001]


 or


g(x) = d/dx( f(x) )|x=x


Note:  The TI-30X Pro MathPrint is a European version of the TI-36X Pro.   The TI-36X Pro has only one function memory slot.  


In any calculus problem, set the angle mode to Radians. 



Examples



1.  f(x) = x^3 + 1 from x = 0 to x = 3.  


For this first example, screens are from the Casio fx-991CW.






Arc length ≈ 27.65808204



2.  f(x) = sin x from x = 0 to x = π


Arc length ≈ 3.820197739



3.  f(x) = 4x^2 + 1 from x = 0 to x = 1


Arc length ≈ 1.478942858



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, August 13, 2023

Solving Integral Equations

Solving Integral Equations



Solving integral equations (for the variable A) of any of the following forms:


∫( f(x) dx, x = constant to x = A) = area


∫( f(x) dx, x = A to x = constant) = area


∫( f(x) dx, x = constant to x = constant) = A


is fairly easy with the solve feature on non-graphing scientific calculators such as:


Casio fx-115ES Plus 

Casio fx-991EX

Casio fx-991CW

TI-30X Pro Math Print

TI-36X Pro


The screen shots below show an example, from the Casio fx-991CW (Equation - Solver):




The function must have the variable x as the independent variable. We can designated any other variable to be limit to be solved for; I used the variable a.  


Here, we don't have to worry about the value of x when solving the equation because x is considered a dummy variable in the integral.  



Examples


Solve for A.


Example 1:


∫( e^(-x^2) dx, x = 0 to x = A) = 0.7


Casio fx-991EX:  

A = 0.8861430055,  L-R = 0


TI-30X Pro MathPrint:  

A = 0.8861430055201,  L-R = 0  (this solve took a little time)



Example 2:


∫( e^(-x^2) dx, x = A to x = 2) = 0.13


Casio fx-991EX:  

A = 1.014499933,  L-R = 0


TI-30X Pro MathPrint:  

A = 1.014499933366,  L-R = 0  



Example 3:


∫( A*x + 1 dx, x = 1 to x = 5 ) = 10


Casio fx-991EX:  

A = 0.4,  L-R = 0


TI-30X Pro MathPrint:  

A = 0.4,  L-R = 0  



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, August 12, 2023

HP Prime: Monte Carlo Integration

HP Prime:  Monte Carlo Integration



Integration by Random Points



There are many ways to calculate the area under the curve f(x) in the interval [a, b].     Two of the common are calculating the antiderivative and using the Simpson's Rule.  Another method is the Monte Carlo method.   Unlike Simpson's Rule, where the intervals are fixed, the Monte Carlo method picks random points in interval.  The integral is calculated using the simple formula:


∫ f(x) dx ≈ (b - a) ÷ (n - 1) * Σ( f(x_i), from i = 0 to n)


x_i is a random point in the interval [a, b]

n = number of points, n > 2


How are the random numbers are picked are determined by various methods: pseudo-random generators, using a uniform distribution, using a normal distribution, etc.  


The program MONTE for the HP Prime uses the RANDOM function.  The HP Prime allows to pick a random (real) number in the interval [a , b] by the syntax RANDOM(a,b). 


Note:  I use the Function app function AREA to calculate the integral using any of the system variables F0 through F9.  In trade, the program uses global variables instead of local variables.  



HP Prime Program:  MONTE


Code: 


EXPORT MONTE()

BEGIN

// 2023-06-03 EWS

STARTAPP("Function");

// use input box for global variables

INPUT({A,B,E},"Monte Carlo of F1(X)",

{"lower:","upper:","# places:"}); 

// set radians

HAngle:=0;

// input check

IF A≥B THEN

MSGBOX("Lower limit must be

less than upper limit.");

KILL;

END;

// AREA must be stored to a global var.

I:=Function.AREA(F1(X),A,B);

// initialize variables

N:=1;

S:=0;

// repeat loop

REPEAT 

X:=RANDOM(A,B);

S:=S+F1(X);

N:=N+1;

IF N>1 THEN

J:=(B-A)*S/(N-1);

END;

UNTIL (N>1) AND (ABS(I-J)<ALOG(−E));

// results

PRINT();

PRINT("Results");

PRINT("Actual: "+STRING(I));

PRINT("Approx: "+STRING(J));

PRINT("# terms used: "+STRING(N)); 

// return home

STARTVIEW(−1);  

END;



Examples


Estimate the integral of F1(X) to three decimal places.  Your mileage may vary. 


∫ F1(X) dX from X = A to X = B


Example 1:

F1(X) = X^2 + 1

A = 0,  B  = 3


Exact Integral = 12


Trial 1:  12.0004750664,  64 points

Trial 2:  11.9996447323,  272 points

Trial 3:  12.0001030297,  9 points


Example 2: 

F1(X) = COS(X - 1) 

A = 1,  B = π/2 + 1


Exact Integral = 1


Trial 1:  1.00079319497, 411 points

Trial 2:  .999705900656, 187 points

Trial 3:  1.00071067474, 737 points



Example 3:

F1(X) = SIN X/X

A = 0, B = 4


Exact Integral = Si(4) ≈ 1.75820313895


Trial 1:  1.75789723089, 205 points

Trial 2:  1.75729880586, 133 points

Trial 3:  1.75832553216, 223 points



Notes


While the Monte Carlo method is easy to calculate, it is difficult to get an accurate answer.  The method requires a lot of calculation points, and how many really depends on what random numbers are picked.  It's really the luck of a draw.   This is good for a short approximation but I recommend the Simpson's Rule, Trapezoid Rule, or when possible and feasible, finding the antiderivative instead.  



Source


Cumer, Victor.  "The basics of Monte Carlo integration"  Towards Data Science.   Medium.  October 26, 2020.  Last Retrieved June 4, 2023.  https://towardsdatascience.com/the-basics-of-monte-carlo-integration-5fe16b40482d


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. 


Casio fx-5000F: Auto Formulas

Casio fx-5000F:   Auto Formulas The formula listing can apply to (almost) any calculator that can handle formula programming. In November, t...