Sunday, February 18, 2024

Casio fx-CG 50 CORDIC Simulation: Approximating Sine and Cosine of Angles

Casio fx-CG 50 CORDIC Simulation:  Approximating Sine and Cosine of Angles




Introduction - How Computers Calculate Mathematical Functions



First developed by Jack E. Volder, the Coordinate Rotation Digital Computer, better known as CORDIC, is an algorithm used to calculate many mathematical functions, including trigonometric functions, logarithms, exponentials, and hyperbolic functions.     CORDIC is a fundamental algorithm, which variants of CORDIC are used in computers and calculators.


Today's focus will be a calculating sines and cosines of angles.  The steps will be detailed in the next sections.  



CORDIC1:  Series of Arctangents


Let Θ be the angle.   The first step is to build Θ as additions and subtractions of terms of arctan(1 ÷ (2^n)), starting at n = 0 and stopping at the required accuracy.  Let A be the approximation.  


Examples: 


Θ = 45° requires only one term:

A = 45° = arctan 1


Θ ≈ 71.56505118°

 A = 71.56505118° = arctan 1 + arctan 1/2


Θ ≈ 32.47119229°

A = 32.47119229° = arctan 1 - arctan 1/2 + arctan 1/4


A series to recreate Θ = 30° takes 32 terms of ±arctan (1 ÷ 2^n) from n = 0 to n = 31.   (8 decimal places)  This is known as coordinate rotation.


The program CORDIC1 determines the number of terms need to created to obtain Θ.   Accuracy in this code is set to 5 decimal places, but can be adjusted (see the line in blue).  


Casio fx-CG 50 Program Code:  CORDIC1


Deg

"ANGLE"?->Θ

0->I

0->A


Lbl 0

tan^-1 (2^(-I))->T

If A<Θ

Then 

A+T->A

Else 

A-T->A

IfEnd


I+1->I


Abs (A-Θ)>1×10^-5=>Goto 0


ClrText

Blue Locate 1,3,"Θ: "

Blue Locate 5,3,Θ


Red Locate 1,4,"A: "

Red Locate 5,4,A


Green Locate 1,7,I


Notes:

-> is the store arrow →

=> is the jump command ⇒


For reference:


arctan 1 = 45°

arctan 1/2 ≈ 26.56505118°

arctan 1/4 ≈ 14.03624347°

arctan 1/8 ≈ 7.125016349°

arctan 1/16 ≈ 3.576334375°

arctan 1/32 ≈ 1.789910608°


CORDIC2:  Calculating Sine and Cosine


Imagine the coordinate (cos Θ, sin Θ) on a unit circle.  A unit circle is a circle with radius of length 1 and center located at the origin (0,0).   


Set the initial angle at 0°.  Then x = cos 0° = 1 and y = sin 0° = 0.   The initial vector is set to be [ [ cos 0° ] [ sin 0° ] ] = [ [ 1 ] [ 0 ] ].


Approximate Θ in terms of arctangent (1 ÷ (2^n)), starting at n = 0.  



Direction of Rotation


Set σ as the direction of rotation.    


A rotation is positive if we add arctan(1 ÷ (2^n)) to A.    For a positive rotation, set σ_i = +1.   


A rotation is negative if we subtract arctan(1 ÷ (2^n)) to A.    For a negative rotation, set σ_i = -1.   


For example:


 Θ ≈ 32.47119229°

A = 32.47119229° = arctan 1 - arctan 1/2 + arctan 1/4


Then:  σ_0 = 1 (positive rotation), σ_1 = -1 (negative rotation), σ_2 =  1 (positive rotation).  



Multiplying Factor


The number of iterations is also used to determine the required multiplication factor:


n = Π( 1 ÷ √(1 + 2^(-2 × I)), I = 0 to I = terms needed - 1)


For the example:


 Θ ≈ 32.47119229°

Needed 3 iterations, i_0 to i_2.  


Then:

n = 1 ÷ √(1 + 2^(-2 × 0)) × 1 ÷ √(1 + 2^(-2 × 1)) × 1 ÷ √(1 + 2^(-2 × 2))

= 4 × √170 ÷ 85

≈ 0.6135719911



Calculating the Next Iteration


The next iteration for x and y are:


x_i+1 = x_i - 2^(-i) × σ_i × y_i


y_i+1 = 2^(-i) × σ_i × x_i + y_i


When A is sufficiently near or equal to Θ, the cosine and sine are approximated as:


cos(A) ≈ n × x_final


sin(A) ≈ n × y_final


For the example:

 Θ ≈ 32.47119229°


The approximated angle, in this case, happens to be exact angle, A = Θ.  And,

cos(A) ≈ 0.8436614877 

sin(A) ≈ 0.5368754922


For more details, please check out resources in the Sources section.   I particularly like Oxford's A Very Short Introduction series.  



Casio fx-CG 50 Program Code:  CORDIC2


This algorithm is adopted from the Python example (see Wikipedia article).  


Deg

"ANGLE"?->Θ


0->I

0->A

1->X

0->Y

1->N


Lbl 0

tan^-1 (2^(-I))->T

If A<Θ

Then 

A+T->A

1->S

Else 

A-T->A

-1->S

IfEnd

N÷√(1+2^(-2*I))->N

X-S*2^(-I)*Y->P

Y+X*S*2^(-I)->Q

P->X

Q->Y


I+1->I


Abs (A-Θ)>1×10^-5=>Goto 0

X*N->X

Y*N->Y


ClrText

Blue Locate 1,3,"Θ: "

Blue Locate 5,3,Θ


Red Locate 1,4,"A: "

Red Locate 5,4,A


Black Locate 1,5,"cos :"

Black Locate 7,5,X

Black Locate 1,6,"sin :"

Black Locate 7,6,Y


Green Locate 1,7,I



CORDIC3:  Doing it without a Arctangent function


In reality, most of the time the arctangent function also has to be approximated.   There are many ways to approximate, which varying accuracy.   I used the fx-CG50's statistics mode to come up with a regression equation with the following lists:


x_list = sequence of 1÷(2^i) from i = 0 to i = 39 


y_list = sequence of arctan(1÷(2^i)) from i = 0 to i = 39


Of the regression models the fx-CG50 offers, the best regression model is quartic regression (4th-order polynomial):


y ≈ 9.43597784 × x^4 - 22.116232 × x^3 + 0.40116676 × x^2 + 57.2790727 × x + 1.4558 × 10^-5


Remember that I am working with degree angle measurement.  





Casio fx-CG 50 Program Code:  CORDIC3


Deg

"ANGLE"?->Θ


0->I

0->A

1->X

0->Y

1->N


Lbl 0

2^(-I)->K

9.43597784917955K^(4)-22.1162323028173K^(3)+

0.401166766193516K^2+57.2790727477367K+

1.45584715586876×10^-5->T


If A<Θ

Then 

A+T->A

1->S

Else 

A-T->A

-1->S

IfEnd

N÷√(1+2^(-2*I))->N

X-S*2^(-I)*Y->P

Y+X*S*2^(-I)->Q

P->X

Q->Y


I+1->I


Abs (A-Θ)>1×10^-5=>Goto 0

X*N->X

Y*N->Y


ClrText

Blue Locate 1,3,"Θ: "

Blue Locate 5,3,Θ


Red Locate 1,4,"A: "

Red Locate 5,4,A


Black Locate 1,5,"cos :"

Black Locate 7,5,X

Black Locate 1,6,"sin :"

Black Locate 7,6,Y


Green Locate 1,7,I


For the example:

 Θ ≈ 32.47119229°


Approximating Θ within 8 decimal places (10^-5) yields these results:

A:  32.47118598

cos A:  0.8436683456

sin A:  0.5368647154

24 terms used



Sources


"CORDIC"  Wikipedia.   Last Edited January 11, 2024.   Accessed January 12, 2024.  https://en.wikipedia.org/wiki/CORDIC


Brummelen, Glen Van.  Trigonometry:  A Very Short Introduction  Oxford University Press: Oxford, United Kingdom.  2020.  ISBN 978-0-19-881431-3



Eddie


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

TI-30Xa Algorithms: Annuity Factors

TI-30Xa Algorithms:   Annuity Factors




Introduction


Even when a calculator isn't (technically) programmable, algorithms can be applied to scientific and financial calculations.


The calculations take numerical arguments that are stored in the TI-30Xa's three memory slots:  M1, M2, and M3.  Store amounts into the memory registers by the [ STO ] key.  


Careful:  For the solar versions of the TI-30Xa, do not press the [ON/AC] button as doing so clears the memory registers.



Today's list of routines deals with annuity factors.



SPFV:  Future Value of a Single Present Value Factor


SPFV = (1 + i%)^n


FV = PV × SPFV



SPPV:  Present Value of a Single Future Value Factor


SPPV = (1 + i%)^(-n)


PV = FV × SPPV



USFV:  Future Value of a Payment Stream Factor


USFV = ((1 + i%)^n - 1) ÷ i%


FV = PMT × USFV



USPV:  Present Value of a Payment Stream Factor


USPV = (1 - (1 + i%)^(-n)) ÷ i%


PV = PMT × USPV



where:

PV = present value

PMT = payment

FV = future value

n = number of periods

i% = periodic interest rate


For monthly payments per year:

n = number of years × 12

i% = annual interest rate ÷ 12


For quarterly payments per year:  

n = number of years × 4

i% = annual interest rate ÷ 4


For the routines, n is stored in memory register 1 and i% is stored in memory register 2. 


n [ STO ] 1 

i% [ STO ] 2




SPFV:  Future Value of a Single Present Value Factor


 [ ( ] 1 [ + ] [ RCL ] 2 [ 2nd ] { % } [ ) ] [ y^x ] [ RCL ] 1 [ = ]


SPPV:  Present Value of a Single Future Value Factor


 [ ( ] 1 [ + ] [ RCL ] 2 [ 2nd ] { % } [ ) ] [ y^x ] [ RCL ] 1 [ ± ] [ = ]


USFV:  Future Value of a Payment Stream Factor


[ ( ] [ ( ] 1 [ + ] [ RCL ] 2 [ 2nd ] { % } [ ) ] [ y^x ] [ RCL ] 1 [ - ] 1 [ ) ] 

[ ÷ ] [ RCL ] 2 [ 2nd ] { % } [ = ]


USPV:  Present Value of a Payment Stream Factor


[ ( ] 1 [ - ] [ ( ] 1 [ + ] [ RCL ] 2 [ 2nd ] { % } [ ) ] [ y^x ] [ RCL ] 1 [ ± ] [ ) ]

[ ÷ ] [ RCL ] 2 [ 2nd ] { % } [ = ]



Example


Let n = 60, i% = 5  


60 [ STO ] 1

5 [ STO ] 2


SPFV:  18.67918589

SPPV:  0.053535524

USFV:  353.5837179

USPV:  18.92928953



Eddie


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

Spotlight: Casio CFX-9850GB Plus

Spotlight:   Casio CFX-9850GB Plus 

(Retro Review)







Quick Facts


Model:  CFX-9850GB Plus

Company:  Casio

Timeline:  late 1990s (circa 1997) to 2008

Type:   Graphing, Algebraic, floating decimal with fractions

Number of Digits:  10

Power:  4 AAA batteries plus CR 2032 backup

Colors:  orange, blue, green

Screen Size:  128 x 64 pixels


There are two versions of the CFX-9850GB Plus:  


*  First edition (1997 - 2002):  Black case, black slide cover, about 32,000 bytes of memory.   


*  Second edition (2002 - 2008):  White case, green cover, about 64,000 bytes of memory.


I have the first edition.   Even though this calculator is no longer in production, the CFX-9850G series is still available through online sites such as eBay and thrift stores.  I purchased mine on eBay from Petchiart Shop.  



Graphing in Color


The CFX-9850G series is the first series of calculators to include a multicolored display.   Graphs, tables, statistical plots, and sequences can be displayed in up to three colors:  blue, green, and orange.  


How were the colors accomplished?  Colors are determined by the contrast of the pixels.  Pixels with the lightest contrast are displayed as orange.  Pixels with a medium contrast are displayed as blue.  Pixels with the darkest contrast are displayed as green.  


Text and regular calculations are shown in blue.  We can change the color of the text to green or orange through [OPTN], [F6] (>), [F1] (COLR).   Blue text is the default.  



Calculator Modes


1  Run:  Main Calculator

2  Statistics:  Statistics. Regressions include linear, med-med, quadratic, cubic, quartic, logarithmic, exponential, power, sinusoidal, and logistic.

3  Matrices:  Matrix editing and manipulation mode

4  Lists:  List editing and manipulation mode.  Up to six lists can be stored (List 1 - List 6)

5  Graphing:  Functions with and without shading (Y(X)), Polar (r(Θ)), Parametric (X(T), Y(T)), Horizontal Lines (x=c) 

6  Dynamic Graphing:  Leave one variable to change during graphing

7  Tables

8  Recursion:  graphing recursion sequences

9  Conics:  graphing conics using templates

A  Equation:  Simultaneous linear systems to the order of 6 equations, quadratic polynomials, cubic polynomials, general solver

B  Program:  Programs can be write-protected with a password if desired. 

C  TVM:  Finance including simple interest, compound interest, amortization, cost/sell/margin, date addition, days between dates

D  Link

E  Contrast menu

F  Memory Manager



Also included through the [OPTN] key:


Complex numbers:  arithmetic, parts (real, imaginary, absolute value, argument/angle), conjugate


Hyperbolic functions


Probability functions


Numeric function including fractional and integer parts, rounding function (internally round the number to fix settings).


Angle:  Angle units including decimal degrees/degree-minute-second conversions


Logic:  AND, OR, NOT.   The calculator has integer modes (decimal, octal, hexadecimal, binary).  


Function Memory:  store up to 6 functions for recall.   


ESYM:  engineering suffixes (mega, micro, etc)



The calculator is run in LineIO format (linear).  There is no textbook mode or an exact function when it comes to terms of pi (π) or square roots (√).



Peripherals


To transfer files between the calculator and a computer, the CFX-9850GB Plus uses an FA-123 connection cable.  If this calculator is not purchased new or like new, the cable will have to be a separate purchase, which may not be an easy find.   I believe the FA-123 is a USB cable.   


There is a SB-62 cable which connects the calculator to a class of Casio label printers, such as the Casio KL-2000 Printer.   



Built-In Library



What separates the CFX-9850GB PLUS (and the CFX-9950GB PLUS) from the rest of the series is the inclusion of a built in software library which can be loaded into the calculator's memory at any time.   All of the library's programs are write-protected and require a password to edit.  I don't know the password, sorry.


The software library includes programs that used the EA-100 data analyzer,  differential equations, drawing Mandelbrot sets, geometry, amortization, complex number powers and roots, double and triple integrals, and slope filed graphs.  (not an all-inclusive list).


I want to try them all.



Comparison of the Color Calculators  (vs. fx-CG 50)


I want to close out this spotlight by comparing the CFX-9850 PLUS with its LCD contrast pixels versus the current Casio fx-CG 50, a full-color graphing calculator.  


In the following pictures, the fx-CG50 is on the left, the CFX-9850GB PLUS is on the right. 








Sources


"CFX-9850G PLUS"   Casio Ledudu.  2022.   Accessed January 9, 2024.  https://casio.ledudu.com/pockets.asp?type=280&lg=eng

(this link includes the main manual)


"Casio 9850 series"  Wikipedia.  Last Edited May 14, 2023.  Accessed December 30, 2023.  https://en.wikipedia.org/wiki/Casio_9850_series


Casio.   Casio CFX9850GB Plus Software Library.  https://support.casio.com/en/manual/manualfile.php?cid=004013009

Accessed December 30, 2023. 


Vis, Peter. "Casio Serial Cable Compatibility"   The Quantum Archive.   Accessed January 9, 2024.  https://www.petervis.com/electronics%20guides/Casio%20Serial%20Cables/Casio%20Serial%20Cable%20Compatibility.html




I am always impressed with Casio graphing calculators.   Often, they give the most functions and capability for the least money.  Money well spent.  


Eddie


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

Spotlight: Aristo Multilog Nr. 970 Slide Rule

Spotlight: Aristo Multilog Nr. 970 Slide Rule



Release Year:  1954


Santa Barbara and Carpentaria, California, are two of my favorite places to visit.   While on vacation in December 2023 in Santa Barbara, I bought a Aristo Nr. Slide Rule at Antique Alley.  








Not only did the slide rule have a nice, hard case, the slide rule is large. The slide rule also has a functional description of each scale.  I also like the slide rule uses two colors, black and brown, to distinguish the scales from each other.  





Side 1:


LL00:   e^(-0.001X)

K:  X^3  (K = D^3)

A:  X^2  (A = D^2)

CF:  πX  

CIF:  1/(πX)

L:  lg X  (log X)

CI:  1/X

C:  X

D:  X

DI:  1/X

LL0:  e^(0.001X)




Side 2:


LL01:  e^(-0.01X)

LL02:  e^(-0.1X)

LL03:  e^(-X)

DF:  πX

B:  X^2

T:  ∡tg   (tan X, X is in degrees, tan D° = T)

ST:  ∡arc  (tan X, sin X)

S:  ∡sin  (arcsin X, sin D° = T) 

C:  X

D:  X 

LL3:  e^X  (LL3 = e^D)

LL2:  e^(0.1X)

LL1:  e^(0.01X)


As a bonus, the slide rule came with a reference card.  One one side is the Dietzgen Slide Rule Conversion Tables  (U.S. and SI units, 1950), and other side is a table of common areas, surface areas, volumes, and trigonometric properties of the right triangle.   I don't know if this was standard addition when the Aristo Multilog Nr. 970 was sold.  


This may be my favorite slide rule:  not only the scales are large (and as a result easier on the eyes to read), but the fact that there are function descriptions on the scales is a big plus.  


Eddie


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

Some RPN Routines: Including Maximum and Minimum of Two Numbers

Some RPN Routines:  Including Maximum and Minimum of Two Numbers



Here are some RPN routines that hopefully you find helpful.   I am assuming that the values are stored in memory registers before calculation and a general four-level stack is used (HP 11C, 12C, 15C, 42S, 32S, 32SII, DM41X, DM32, DM42, DM15, WP34, etc.).  



(a + b + c) × (a + b - c)


Assume that: 

Memory register 1 = a

Memory register 2 = b

Memory register 3 = c

(Your memory registers may have different names or labels)



If recall arithmetic is allowed:


RCL 3

RCL 1

RCL+ 2

+

LST x

RCL- 3

×


(LST x = LAST x)


If recall arithmetic isn't available:


RCL 3

RCL 1

RCL 2

+

+

LST x

RCL 3

-

×



Example:  a= 10, b = 2, c = 7.   Result:  95



 (s + a) × (s + b) × (s + c)


Assume that: 

Memory register 1 = a

Memory register 2 = b

Memory register 3 = c

Memory register 4 = s

(Your memory registers may have different names or labels)


If recall arithmetic is allowed:


RCL 4

ENTER

ENTER

ENTER

RCL+ 1

x<>y

RCL+ 2

×

x<>y

RCL+ 3

×


If recall arithmetic isn't available:


RCL 4

ENTER

ENTER

ENTER

RCL 1

+

x<>y

RCL 2

+

×

x<>y

RCL 3

+

×


Example:  a = 4, b = 8, c = 2, s = 3.   Result:  385



 (s - a) × (s - b) × (s - c)


Assume that: 

Memory register 1 = a

Memory register 2 = b

Memory register 3 = c

Memory register 4 = s

(Your memory registers may have different names or labels)


If recall arithmetic is allowed:


RCL 4

ENTER

ENTER

ENTER

RCL- 1

x<>y

RCL- 2

×

x<>y

RCL- 3

×


If recall arithmetic isn't available:


RCL 4

ENTER

ENTER

ENTER

RCL 1

-

x<>y

RCL 2

-

×

x<>y

RCL 3

-

×


Example:  a = 8, b = 10, c = 3, s = 24.   Result:  4,704



The Maximum and Minimum of the X and Y Stacks



In a program, we can arrange the stack to show the maximum and minimum between two numbers as follows:



Maximum on the X Stack, Minimum on the Y Stack:


...

x≤y   

x<>y

...


If the value of x is less than or equal to y, swap the stack values.  Otherwise, leave the stack as is.



Minimum on the X Stack, Maximum on the X Stack:


HP 12C, HP 11C, HP 10C, and the HP 41C/DM41 family, due to the lack of the  x≥y command:


... 

x≤y

x<>y

x<>y

...


Same routine as the maximum routine, except an extra swap command is placed.



All others:


... 

x≥y

x<>y

...


x≥y is TEST 9 on the HP 15C.  


If the value of x is greater than or equal to y, swap the stack values.  Otherwise, leave the stack as is.

Of course, if your calculator has the maximum (MAX) and minimum (MIN) functions, by all means, use them.  



Eddie


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

Swiss Micros DM42 and TI-84 Plus: Sum of an Infinite Geometric Series

Swiss Micros DM42 and TI-84 Plus:  Sum of an Infinite Geometric Series



Introduction


An infinite geometric series has the form:


a + a × r + a × r^2 + a × r^3 + ...


= a × (1 + r + r^2 + r^3 + ....)



If |r| < 1, the series converges and a sum exists. 


Σ  a × r^n   =   a ÷ (1 - r)

n=0


Σ  a × r^(n-1)   =   a ÷ (1 - r)

n=1


However if |r| ≥ 1, the series diverges and does not have as sum.



DM42 Program:  GSUM


Calculators: DM42, HP 42S, Free42, Plus42


00 { 36-Byte Prgm }

01 LBL "GSUM"

02 ENTER

03 ABS

04 1

05 X<>Y

06 X>Y?

07 GTO 00

08 R↓

09 R↓

10 1

11 X<>Y

12 -

13 ÷

14 RTN

15 LBL 00

16 CLX

17 "DIVERGES"

18 AVIEW

19 .END.


In the case the series diverges, the X stack is cleared (displays 0).  



TI-84 Plus Program:  GSUM


Calculators:  TI-84 Plus, TI-84 Plus CE (Python), TI-83 Premium CE (Python)


Disp "Σ(A*R^N,0,INF)","Σ(A*R^(N-1),1,I)"

Prompt A,R

ClrHome

Disp "A=",A,"R=",R

If abs(R)<1

Then

A/(1-R)→S

Disp "SUM=",S

Else

Disp "DIVERGES"

End



Examples


A:  3,  R:  -0.2

Stack:  Y = 3, X = -0.2

Result = 2.5


A:  3,  R:  0.2

Stack:  Y = 3, X = -0.2

Result = 3.75


A:  3,  R:  -2.2

Stack:  Y = 3, X = -2.2

Result = diverges


A:  3,  R:  2.2

Stack:  Y = 3, X = 2.2

Result = diverges



Eddie


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

Swiss Micros DM42 and TI-84 Plus: Sum of an Infinite Geometric Series

Swiss Micros DM42 and TI-84 Plus:  Sum of an Infinite Geometric Series



Introduction


An infinite geometric series has the form:


a + a × r + a × r^2 + a × r^3 + ...


= a × (1 + r + r^2 + r^3 + ....)



If |r| < 1, the series converges and a sum exists. 


Σ  a × r^n   =   a ÷ (1 - r)

n=0


Σ  a × r^(n-1)   =   a ÷ (1 - r)

n=1


However if |r| ≥ 1, the series diverges and does not have as sum.



DM42 Program:  GSUM


Calculators: DM42, HP 42S, Free42, Plus42


00 { 36-Byte Prgm }

01▸LBL "GSUM"

02 ENTER

03 ABS

04 1

05 X<>Y

06 X>Y?

07 GTO 00

08 R↓

09 R↓

10 1

11 X<>Y

12 -

13 ÷

14 RTN

15▸LBL 00

16 CLX

17 "DIVERGES"

18 AVIEW

19 .END.


In the case the series diverges, the X stack is cleared (displays 0).  



TI-84 Plus Program:  GSUM


Calculators:  TI-84 Plus, TI-84 Plus CE (Python), TI-83 Premium CE (Python)


Disp "Σ(A*R^N,0,INF)","Σ(A*R^(N-1),1,I)"

Prompt A,R

ClrHome

Disp "A=",A,"R=",R

If abs(R)<1

Then

A/(1-R)→S

Disp "SUM=",S

Else

Disp "DIVERGES"

End



Examples


A:  3,  R:  -0.2

Stack:  Y = 3, X = -0.2

Result = 2.5


A:  3,  R:  0.2

Stack:  Y = 3, X = -0.2

Result = 3.75


A:  3,  R:  -2.2

Stack:  Y = 3, X = -2.2

Result = diverges


A:  3,  R:  2.2

Stack:  Y = 3, X = 2.2

Result = diverges



Eddie


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

HP Prime - Restart and Some CAS Command Comparisons

HP Prime - Restart and Some CAS Command Comparisons


restart - A Rescue in CAS Mode

I learned about this command in a recent HPCC virtual meeting about the command restart.   One of the participants had trouble storing equations in variables.   After changing settings and trying other formats, the restart command was introduced and it solved the problem.  

What the restart command does is purge all the variables in CAS variables and reset all CAS settings.    The restart command can be typed or found in the Catalog.
The command does not require arguments.

When the restart command, the screen will show:

============== restarted ==============

Pressing enter will show a list of the CAS variables in a list.  



Some CAS Command Comparisons


ifactor vs. ifactors

ifactor gives the prime factorization of integers.

ifactors returns a list of prime factors with the associated multiplicity in a list in the format:    
[ factor1, multiplicity1, factor2, multiplicity2, ... ]


Examples:


ifactor(480) returns 2^5 * 3 * 5

ifactors(480) returns [2, 5, 3, 1, 5, 1]


ifactor(507) returns 3 * 13^2

ifactors(507) returns [3, 1, 13, 2]


normal vs. regroup

Both the normal and regroup commands can be found in the catalog or can be typed.  According to the help facility:

normal simplifies an expression to an irreducible form.

regroup simplifies and collects terms in an expression, to match the Minimum simplification setting.  


Examples:


normal(a*(b+a-b^2)) returns a^2-a*b^2+a*b

regroup(a*(b+a-b^2)) returns a*(-b^2+a*b)


normal(x+5*x+6*(x^2-3*x)) returns 6*x^2-12*x

regroup(x+5*x+6*(x^2-3*x)) returns 6*(x^2-3*x)+6*x


normal(x^2*√2-(x^3-1)/(x+1)) returns ((√2-1)*x^3+2*√2*x^2+1)/(x+2)

regroup(x^2*√2-(x^3-1)/(x+1)) returns √2*x^2-(x^3-1)/(x+2)


normal((x+3)^5) returns x^5+15*x^4+90*x^3+270*x^2+405*x+243

regroup((x+3)^5) just returns (x+3)^5


iquo vs irem vs. iquorem

The three commands iquo, irem, and iquorem are commands in Euclidean Division.

iquo(x,y) returns the quotient of x/y

irem(x,y)  returns the remainder of x/y

iquorem(x,y)  returns the quotient and remainder of x/y in a list.

The arguments x and y must be positive integers.  


Examples:


iquo(258,19) returns 13

irem(258,19) returns 11

iquorem(258,19) returns [13, 11]

258 = 13 * 19 + 11



I really need to work with the CAS engine of the HP Prime more often,

Eddie

All original content copyright, © 2011-2024.  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-CG 50 CORDIC Simulation: Approximating Sine and Cosine of Angles

Casio fx-CG 50 CORDIC Simulation:  Approximating Sine and Cosine of Angles Introduction - How Computers Calculate Mathematical Functions Fir...