Showing posts with label strings. Show all posts
Showing posts with label strings. Show all posts

Saturday, July 22, 2023

HP Prime and TI-84 Plus CE: Binary Dot Product

HP Prime and TI-84 Plus CE:   Binary Dot Product



Binary Dot Product



The binary, or inner product, of two binary integers is calculated by:


1.  Using the AND operator on each bit.

2.  Count the number of 1 bits from the result.

3.  Take the result mod 2.   The result will either by 0 (an even number of 1 bits) or 1 (an odd number of 1 bits).


Examples:


Binary dot product of 111011 and 100110.


111011

100110


From the left:

1st bit:  1 and 1 = 1

2nd bit:  1 and 0 = 0

3rd bit:  1 and 0 = 0

4th bit: 0 and 1 = 1

5th bit:  1 and 1 = 1

6th bit: 1 and 0 = 0


Number of 1 bits:  2


2 mod 2 = 0


Result:  111011 • 100110 = 0



Binary dot products are used in various applications, especially in quantum mechanics.  Specific examples include the Bernstein-Vazirani Algorithm.  




Program Notes



In order to compare the individual bits, the two binary integers are converted to strings.   A loop is executed to compare string characters one by one.  


The HP Prime has the BITAND function which compares each pairs of bits with the AND operation.  





HP Prime Program:  BINDOT



EXPORT DOTBIN(x,a)

BEGIN

// EWS 2023-05-13

// Bernstein-Vazirani

// x, a: binary integers

LOCAL f,m,i,s,c;


f:=BITAND(x,a);

// convert to strings

c:=CEILING(LOG(f)/LOG(2));

s:=STRING(f);


FOR i FROM 2 TO c+1 DO

IF MID(s,i,1)=="1" THEN

m:=m+1;

END;

END;


m:=m MOD 2;  

RETURN m;

END;



TI-84 Plus CE Program:  DOTBIN



"EWS 2023-05-11"

Disp "BINARY DOT PRODUCT"

Input "BINARY 1? ",Str1

Input "BINARY 2? ",Str2

length(Str1) → A

length(Str2) → B


If A ≠ B

Then

If A < B

Then

For(I, 1, B - A)

"0" + Str1 → Str1

End

Else

For(I, 1, A - B)

"0" + Str2 → Str2

End

End

End


ClrHome

Disp Str1, Str2

Pause


0 → M


For(I, 1, max(A,B))

If sub(Str1, I, 1)="1" and sub(Str2, I, 1)="1"

Then

M + 1 → M

End

End


remainder(M,2) → M

Disp M




Examples


Example 1:  1101 • 1001001 = 1


Example 2:  11100 • 11110 = 1


Example 3:  1011110 • 10101 = 0



Source

 

Biswas, Shrey.  "The Bernstein-Vazirani Algorithm: Quantum Algorithms Untangled"  Quantum Untangled.  Medium.  February 4, 2021.   Retrieved May 12, 2023.  https://medium.com/quantum-untangled/the-bernstein-vazirani-algorithm-quantum-algorithms-untangled-67e58d4a5096





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, January 21, 2023

Casio fx-9750GIII: Spin the Wheel

Casio fx-9750GIII:   Spin the Wheel



Making the Wheel and String Commands


The wheel is comprised of a long string.  Each space has an equal amount of characters, in this case I picked 5.  To make the wheel "spin", I use the StrRotate.


StrRotate(Str n, s):


Str n:  n from 1 to 20

s:  number of spaces to rotate the string.  If s>0 the string rotates left.  If s<0, the string rotates right.   The characters wrap around.  


If Str1 = "TESTBOOKADAM"


StrRotate(Str 1,4) returns "BOOKADAMTEST"

StrRotate(Str 1,-4) returns "ADAMTESTBOOK"


Other commands used:


StrLeft(Str n, s):   takes the left s characters of Str n

StrRight(Str n, s):  takes the right s characters of Str n

StrMid(Str n, p, m):  extracts the string starting at position n at m characters



The wheel used in this program:

BROKE  (it's bankrupt said in five characters)

$ 650

$ 550

$ 900

$ 800

$ 700

PRIZE  (prize space)

$1000

$ 600

$ 750

$ 500

$5000


5 characters per space is used.  




Casio fx-9750GIII Program:  SPIN


"2022-11-23 EWS"

"BROKE$ 650$ 550$ 900$ 800$ 700PRIZE$1000$ 600$ 750$ 500$5000"→Str 1

Lbl 1

RanInt#(20,48)→N

For 1→I To N

StrRotate(Str 1,5)→Str 1

StrLeft(Str 1,5)→Str 2

ClrText

Locate 10,3,"↓"

Locate 2,4,StrRight(Str 1,5)

Locate 8,4,Str 2

Locate 14,4,StrMid(Str 1,6,5)

Next

1DispsMenu "SPIN AGAIN?","YES",1,"NO",0

Lbl 0

ClrText

Locate 4,4,"THANK YOU"


↓ and $ are found in the CHAR menu.  






Have fun,


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 1, 2022

Python - Lambda Week: Building and Asking for Functions

Python - Lambda Week: Building and Asking for Functions


Welcome to Python Week!  This we we're going to cover calculus and the keyword lambda.


Note:  All Python scripts presented this week were created using a TI-NSpire CX II CAS.   As of June 2022, the lambda keyword is available on all calculators (in the United States) that have Python.   If you are not sure, please check your calculator manual. 



Lambda - Introduction


The key word lambda allows us to define a one-line function in Python program for internal use.  Keep in mind, this is different from the define (def-return) structure, where we can define multiline functions and can be used to be imported into other programs or the shell.


I briefly introduced lambda last September:  https://edspi31415.blogspot.com/2021/09/calculator-python-lambda-functions.html



The syntax for lambda is for one argument:


fx=lambda var:define f(var) here


And we can use fx(var) to calculate the lambda function. 




We can use more than one argument, and the syntax looks something like this:


fx=lambda var1, var2, ...:define f(var1, var2, ...)


We use fx(var1,var2,...) to recall and calculate.



Keep in mind, a lambda function can accept many arguments, but can only return one answer.   The script lambdabuild.py shows a short demonstration of the lamdba key word:



lambdabuild.py:   Build a lambda function


from math import *

#================================

# build a lambda function


fx=lambda x:x**2+1

print("x=1, ",str(fx(1)))

print("x=2, ",str(fx(2)))


# lambda can have more than 1 input, but 

# must have only 1 output


gxy=lambda x,y:sqrt(x**2+y**2)

print("x=3, y=4",str(gxy(3,4)))

print("x=6, y=10",str(gxy(6,10)))


Getting User Input


We can ask for a user function by the lines:

fs=input("text here")

fx=eval("lambda var:"+fs)


This can be combined in one line:

fx=eval("lambda var:"+input("prompt"))


For example:

fx=eval("lambda x:"+input("f(x) = "))


The eval function changes a string to an expression to be evaluated.  This is great because we can use eval to change strings to make lambda functions and ask for input of numerical expressions including pi (assuming the math module is imported).


lambda2.py:   Asking for a function


# Math Calculations

#================================

from math import *

#================================

# ask the user to define a function

# input defaults as a string


print("The math module is imported.")

print("Use eval for allow for numeric expressions,")

print("including pi.")

f=eval("lambda x:"+input("f(x) = "))


# ask for three inputs

# use eval to allow for expressions

x1=eval(input("x1? "))

x2=eval(input("x2? "))

x3=eval(input("x3? "))


# calculate

y1=f(x1)

y2=f(x2)

y3=f(x3)


# print results

print("Here are your results:")

print(x1, y1)

print(x2, y2)

print(x3, y3)




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. 


Saturday, February 5, 2022

TI-84 Plus CE Python: Evaluation and Integration

 TI-84 Plus CE Python: Evaluation and Integration


Introduction


The two scripts presented in today's blog will make use of Python's built in commands input and eval, to allow the user to enter equations and expressions as inputs.


Using input itself defaults whatever is entered as a string.   If the string is an equation, it will allow for the eval command to evaluate the formula.


Using the eval-input combination will allow the user to enter numerical expressions as well as numbers.   This allows pi as an input, something I wasn't able to do with the float-input combination.  


To allow for math functions including the use of π, I imported the standard math module.


You can download the app variables for the TI-84 Plus CE Python here:

https://drive.google.com/file/d/1Kzly9LjxQg0WrT0XLpdgL8yArGaggaCW/view?usp=sharing


The scripts are presented below.


evaluate.py




# evaluate.py

# 2021-11-29 EWS

from math import *

ch=0

fx=input("f(x)= ")

while ch==0:

  x=eval(input("x? "))

  y=eval(fx)

  print("f(x)= "+str(y))

  print("--------")

  print("Quit? ")

  ch=float(input("0: no,1: yes  "))


Example:

f(x) = exp(.5*sin(x))

x = 0.2, f(x) = 1.104435854

x = 0.6, f(x) = 1.326204677


integral.py





# integral.py

# 2021-11-29 EWS

# Simpson's Rule

from math import *

fx=input("f(x)= ")

a=eval(input("lower? "))

b=eval(input("upper? "))

n=eval(input("n (even)? "))


x=a

t=eval(fx)

x=b

t+=eval(fx)


h=(b-a)/n

for i in range(1,n):

  x=a+i*h

  if i/2-int(i/2)==0:

    t+=2*eval(fx)

  else:

    t+=4*eval(fx)


t*=h/3

print("integral = "+str(t))


Examples:

f(x) = 1/3*sin(x/pi)

lower = 0

upper = 2*pi

n = 10,  integral = 1.482985499


f(x) = (x+1)**(-1)*(x+3)**(-1)

lower = 1

upper = 5

n = 10,  integral = 0.2027325541


The eval command has opened up more possibilities,


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. 


Saturday, October 2, 2021

Swiss Micros DM41X: Working With Alpha Strings

Swiss Micros DM41X: Working With Alpha Strings





This first blog in the October series for the DM41X will cover basic tips and tricks for working with alpha strings.  


Considerations


Alpha characters are marked in blue on the Swiss Micros DM41X and the HP 41C series.  Alpha characters and the shift characters are shown on the back of the calculator.  


The alpha string can hold up to 24 characters total.  All letters are upper case, with the only lower case letters available are a, b, c, d, and e.  


Let's start with clearing the alpha register.   Usually, when a new alpha string is started, it will replace the contents of the alpha register.  However, ARCL and |- add to the string.  A sure way to make sure that the alpha register is cleared by executing the Clear Alpha (CLA) command.


You can attach the contents of a register, including stack register characters, to the end of the alpha register by using the ARCL command.  


ALENG returns the length of the alpha string.  


You can store strings by using ASTO.  But please be aware, each register can only hold up to six characters.   Example:  an attempt to store EDWARDS to R00 will only store EDWARD.  



Swiss Micros DM41X Program 1:  ALP1


Notes:


To attach strings together, use the append symbol (|-) as the first symbol of the string. Press [ alpha ], [ shift ], [ XEQ ] for the append symbol.  


33 XTOA adds an exclamation point (shown as a small 1 or a small exclamation point).   XTOA is present for the HP 41CX, HP 41C with the Extended Module, or the Swiss Micros DM41X.  XTOA appends characters to the end of the string.   Some XTOA characters include:


12 µ

33 !

34 "

36 $   

37 % (also [ alpha ], [ shift ], G)

63 ?  (also [ alpha ], [ 3 ])


Program:


Goal:  Build "HELLO WORLD, I AM THE 41!" from two strings and 33 XTOA.  If you have an HP 41C without the extended functions, the 33 XTOA must be ignored.  


01 LBL^T ALP1

02 CLA

03 ^T HELLO WORLD,

04 ^T |- I AM THE 41

05 33

06 XTOA

07 AVIEW

08 END


Swiss Micros DM41X Program 2:  ALP2


Goal:

Store 41 in R00.

"HELLO WORLD, I AM THE "

Alpha recall R00.


01 LBL^T ALP2

02 FIX 0

03 41

04 STO 00

05 ^T HELLO WORLD,

06 ^T |- I AM THE

07 ARCL 00

08 AVIEW

09 FIX 4

10 END


Swiss Micros DM41X Program 3:  ALP3


Goal:

Ask for two numbers and store them in R01 and R02, respectively.

Multiply them and store the result in R03.

Build the string "{R01} * {R02} = {R03}"


01 LBL^T APL3

02 FIX 0

03 CLA

04 CLX

05 ^T R01?

06 PROMPT

07 STO 01

08 CLA

09 ^T R02?

10 PROMPT

11 STO 02

12 RCL 01

13 *

14 STO 03

15 CLA

16 ARCL 01 

17 ^T |- *

8 ARCL 02

19 ^T |- = 

20 ARCL 03

21 AVIEW

22 FIX 4

23 RTN

24 END


Example:  R01 = 11, R02 = 24

Result:  "11*24=264" 


Swiss Micros DM41X Program 4:  ALP4


Ask what is user's name.   Then store the name in:

"HELLO, {NAME} ."


Remember, ASTO stores only the left four characters.  


01 LBL^T ALP4

02 CLA

03 ^T NAME?

04 PROMPT

05 AON

06 ASTO 00

07 CLA

08 ^T HELLO,

09 ARCL 00

10 ^T |- .

11 AVIEW

12 END


Example:  LAUREN  (it's already in Alpha mode because of the AON command)

HELLO, LAUREN.


Hope you find this 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. 


Sunday, May 23, 2021

Firmware Update: Swiss Micros DM42 - DMCP 3.21/DM42-3.19, Free42, and Offscreen Images

Firmware Update:   Swiss Micros DM42 - DMCP 3.21/DM42-3.19, Free42, and Offscreen Images


Firmware Update


Swiss Micros released a firmware update to the Swiss Micros DM42 calculator.  The current versions are:


* DMCP 3.21

* DM42-3.19


Download the file here:


https://technical.swissmicros.com/dm42/firmware/


This firmware brings the DM42 in alignment with Firmware 3.0.3 of Free42 by Thomas Okken.  Click here for details:


https://thomasokken.com/free42/history.html


Furthermore, you download the latest version of Free42 here:


https://thomasokken.com/free42/#doc



Steps:


1.  Plug in the DM42 into the PC.

2.  Activate USB Disk.  Press [ shift ] [ 0 ] (SETUP), 1. File, 3.  Activate USB Disk.

3.  Transfer the file (see Tip below) to the root directory of the calculator (hardware).

4.  Exit USB Disk on your calculator.  The firmware should update itself automatically.


Detailed instructions and other ways to update firmware can be found here, refer to sections 6.2 for the quick update or 6.3 for an alternative method:


https://technical.swissmicros.com/dm42/doc/dm42_user_manual/#quick_update_guide


Tip:  When transferring the bin file to the calculator, you want to transfer the combination bin file DCMP_flash_3.21_DM42-3.19.bin.   You need both the DCMP and DM42 files for the calculator to run.   


New Comparison Functions


X=?, X>?, X<?, X≤?, X≥?, X≠?


These tests compare the contents of the X Register to any other stack (T,Z,Y,L) or variable.   


Example:

R01 = 33

X:  25


X>? 01 returns No (next program step will be skipped)

X<? 02 returns Yes (next program step will be executed)


0=?, 0>?, 0<?, 0≤?, 0≥?, 0≠?


These tests are similar to the above except this comparison of any target stack or variable to zero.   


Both can be found in the CATALOG-PRGM menu.  In CATALOG, scroll to the PRGM submenu.


Writing Program Lines with X2LINE and A2LINE


Found in the CATALOG-MISC menu, X2LINE and A2LINE creates a program line from the X-stack and Alpha register, respectively.  This allows the user to create program lines outside of the program editor.  I don't know how this can be effective when it comes to executing functions, but they are here.


Enhanced VARMENU Command


The VARMNU1 allows the user to select variables without having to assign values to other variables first.  Found in the CATALOG-PRGM menu.


Longer String Creation with XSTR


I think this going to be my new favorite command besides the new comparison functions.  The XSTR allows for creation of strings of any length, beating the six-character limit of ASTO.  Found in the CATALOG-PRGM menu.


Example:

CLA

XSTR "FREE 42/DM 42"

ARCL ST X

XSTR " 2021"

ARCL ST X


Alpha Register:  "FREE 42/DM42 2021"



Off Images for the DM42 and DM41X


Off images must be the size of 400 x 240 pixels and be 1-color (monochrome) .bmp files.  





Carbon Canyon Park, Brea, CA - April 2021



 

Polar Butterfly - Plotted on an HP Prime - 2020




Mojave Narrows Park, Victorville, CA - May 2021




Laguna Beach, CA - March 2021



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. 


Saturday, December 5, 2020

HP 71B: Sign "Graph" of Trig Functions

 HP 71B: Sign "Graph" of Trig Functions


Introduction


The program SGNTRIG builds a 22 character binary string that depends on the function:


g(x) = 

1  if  sgn(t(x/c)) > 1

0  if  sgn(t(x/c)) ≤ 0


where:


c is a scaling factor, 


sgn(x) is the sign function,  and


t(x) represents one of three trigonometric functions, sin(x), cos(x), or tan(x).   Angles are assumed to be radians.


If we set to scale to c = 1, then g(x) takes the integer values from 1 to 22.  


The HP 71B builds the result to the string S$.   This is an aid to visualize at least some of the graph.   When the bit is 1, the graph is above the x-axis, otherwise, the graph is either on or below the x-axis.  The program presented can be expanded or modified to explore other functions.


The resulting string is a "psuedo-graph".  


Below is a graphical representation of g(x) (an HP Prime is used to graph g(x)).


HP 71B Program SGNTRIG

Size:  270 bytes


100 DESTROY S,I,N,E,C

105 S$=""

110 RADIANS

115 INPUT 'SCALE? ';C

120 DISP "S:SIN C:COS T:TAN"

125 E$=KEY$

130 IF E$="S" OR E$="C" OR E$="T" THEN 200 ELSE 120


200 FOR I=1 TO 22

205 IF E$="S" THEN N=SGN(SIN(I/C))

210 IF E$="C" THEN N=SGN(COS(I/C))

215 IF E$="T" THEN N=SGN(TAN(I/C))

220 IF N=1 THEN N=1 ELSE N=0

225 S$=S$&STR$(N)

230 DISP S$ @ BEEP 589,0.1 @ WAIT 0.2

235 NEXT I

240 DISP S$ @ BEEP 661,2


Notes:


Line 105:  creates a blank string, which is allowed on the HP 71B


Line 125:  The KEY$ function calls for a key input. S for sine, C for cosine, and T for tangent.


Lines 205 to 215: determine which trigonometric function to use


Line 220:  Sets the character to 0 if the sign function returns 0 or -1


Line 225:  &, the ampersand symbol concatenates two strings


Lines 230 and 240, respectively:  589 Hz is middle D, 661 Hz is middle E


Example


Below are results for each of the trigonometric functions when scale is set to 1.  




YouTube video: https://www.youtube.com/watch?v=GL6urOGvRGY&feature=youtu.be

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. 


Saturday, December 28, 2019

HP Prime: Base Conversions

HP Prime:  Base Conversions 

Introduction

The program BASEDEC converts a number in a base representation to decimal (base 10).   BASEDEC accepts any positive number, including non-integers up to base 36.  Each of the letters of alphabet represents a value:

A = 10
B = 11
C = 12
D = 13
E = 14
F = 15
...
Z = 35

BASEDEC takes two arguments: number to be converted, entered as a string;  and the base representation of the number.

Examples: 

BASEDEC("531",8) converts 531_8 to decimal.  Result:  345

BASEDEC("63.95A", 11) converts 63.95A_11 to decimal.  Result:  69.86701728

BASEDEC("4H", 18) converts 4H_18 to decimal.  Result:  89  (H = 17)

HP Prime Program BASEDEC

EXPORT BASEDEC(s,b)
BEGIN
// string, original base
// number can have fractional
// part in decimal form
// convert to base 10
// A=10,B=11,C=12...Z=35
// 2019-12-09 EWS
LOCAL l,pt,sl,sr,ls,lr,d;
LOCAL k,ac,al,dg,sd;
d:=0; // decimal
l:=DIM(s);
// split the string
pt:=INSTRING(s,".");
CASE
IF pt==0 THEN 
sl:=s;
sr:="";
END;
IF pt==1 THEN 
sl:="";
sr:=RIGHT(s,l-1);
END;
DEFAULT
sl:=LEFT(s,pt-1);
sr:=RIGHT(s,l-pt);
END;
// conversion to decimal
// integer part
ls:=DIM(sl);
IF ls>0 THEN
FOR k FROM 1 TO ls DO
sd:=MID(sl,k,1);
ac:=ASC(sd);
al:=ac(1);
dg:=when(al>64,al-55,EXPR(sd));
d:=d+dg*b^(ls-k);
END;
END;
// fractional part
lr:=DIM(sr);
IF lr>0 THEN
FOR k FROM 1 TO lr DO
sd:=MID(sr,k,1);
ac:=ASC(sd);
al:=ac(1);
dg:=when(al>64,al-55,EXPR(sd));
d:=d+dg/(b^k);
END;
END;
// return decimal
RETURN d;
END;

Introduction Part II

The program DECBASE converts a number in decimal form to any base you want.  DECBASE works will all positive real numbers.  There are three arguments to DECBASE:

*  The number in decimal form
*  The desired base
*  Accuracy:  how many decimal points do you want.  Conversions from decimal to other bases are approximations.   If the number is a integer (frac(number) = 0), then this argument is ignored (put 0).

The result is returned as a string.

Examples:

DECBASE(69, 6, 0) converts 69 to base 6.  Result:  "153"

DECBASE(5.875, 8, 4) converts 5.875 to base 8 to four decimals.  Result:  "5.7000"  (exact:  5.7_8)

DECBASE(635.05, 12, 12) converts 635.05 to base 12 to twelve decimals.  Result:  "44B.072497249724"   (exact:  44B.07249..._12  (7249 repeats))

HP Prime Program DECBASE

EXPORT DECBASE(d,b,acc)

BEGIN

// decimal, base, accuracy

// convert from decimal to base

// 2019-12-09 EWS

LOCAL n,f,nl,nd;

LOCAL nf,k,dg,s,fd;

n:=IP(d); // integer

f:=FP(d); // fractional

s:="";

// integer

IF n>0 THEN

nl:=IP(LOG(n)/LOG(b));

nd:=n;

FOR k FROM nl DOWNTO 0 DO

dg:=IP(nd/(b^k));

IF dg<10 THEN

s:=s+STRING(dg);

ELSE

s:=s+CHAR(dg+55);

END;

nd:=nd-dg*b^k;

END;

END;

// numbers < 1

IF n==0 THEN

s:="0";

END;

// fractional part

IF f>0 THEN

s:=s+".";

fd:=f;

FOR k FROM 1 TO acc DO

dg:=IP(fd*b^k);

IF dg<10 THEN

s:=s+STRING(dg);

ELSE

s:=s+CHAR(dg+55);

END;

fd:=fd-dg/(b^k);

END;

END;

RETURN s;

END;


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.

Thursday, August 1, 2019

TI-84 Plus CE: Solving Algebraic Equations Step by Step

TI-84 Plus CE:  Solving Algebraic Equation Scripts

Introduction

There are four programs that uses the wait and string commands to provide a step by step instruction on how to solve the following four equations:

1.  a * x + b = c
2.  a * x^n + b = c
3.  a^x = b
4,  (a + x)^2 = b

We will need the TI-84 Plus CE.  The original TI-84 Plus with the monochrome screen will not have the necessary commands.





ALGDEMO1 

"EWS 2019-05-30"
Disp "SOLVE AX + B = C"
Prompt A,B,C
(C-B)/A→X
ClrHome
Disp toString(A)+"X + "+toString(B)+" = "+toString(C)
Wait 1.5
Disp toString(A)+"X + "+toString(B)+" - "+toString(B)+" = "+toString(C)+" - "+toString(B)
Wait 1.5
Disp toString(A)+"X = "+toString(C-B)
Wait 1.5
Disp toString(A)+" X / "+toString(A)+" = "+toString(C-B)+" / "+toString(A)
Wait 1.5
Disp "X = "+toString(X)




ALGDEMO2

"EWS 2019-05-30"
Disp "SOLVE AX^N+B=C"
Prompt A,B,C,N
((C-B)/A)^(1/N)→X
ClrHome
Disp toString(A)+"X^"+toString(N)+"+"+toString(B)+"="+toString(C)
Wait 1.5
Disp toString(A)+"X^"+toString(N)+"+"+toString(B)+"-"+toString(B)+"="+toString(C)+"-"+toString(B)
Wait 1.5
Disp toString(A)+"X^"+toString(N)+"="+toString(C-B)
Wait 1.5
Disp toString(A)+"X^"+toString(N)+"/"+toString(A)+"="+toString(C-B)+"/"+toString(A)
Wait 1.5
Disp "X^"+toString(N)+"="+toString((C-B)/A)
Wait 1.5
Disp "X"+"="+toString((C-B)/A)+"^(1/"+toString(N)+")"
Wait 1.5
Disp "PRINCIPAL ROOT:","X="+toString(X)



ALGDEMO3

"EWS 2019-05-30"
Disp "SOLVE A^X=B"
Prompt A,B
log(B)/log(A)→X
ClrHome
Disp toString(A)+"^X="+toString(B)
Wait 1.5
Disp "log("+toString(A)+")^X=log("+toString(B)+")"
Wait 1.5
Disp "X log("+toString(A)+")=log("+toString(B)+")"
Wait 1.5
Disp "DIVIDE BY log("+toString(A)+")"
Wait 1.5
Disp "X = "+toString(X)


ALGDEMO4

"EWS 2019-05-30"
Disp "SOLVE (A+X)^2=B"
Prompt A,B
­√(B)-A→X
√(B)-A→Y
ClrHome
Disp "("+toString(A)+"+X)^2="+toString(B)
Wait 1.5
Disp toString(A)+"+X=+-√("+toString(B)+")"
Wait 1.5
Disp toString(A)+"+X-"+toString(A)+"=+-√("+toString(B)+")-"+toString(A)
Wait 1.5
Disp "X=+-√("+toString(B)+")-"+toString(A)
Wait 1.5
Disp "TWO ROOTS:"
Disp "X = "+toString(X)
Disp "X = "+toString(Y)

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

Tuesday, September 18, 2018

TI-84 Plus CE: Storing Names in a Concentrated String

TI-84 Plus CE: Storing Names in a Concentrated String 

Introduction

The program STRNAMES allows the user to store a list of names in a single string.  There are only 10 string variables for the TI-84 Plus CE (and in fact, all the the TI-83 and TI-84 families), so if you need to store more than 10 names, a workaround is needed.

This program uses two strings:  Str1 and Str2.  Str1 is a temporary string variable used to store and edit the list of names.  Str2 is the master list of all the names. 

In order to make this work, we will need to note where in the string the names start and the length of the names.  The two lists used are L₁, the position of each name, and L₂ for the length of each name.

In this program, each name is separated by space.

You will notice that Str2 starts with a space, and the lists L₁ and L₂ have a 0.  The TI-84 Plus CE does not allow us to store empty strings or lists. 

STRNAMES The Menu

1.  Add a Name:   Add a name to the list
2.  Delete Last Name:  Deletes the last name on the list
3.  Clear/Initialize:  Clears all the variables.  I recommend you start with this option every time you work with a new list of names.  Also, if you use other programs or the list or strings for other things, run the Clear/Initialize before beginning.
4.  Review:  List all the names in order.
5.  Erase Any Name:  You can erase any name in the list (1st name, 2nd name, 3rd name, etc).
6.  Exit: Quits the Program

TI-84 Plus CE Program STRNAMES

"2018-09-18 EWS"
Lbl 0
Menu("MENU","ENTER A NAME",A,"DELETE LAST NAME",B,"CLEAR/INITIALIZE",C,"REVIEW",D,"ERASE ANY NAME",E,"EXIT",F)

Lbl A
Input "NAME: ",Str1
augment(L₁,{length(Str2)+1})→L₁
augment(L₂,{length(Str1)}→L₂
Str2+Str1+" "→Str2
Disp "ADDED",Str2,"NAMES:",dim(L₁)-1
Pause 
Goto 0

Lbl B
If dim(L₁)≠1
Then
dim(L₁)→I
L₂(I)→B
length(Str2)→C
sub(Str2,1,C-B-1)→Str2
dim(L₁)-1→dim(L₁)
dim(L₂)-1→dim(L₂)
Disp "DONE.",Str2,"NAMES:",dim(L₁)-1
Else
Disp "LIST IS EMPTY."
End
Pause 
Goto 0

Lbl C
" "→Str2
{0}→L₁
{0}→L₂
Disp "CLEARED"
Pause 
Goto 0

Lbl D
For(I,2,dim(L₁))
L₁(I)→A
L₂(I)→B
dim(L₁)→C
toString(I-1)+"/"+toString(C-1)+": "+sub(Str2,A,B)→Str1
Disp Str1
Wait 0.5
End
Pause 
Goto 0

Lbl E
Input "ENTRY NUMBER:",I
I+1→I
dim(L₁)→D
L₂(I)→E
If D=I
Then
Goto B
Else
L₁(I)→A
L₁(I+1)→B
length(Str2)→C
sub(Str2,1,A-1)+sub(Str2,B,C-B)+" "→Str2
For(K,I+1,D)
L₁(K)-E-1→L₁(K-1)
L₂(K)→L₂(K-1)
End
dim(L₁)-1→dim(L₁)
dim(L₂)-1→dim(L₂)
Disp "DONE.",Str2,"NAMES:",dim(L₁)-1
Pause 
End
Goto 0

Lbl F
Disp "END PROGRAM"

Example

Try playing with this program.

Example list:

1.  Start by initializing, choose option 3.

2.  Enter EDDIE.  Choose option 1.  Press [ 2nd ] [alpha] and type EDDIE.  Quotes are not needed (since the Input command will be stored to a string).  Str2 = " EDDIE "

3.  Enter ANN.  Choose option 1.  Str2 = " EDDIE ANN "

4.  Enter TERRY.  Choose option 1. Str2 = " EDDIE ANN TERRY "

5.  Let's remove ANN from the list.  In our example, ANN is the second name.  Choose option 5.  Enter 2.  The result, Str2 = " EDDIE TERRY "

6.  Enter MARK.  Choose option 1.   Str2 = " EDDIE TERRY MARK "

7.  Review the list of names.  Choose option 4.  The screen will show:

1/3 EDDIE
2/3 TERRY
3/3 MARK

Continue with the example however you want. 

Eddie

All original content copyright, © 2011-2018.  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.  Please contact the author if you have questions.


RPN: DM32 and DM42: Stopping Sight Distance (Metric)

RPN: DM32 and DM42: Stopping Sight Distance (Metric) The Stopping Sight Distance Formula – Derivation The stopping sight di...