Showing posts with label real numbers. Show all posts
Showing posts with label real numbers. Show all posts

Sunday, August 14, 2022

TI 84 Plus CE TI-Basic and TI Nspire CX II Python: Gamma by Multiplication Recursion Property

TI 84 Plus CE TI-Basic and TI Nspire CX II Python:   Gamma by Multiplication Recursion Property


Introduction


The program calculates the gamma function for any real positive number in tenths by the multiplication recursion:


Γ(x + 1) = x * Γ(x)


For example:  


Γ(2.5)

= 1.5 * Γ(1.5)

= 1.5 * 0.5 * Γ(0.5)

≈ 1.5 * 0.5 * 1.772453851

≈ 1.329340388


Reduce x by 1 until 1 is in between 0.1 and 1. 


Gamma Values:


Γ(0.1) = 9.513507699

Γ(0.2) = 4.590843712

Γ(0.3) = 2.991568988

Γ(0.4) = 2.218159544

Γ(0.5) = 1.772453851

Γ(0.6) = 1.489192249

Γ(0.7) = 1.298055333

Γ(0.8) = 1.164229714

Γ(0.9) = 1.068628702

Γ(1) = 1


TI-84 Plus CE Program: GAMMATEN

TI-Basic


Notes:


*  To get the small L to create lists with custom names, get the character with the key strokes:  [ 2nd ] ( list ), OPS, B.  L.   In this listing, I will write L^ to symbolize the lower case L.


* L^TEN is a custom list.


Program listing:


{9.513507699, 4.590843712, 2.991568988, 

2.218159544, 1.772453851, 1.489192249,

1.298055333, 1.164229714, 1.068628702

1}→L^TEN

ClrHome

Disp "GAMMA X (NEAREST 0.1)"

Input "X≥0.1, X?",X

round(X,1)→X

fPart(X)*10→F

If F=0:10→F

1→G

While X>1

G*(X-1)→G

X-1→X

End

G*L^TEN(F)→G

Disp "EST. GAMMA: ", G


TI-NSpire Python Script:  gammaten.py


The code is defined as a function.   


def gammaten(x):

  lten=[9.513507699]

  lten.append(4.590843712)

  lten.append(2.991568988)

  lten.append(2.218159544)

  lten.append(1.772453851)

  lten.append(1.489192249)

  lten.append(1.298055333)

  lten.append(1.164229714)

  lten.append(1.068628702)

  lten.append(1)

  #print("gamma(x) to the nearest 0.1")

  x=round(x,1)

  f=round(10*(x-int(x))-1)

  g=1

  while x>1:

    x-=1

    g*=x

  g*=lten[f]

  return [g,f]


# list[-1] gets last item too

# round integers for accurate results!

# 2022-06-13 EWS


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, January 10, 2022

Retro Review: Sharp EL-9300C

Retro Review:  Sharp EL-9300C 










Quick Facts


Model: EL-9300C

Company: Sharp

Years: 1995 - 2000s  

Type:  Graphing with Programming

Memory:  23,064 bytes (programming, statistics, graph database, solver equations)

Battery:  4 AAA batteries, with 1 CR 2032 backup

Logic:  Algebraic, textbook

Comes with hard case.  The calculator I purchased came had in it's original box and manual.


The EL-9300C is part of the Sharp EL-9200/9300 family.   The earlier EL-9200/EL-9200C, released in 1992, had only 1,800 bytes.   I'm not sure about the difference between the EL-9300 and the EL-9300C.  The average cost of the EL-9300C is relatively inexpensive, around $15 to $25 U.S. dollars.  


Features


*  Mathematics with Calculus 

*  Complex Numbers Mode

*  Matrices

*  Base Mode

*  Graphing:  Function, Polar, Parametric

*  Equation Solver

*  Programming - up to 99 titled programs

*  Statistics with Linear Regression

*  Statistic Graphs with regression of six different regression fits


Mathematics with Calculus 


The EL-9300C (and its graphing family) has a rich set of scientific functions including numerical calculus.  The calculus functions include numeric derivative and numeric integral.


The numeric derivative works on functions in terms of X using the standard definition of the derivative:


f'(x) = (f(x+h) -f(x)) / h,  where h can be designated as an optional argument.   


The numeric integral uses to commands:   ∫ and dx.   The dx must be attached to the end unless an error occurs.  The integral uses calculates the Simpson's Rule   The number of subdivisions can be entered.  It is an early graphing calculator, so expect the calculator to take a few seconds to calculate integrals.  


Unfortunately, simplification of square roots and multiples of π are not included.   The EL-9300 still has fractions and fraction simplification.  


Complex Numbers Mode


For the time, the EL-9300 offers one most expansive set of pre-programmed calculations for complex numbers, which included logarithmic, power, exponential, trigonometric, and hyperbolic functions.  In trade, there the mantissa is 8 digits instead of the normal 10, and the complex mode is still separate.  


Matrices


Matrices are available, but they are in a separate mode.   Matrices are edited, created, and deleted through the MENU key, while called up by using the "mat" suffix through the MATH-E-1 keystrokes.


Basic row operations, inverse, transpose, and determinant.  


Base Mode


Base mode that allows logic operations for decimal, binary, hexadecimals, and octal integers are offered.  


Regardless of display mode, all matrices are show by the matrix's columns.  


Graphing:  Function, Polar, Parametric


The EL-9300C has three graphing modes, accessed through the SET UP menu.  If the calculator is in text mode, the function screen only displayed one equation at a time.  The graphing speed is fairly decent.  


Equation Solver


The solver is advanced, allowing for multi-character variables.  There are three methods:  Equation (where exact methods are used when available), Newton (using Newton's Method), and Graphic method.  


Newton's Method:  x_n+1 = x_n - f(x_n) ÷ f'(x_n)


Each equation can be saved and loaded into memory.  


Note, the equation solver is not available on the EL-9200.  


Programming 


The programming model is a basic version of basic.  Like the Equation Solver, multi-character variables are allowed.   There is a basic set of graphing commands.  The Input command included an automatic prompt.  For example:


Input base  returned  base? 


The automatic prompting will require getting used to.  


Loops, both conditional and unconditional, are handled by the use of Goto and Label.  


The EL-9300 can store up to 99 named programs.


The mode (Real, Matrix, N-Base, Complex) must be determined prior to creating a program.  Unfortunately, I have no way to change the SET UP in the program, such as fix settings, angle mode, and coordinate/graphing mode, we have to keep this mind.  


Statistics 


The statistics mode uses an index card interface.   There are four entry modes:


*  one variable

*  one variable with weights

*  two variable

*  two variable with weights


There is a one set of data and it must be cleared through the Delete Data (or Delete All) through the OPTION menu.  Statistical data can be calculated and graphed.  The EL-9300C offers up to six regression models (see below), but unfortunately, they are only available in graphing mode:


1.  y = a + b ∙ x   (linear)

2.  y = a ∙ e^(b ∙ x)  (exponential)

3.  y = a + b ∙ ln x  (logarithmic)

4.  y = a + b ∙ log x (common logarithmic)

5.  y = a ∙ x^b   (power)

6.  y = a + b ∙ x^-1  (inverse)


Common logarithmic is very unique, probably only offered on the EL-9200, EL-9300, and EL-9600 series.  


In calculation mode, we only have linear regression.  


One really cool feature of the Statistics mode, which will most likely not be able to found anywhere else is the ability to mask data.   A masked data point turns that data point "off", temporarily excluding the data point from calculation.  


Verdict


I like the perks of the EL-9300:  the ability to mask data points in statistics, extensive set of complex number commands,  the ability to save equations and use multi-character variable names (especially when most graphing calculators allowed only one-character variables, mainly A-Z and θ).  


However, be prepared to use separate modes for matrices, complex numbers, and general calculations (real mode).   The lack of set up commands in program will provide a challenge, and have to be set prior to running the programs.  


For the price, I find that the calculator is a good buy.  



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. 


Sunday, August 2, 2020

HP Prime and Casio fx-CG 50: Binary Conversions

HP Prime and Casio fx-CG 50:   Binary Conversions 

x = 2 * (1 + n)^p

The program DECOM2 takes a real number, x, and decomposes it to the form of:

x = 2 * (1 + n)^p

HP Prime Program:  DECOMP2

EXPORT DECOMP2(x)
BEGIN
// 2020-07-11 EWS
// x → 2^p*(1+n)
LOCAL s,p,n,str;
s:=ABS(x);
p:=FLOOR(LOG(s)/LOG(2));
n:=s/2^p-1;
str:=STRING(SIGN(X))+"*2^"+STRING(p)+
"*(1+"+STRING(n)+")";
RETURN str;
END;

Casio fx-CG 50 Program:  DECOMP2
188 bytes

"2020-07-11 EWS"
"X"? → X
Abs X → S
Int (log S ÷ log 2) → P
S < 1 ⇒ P - 1 → P 
S ÷ 2^P - 1 → N
X ÷ S → T
ClrText
Locate 1, 3, X
Locate 18, 3, "="
Locate 1, 5, T
Locate 4, 5, "×2^"
Locate 9, 5, P
Locate 18, 5, "×"
Locate 1, 6, "(1+"
Locate 5, 6, N
Locate 18, 6, ")"

Examples:

-720 = -1 * 2^9 * (1 + 0.40625)

0.7868 = 1 * 2^-1 * (1 + 0.5736)

Converting Numbers to Binary

The program RBIN converts any real number in base 10 to base 2, including non-integers and negative numbers.  The result is displayed as a string.   The HP Prime program has one string for output while the Casio fx-CG 50 uses two:  Str1 for the integer part and Str2 for the fractional part.

RBIN will need two arguments:  the number to be converted and the precision level.

For the precision level:

1 rounds the number to the nearest 1/2 before conversion.

2 rounds the number to the nearest 1/4 before conversion.

3 rounds the number to the nearest 1/8 before conversion.

4 rounds the number to the nearest 1/16 before conversion.

and so on.

HP Prime Program:  RBIN

EXPORT RBIN(x,p)
BEGIN
// 2020-07-11 EWS
// Decimal to Binary
// decimal, precision
// for real x, rounded 1/2^p

LOCAL b,i,f,n,s,w,k,str;
s:=ABS(x);
b:=IP(s)+ROUND(FP(s)*2^p,0)/2^p;
str:="";
i:=IP(b);
f:=FP(b);

IF i≠0 THEN
n:=IP(LOG(i)/LOG(2));
FOR k FROM n DOWNTO 0 STEP 1 DO
w:=IP(i/2^k);
str:=str+STRING(w);
i:=i-w*2^k; 
END;
END;

IF f≠0 THEN
str:=str+".";
FOR k FROM 0 TO p-1 DO
w:=IP(2*f);
str:=str+STRING(w);
f:=FP(2*f);
END;
END;

IF x<0 font="" then="">
str:="-"+str;
END;

RETURN str;
END;

Casio fx-CG 50:  RBIN
372 bytes

"2020-07-11 EWS"
"DEC>BIN: NUM"? → X
"PRECISION"? → P

Abs X → S
Int S + RndFix(Frac S × 2^P, 0) ÷ 2^P → B
" " → Str 1
Int B → I
Frac B → F

If I ≠ 0
Then
Int (log I ÷ log 2) → N
For N → K To 0 Step -1
Int (I ÷ 2^K) → W
W = 0 ⇒ Str 1 + "0" → Str 1
W = 1 ⇒ Str 1 + "1" → Str 1
I - W × 2^K → I
Next
IfEnd

" " → Str 2
If F ≠ 0
Then
"." → Str 2
For 0 → K To P-1
Int (2F) → W
W = 0 ⇒ Str 2 + "0" → Str 2
W = 1 ⇒ Str 2 + "1" → Str 2
Frac (2F) → F
Next
IfEnd

X < 0 ⇒ "-" + Str 1 → Str 1

ClrText
Locate 1, 3, X
Locate 20, 3, "="
Locate 1, 5, Str 1
Locate 1, 6, Str 2

Examples:

RBIN(-0.985,3) returns "-1"
RBIN(-0.985,6) returns "-.111111"
RBIN(-0.985,9) returns "-.111111000"

RBIN(860.63,3) returns "1101011100.101"
RBIN(860.63,6) returns "1101011100.101000"
RBIN(860.63,9) returns "1101011100.101000011"

Take care,

Eddie

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