Showing posts with label fx-5800p. Show all posts
Showing posts with label fx-5800p. Show all posts

Saturday, March 12, 2022

Casio fx-5800P: Multiplying Big Numbers - Laws of Logarithms

Casio fx-5800P: Multiplying Big Numbers - Laws of Logarithms


Introduction


This post was inspired by a recent video from Scott Collins, where he discussed what happens when multiplying numbers with large valued exponents:


https://www.youtube.com/watch?v=ziMIphyd9wg


Scientific calculators handle large numbers in the form M * 10^E where M is the mantissa and E is the exponent.  For most calculators, E ranges from -99 to +99.   For most Hewlett Packard calculators, the range expands to -499 to +499.  On CAS enabled calculators, the range usually tops out at -999 to +999.


At some point, if the exponent goes too small, say 10^-12 or less, the number is approximated with 0. 


For example, entering 4 *10^-56 * 2 * 10^-76 returns 0 on a lot of calculators, which the real answer is 8 * 10^-132.  


If you work with multiplying numbers of this magnitude, it may be useful to work with the mantissa and exponent parts separately, which can be the done thanks to the laws of exponents:


( A * 10^B ) * ( C * 10^D )

=  A * C * 10^B * 10^D

= ( A * C) * 10^(B + D)


Mantissa:  A * C

Exponent:  B + D


Similarly: 


( A * 10^B )^S * ( C * 10^D )^T

= (A^S * (10^B)^S) * (C^T * (10^D)^T)

= A^S * 10^(B*S) * C^T * 10^(D*T)

= (A^S * C^T) * 10^(B*S + D*T)


The program BIGMULT can automate this process, as well as adjust the answer to scientific notation form: #.####### * 10^# 


Casio fx-5800P Program:  BIGMULT


"(A×10^B)^(S)×(C×10^D)^(T)"

"A"?→A

"B"?→B

"S"?→S

"C"?→C

"D"?→D

"T"?→T

A^(S)×C^(T)→M

B×S+D×T→E

Intg(log(M))→S

M÷10^(S)→M

E+S→E

M ◢

E


The results:

Mantissa

Exponent


Note:  


Intg is the largest/greatest integer function, which allows us to fine tune our answer into the standard format.


Intg(log(M))→S

M÷10^(S)→M

E+S→E


Using the Int/IP (integer part) function would require additional adjustments.  


Examples


Example 1:

4 *10^-56 * 2 * 10^-76 


Input:

A = 4, B = -56, S = 1

C = 2, D = -76, T = 1


Result:

8

-132


8 * 10^-132



Example 2:

(2 * 10^5)^2 * (3 * 10^6)^3


Input:

A = 2, B = 5, S = 2

C = 3, D = 6, T = 3


Result:

1.08

30


1.08^30


Example 3:

(0.076 * 10^3)^2 * (0.9 * 10^2)^3


A = 0.076, B = 3, S = 2

C = 0.9, D = 2, T = 3


Result:

4.210704

9


4.210704 * 10^9



Until the next time,


Eddie


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. 


Monday, February 14, 2022

Casio fx-5800P: Convert to Fractions by Pierre Gillet

 Casio fx-5800P: Convert to Fractions by Pierre Gillet


The program on this blog entry are created and authored by Pierre Gillet.   Gratitude for his permission to post this on my blog.  The program FRAC will show successful approximations of fractions.  Note, the program uses 30 additional registers by the DimZ command.  


Take it away, Pierre.


Casio fx-5800P FRAC and Notes


    Casio fx-5800P:

    "FRAC":

    ?X : Abs(X)->Z

    30->DimZ : 0->W

    Lbl 1    

    W+1->W

    Int(Z)->Z[W]

    Z[W]->R : 1->S

    For W-1->I TO 1 Step -1

    R->T

    Z[I]*R+S->R : T->S

    Next

    Cls : Locate 1,1,R

    Locate 1,2,"÷"

    Locate 2,2,S

    Locate 1,3,"="

    Locate 2,3,R/S

    Locate 1,4,R/S-Abs(X)◢

    1/Frac(Z)->Z

    Goto 1


Notes:


    ⦁ ?X is allowed on the fx-5800P:   When executed, the last value of X is shown which can be accepted or replaced. It doesn't work for the Casio graphing calculators. 

    ⦁ The program works with the absolute value of X

    ⦁ The program uses 30 DimZ extra memories (from Z[1] to Z[30]) by default; If it's not enough, it will display "Dimension ERROR"

    ⦁ The program pauses displays pauses after each step, displaying 4 lines per step, until it suits you:

        ⦁ Numerator

        ⦁ Denominator

        ⦁ Result of the division of Numerator by Denominator

        ⦁ Absolute error, compared to absolute value of X

For example, at the 4th step with X=Pi, the program will display:


        ⦁ 355

        ⦁ ÷113

        ⦁ =3.14159292

        ⦁ 2.6676418x10^-7


    ⦁ The fx-5800P doesn't allow "A=";A  to display "A=8"  (if A=8) 


BUT you can bypass this using Locate <Column>, <Row>, <String or Variable>

For example, in order to display "A=8"  (if A=8)  at the beginning of the first row of the display, do:


    ⦁ Locate 1,1,"A="

    ⦁ Locate 3,1,A



Examples


0.675 -> 27/40 after 4 steps  


2.08080808 -> 26,010,101/12,500,000 with approximately 0 difference


1.37456356 -> 1,812,138/1,318,337  with approximately 0 difference 



Thank you to Pierre Gillet.


Eddie 


All original content copyright, © 2011-2022.  Edward Shore.  Programs provided by Pierre Gillet with permission, © 2022.   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, January 17, 2022

Casio fx-5800P: Lambert Function by Pierre Gillet

Casio fx-5800P: Lambert Function by Pierre Gillet


The programs on this blog entry are created and authored by Pierre Gillet. Gratitude for his permission to post this on my blog.


Introduction


The Lambert function is defined as:


    w = W(x) where  w * e^w = x


W(x) is the inverse of y = x * e^x: so, W(x) * e^(W(x)) = x and W(x * e^x)=x

In all cases, x must be >= -1/e to get a real value of W(x)

For x>=0, there’s only one value of W(x), called W0(x) (« principal branch »   of W(x))

For x<0, two values of W(x) are possible : W0(x) and W-1(x)

In all cases, W0(x) >= -1 and W-1(x) < = -1


The set of programs presented use W(x) to solve equations such as:

    x^x = a

    log x = x - 1

    a^x = b - x

where a and b are real constants.  


The trick to solve these kinds of equation is to transform them into the form

    f(x) * e^f(x) = constant

Then comes

    W(f(x) * e^f(x)) = W(constant)

    f(x) = W(constant) (remember that W(x * e^x) = x)

and then you normally solve easily for x but still have to calculate the above W(constant)


You can calculate W(p) (where p is constant) with the efficient Newton’s method solving the equation x * e^x – p = 0:

To get W0(p) : 

    if -1/e <= p <= 10 then x_0 = 0

    if p > 10  then x_0 = ln(p) – ln(ln(p))   (asymptotic behavior of W0(x))

To get W-1(p) :

    If -1/e <= p <= -0.1 then x_0 = -2

    if p > -0.1 then x_0 = ln(-p) – ln(-ln(-p))   (asymptotic behavior of W-1(x))

    Then iterate x_n = (x^2 + p * e^(-x)) / (x + 1)

      will normally converge to the desired W(p) value


See this post: 

https://math.stackexchange.com/questions/463055/approximation-to-the-lambert-w-function


Programs :


"W0FX"  // The program asks for x and displays W0(x) value (stored in W)

?X:0->G

X>10 => Ln(X)-Ln(Ln(X))->G

Prog "WSUB":W


"W-1FX"  // The program asks for x and displays W-1(x) value (stored in W)

?X:-2->G

X>-.1 => Ln(-X)-Ln(-Ln(-X))->G

Prog "WSUB":W


"WSUB"  // Subroutine called by W0FX and W-1FX

X<-e^(-1) => -1->G

10^(-10)->E:Lbl 1

(G^2+Xe^(-G))/(G+1)->W

Abs(G-W)<E => Return

W->G:Goto 1


Notes:

Precision is 1E-10 (see 10^(-10) in WSUB)

The first line in WSUB ensures Math error if X<-1/e


Note from Edward Shore:

?X is allowed on the fx-5800P:   When executed, the last value of X is shown which can be accepted or replaced.   It doesn't work for the Casio graphing calculators. 


Below is a graph of x*e^x vs. W_0 from W0FX and W_-1 from W-1FX, as created by the Desmos graphing app:




Examples


x^x = 2


    x * ln(x) = ln(2)    

    Let t = ln x (=>x = e^t)

    t * e^t = ln(2)

    W(t * e^t) = W(ln(2))

    t = W(ln(2))

    x= e^W(ln(2))


    Ln(2) is >= 0 => Only one value for W: on W0(x)

    Execute W0FX:

    Type ln(2) then EXE

    The program displays approx 0.4444 (ie W0(ln(2)))

    You are out of the program and now type e^(W)

    The machine displays approx 1.5596 (x value)



log x = x - 1


    x = 10^(x - 1)

    x = 10^x * 10^(-1)

    x = e^(x * ln(10)) * 10^(-1)

    x*e^(-x * ln(10)) = 10^(-1)

    -x * ln(10) * e^(-x * ln(10)) = -10^(-1) * ln(10)

    W(-x * ln(10) * e^(-x * ln(10))) = W(-10^(-1) * ln(10)

    -x * ln(10) = W(-10^(-1) * ln(10)

    x = -W(-10^(-1) * ln(10)) / ln(10)


    -10^(-1) * ln(10))) is < 0 => Two values for W : on W0(x) and W-1(x)

    Execute W0FX:

    Type -10^(-1) * ln(10) then EXE

    The program displays approx -0.3158 (ie W0(-10^(-1) * ln(10)))

    You are out of the program and now type -W / ln(10)

    The machine displays approx 0.1371 (first x value)


    Then Execute W-1FX:

    Press EXE (to keep the current value -10^(-1) * ln(10) in X)  (approx -0.2303)

    The program displays approx -2.3026 (ie W-1(-10^(-1) * ln(10)))

    You are out of the program and now type -W / ln(10)

    The machine displays approx 1 (second x value)


2^x = 11 - x


    Let t = 11-x (=>x = 11-t)

    2^(11 - t) = t

    2^11 * 2^(-t) = t

    2^11 * e^(-t * ln(2)) = t

    e^(-t * ln(2)) = t / (2^11)

    1 = t * e^(t * ln(2)) / (2^11)

    ln(2) = t * ln(2) * e^(t * ln(2)) / (2^11)

    2^11 * ln(2) = t * ln(2) * e^(t * ln(2))

    W(2^11 * ln(2)) = W(t * ln(2) * e^(t * ln(2))

    W(2^11 * ln(2)) = t * ln(2)

    t = W(2^11 * ln(2)) / ln(2)

    x= 11 - W(2^11 * ln(2)) / ln(2)


    2^11 * ln(2) is >= 0 => Only one value for W: on W0(x)

    Execute W0FX:

    Type 2^11*ln(2) then EXE

    The program displays approx 5.5452 (ie W0(2^11 * ln(2)))

    You are out of the program and now type 11 – W / ln(2)

    The machine displays approx 3 (x value)



What for numbers beyond 10^100 ?


Even for small values of the constants involved in an equation, you have        to calculate W(x) with rapidly astronomical arguments :


For example, with the equation 2^x = 1000 – x  (cf the 2^x = 11 – x case), you’d need to calculate W(2^1000 * ln(2)), causing overflow of most of the        calculators.


Here again, you can calculate W(p) (where p is constant) with the efficient        Newton’s method solving this time the equation ln(x) + x - ln(p) = 0, handling ln(p) instead of p:

To get W0(ln(p)): 

    x_0 = ln(p) – ln(ln(p))   (asymptotic behavior of W0(x))

Then iterate:  

x_n = x * (1 - ln(x) + ln(p)) / (x + 1)

will normally converge to W0(p)


Additional programs


"W0FLNX"  // The program asks for ln(x) and displays W0(x) value (stored in W)

?X:0->G

X-Ln(X)->G

Prog "WSUBLN":W


"WSUBLN"  // Subroutine called by W0FLNX

10^(-10)->E:Lbl 1

G(1-Ln(G)+X)/(G+1)->W

Abs(G-W)<E => Return

W->G:Goto 1


Notes:

If p is an excessively large number then W0FLNX asks for ln(p) and returns W0(p). Enter ln(p) in a good way : for example, not ln(10^1000) but 1000 * ln(10)

2nd line in W0FLNX: "X - Ln(X)" is in fact ln(p) - ln(ln(p)) since you entered ln(p) in X


Example


2^x = 1000 - x


    Solution : x = 1000 - W0(2^1000 * ln(2)) / ln(2) 

    (cf the Solve 2^x = 11 - x case)


    2^1000 * ln(2) is >= 0 => Only one value for W: on W0(x)

    2^1000 * ln(2) > 10^100 so you can’t execute W0FX


    Note that ln (2^1000 * ln(2)) = 1000 * ln(2) + ln(ln(2))


    Execute W0FLNX:

    Type 1000 * ln(2) + ln(ln(2))  then EXE

    The program displays approx 686.2494  (ie W0(2^1000 * ln(2)))

    You are out of the program and now type 1000 - W / ln(2)

    The machine displays approx 9.9514 (x value)



Thank you to Pierre Gillet.


Eddie 


All original content copyright, © 2011-2022.  Edward Shore.  Programs provided by Pierre Gillet with permission, © 2022.   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. 


Friday, June 7, 2019

Casio fx-5800P: Cash Flow Program (Pierre Gillet)

Casio fx-5800P:  Cash Flow Program (Pierre Gillet)

Introduction:  Cash Flows Using the Stat List

Today's program comes from Pierre Gillet, who emailed me a set of programs to calculate net present value (NPV) and internal rate of return (IRR) for the Casio fx-5800P.  A key feature is that these programs use the statistical lists List X and List Freq from the SD mode.

There are three programs listed:

"NPV":  calculates Net Present Value.  Store the interest rate in decimal in variable X in Comp mode before running "NPV".

"SOLVE":  solves for the Internal rate of return (IRR) using the secant method.  Again, use decimals for interest rates.  For the IRR, your YTARGET is always 0.

"YFX":  The function to solve.  In this case, YFX refers the program to "NPV".

The programs here are from Pierre Gillet and are presented with permission.

Casio fx-5800P program "NPV"  (Pierre Gillet) 

Notes:
1.  Small n  is from the Statistics variable n.  [ FUNCTION ], 7:  STAT, 2: VAR, 1: n
2.  Call up the Stat lists by:  [ FUNCTION ], 7: STAT, 1: LIST  (1: List, 2:  Freq, or type X for List X)

0 → Y : 1 → U : 2 → W 
Lbl 1
U + List Freq[W] → V
Lbl 2
Y (1 + X) + List X[W] → Y
Isz U
U < V ⇒ Goto 2
Isz W
U < n ⇒ Goto 1
List X[1] + Y ÷ ( ( 1 + X ) ^ ( n - 1 ) ) → Y

Casio fx-5800P program "SOLVE"  (Pierre Gillet)

Note:  Keep recycling the loop with [ EXE ] until an error occurs.  The final result is the IRR (stored in X).

Note: The frequency of the first data point (X[1]) is not considered in the calculation.

"X1" ? → A
"X2" ? → B
"YTARGET" ? → T
A → X : Prog "YFX"
Y - T → R
B → X : Prog "YFX"
Y - T → S
Lbl 1
B - S ( B - A ) ÷ ( S - R ) → C
C → X ⊿
Prog "YFX" : Y - T → Q
A → B : R → S : C → A : Q → R
Goto 1

Casio fx-5800P program "YFX"  (Pierre Gillet)

Prog "NPV"

Example

Go to SD mode.  Make sure that the Frequency is turned on by pressing [ SHIFT ],  ( SETUP), 5: STAT, 1: FreqOn

Data:  List X, Freq
-5600, 1
1300, 1
2500, 1
3000, 1

NPV:  interest rate of 8%.  (store 0.08 in X)

Result:  $128.55

Solve for IRR,  run SOLVE with guesses X1 = 0, X2 = .15, and YTARGET = 0.

Final result:  0.0912 (9.12%)

Thank you Pierre Gillet!

Note: I wasn't called to jury duty - back to normal life for me.  I'm also posting this a day early. 

Eddie

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

Wednesday, November 29, 2017

Casio fx-5800p Special Functions

Casio fx-5800p Special Functions

Programs

An Alternate Way of Extracting the Fraction and Integer Parts of a Number

The fraction part is stored in F, and the integer part is stored in I.  This algorithm can be used when a calculator or programming language does not have a fractional part or integer part function.

This program assumes the program is in Radians mode.

Casio fx-5800P Program FPIP

Rad
0.5    → F
? → X
cos(Ï€X) = 0 ⇒ Goto 1
Abs(X) → F
tan^-1 (tan (Ï€F)) ÷ Ï€ → F
X < 0 ⇒ -F → F
Lbl 1
F /right-triangle ([Shift] [x^2])
X – F → I

Bernoulli Numbers

The program BERNOULLI approximates the Bernoulli number of nth order.

Casio fx-5800P Program BERNOULLI

? → N
If N = 0
Then
1 → B
Goto 1
IfEnd
If Frac(N ÷ 2) ≠ 0
Then
Int( Abs(N – 2) ÷ (N – 2) – 1) ÷ 4 → B
Goto 1
IfEnd
Σ ( (2*J*Ï€)^(-N), J, 1, 250) * (-1)^(N ÷ 2 + 1) * 2 * N! → B
Lbl 1
B

Euler Numbers

The program EULERNUM calculates the Euler number of order n.

Casio fx-5800P Program EULERNUM

? → N
0 → E
Frac(N ÷ 2) ≠ 0 ⇒ Goto 1
(2 ÷ Ï€)^(N + 1) * N! ÷ 5 → E
-1 – 10 * Int(E) → E
Frac(N ÷ 4) ≠ 0 ⇒ Goto 1
4 – E → E
N ≠ 0 ⇒ Goto 1
1   → E
Lbl 1
E

Custom Formulas

How to create custom formulas:  [MODE], 5.  PROG, 1.  NEW, give the name, 3. Formula

To calculate the custom formula, press [CALC], enter the value for T (ignore X because X is a dummy variable).

Sine Integral:   SI:  ∫( sin(X)/X dX,0,T)

Dawson Integral:  DAWSON:  ∫(e^(T^2-X^2) dX,0,T)

Bessel Function, with order N:  BESSEL:  1/Ï€ * ∫(cos(T * sin(X)-N*X) dX,0,T)

Error Function:  ERF:  2/√Ï€ * ∫(e^(-X^2) dX,0,T)

Fresnel Sine:  FRESSIN:  ∫( sin(Ï€*X^2/2) dX,0,T)

Fresnel Cosine: FRESCOS: ∫( cos(Ï€*X^2/2) dX,0,T)

Source:

Jerome Spainer and Keith B. Oldham  An Atlas of Functions Hemisphere Publication Corporation: Washington  1987  ISBN 0-89116-5738-8

Eddie

This blog is property of Edward Shore, 2017

Casio fx-50F/Radio Shack EC-4024 Program Collection: October 2026

Casio fx-50F/Radio Shack EC-4024 Program Collection: October 2026 Notes: * The fx-50F/EC-4024 has a 29 step program space betwe...