Monday, February 15, 2021

Review: Swiss Micros DM16L

Review: Swiss Micros DM16L






Welcome to a special Monday edition of Eddie’s Math and Calculator blog!


General Information


Company:  SwissMicros, https://www.swissmicros.com

Type:  Programmable Scientific - Boolean Algebra

Memory: 203 steps, shared with memory registers; 32 MB external flash

Battery:  CR 2032

Connection:  USB-B

Cost:  119 CHF, about $132.38 USD (2/5/2021)

Current Software Version:  DM16_31, 7/21/2020

Case Included?  Yes

Operating System: RPN (Reverse Polish Notation)


A Programmer’s Paradise

The Swiss Micros DM16L, and it’s small version, the DM16, is a clone of the highly popular and sought after Hewlett Packard HP 16C.  The functions are suited to computer science, including:


One key conversions between Hexadecimal (base 16), Octal (base 8), Decimal (base 10), and Binary (base 2) integers.  


Boolean features including AND, OR, NOT,  XOR


Bit shift and rotating functions, masking bits, and double division, remainder, and multiplication


There is a separate floating point arithmetic mode, separate from decimal integer mode.


You can customize integers up to 64 bits by the WSIZE function.  A handy shortcut is to set integers up to 64 bits is done by the key sequence:  0 [ f ] [ STO ] (WSIZE)


Negation of integers are determined by one of three modes:  1’s Complement, 2’s Complement, and Unsigned Numbers.    


If that isn’t enough, you can manipulate and test specific bits with the SB (set bit), CB (clear bit), and B? (is the bit set) commands. 


The STATUS command gives the user a three number status #-##-####. 


The first number is the complement mode:  0 for unsigned, 1 for 1’s complement, 2 for 2’s complement.


The second number is the current wordsize, from 1 bit to 64 bits.


The third number is the status of the four user flags 0 to 3, in descending order (flag 3, flag 2, flag 1, flag 0):  0 for clear, 1 for set.  The user flags are used in programming.


Programming


If you have programmed on the original HP-16C, then you would be right at home programming with the DM16L, with all the key codes and positions intact.   There are eight comparison tests available:  x≤y, x<0, x>y, x>0, x≠y, x≠0, x=y, x=0.   Up to 16 labels can be used, labels 0-F.  The special registers I and (I) are used for indirect storage and branching.   The DSE and ISZ use register I.


Curiously missing is storage arithmetic.   For example, instead of STO+ #, the following sequence of commands must be used:  (number), RCL #, +, STO #.  


Sample Programs


Integer Division:  Quotient and Remainder


001 LBL A         43,22,A

002 STO 0 44,0

003 X<>Y 34

004 STO 1 44, 1

005 X<>Y 34

006 ÷ 10

007 R/S 31

008 RCL 1 45, 1

009 RCL 0 45, 0

010 RMD 42, 9   \\ remainder command

011 RTN 43, 21


Example:  Word size = 16


Decimal Integer Mode (DEC):   41 / 7 = 5, remainder 6

Y:  41, X:  7 [ GSB ] [ A ]

Result:   5, [ R/S ], 6


Hexadecimal Integer Mode (HEX):  FE2 / 81 = 1F, remainder 43

Y:  FE2, X: 81 [ GSB ] [ A ]

Result:  1F, [ R/S ], 43


Adding Both the 1’s and 2’s Complement


001 LBL B 43, 22, B

002 STO 1 44, 1

003 Set 1’s 42, 1

004 CHS 49

005 STO 0 44, 0

006 RCL 1 45, 1

007 Set 2’s 42, 2

008 CHS 49

009 RCL 0 45, 0   // storage arithmetic is not available

010 + 40

011 STO 0 44, 0

012 RTN 43, 21


Examples:  Word Size = 8


Hexadecimal Integer Mode (HEX)

x = 2D

Result:  A5  (D2 + D3)


Hexadecimal Integer Mode (HEX)

x = F6

Result:  13  (9 + A)


Remember: Word size is important, as your mileage may vary.  


Verdict

Swiss Micros continues to manufacture quality calculators.  Due to the rarity and highly sought after HP 16C, the price to obtain one may be out of reach.  The DM16L is a much more affordable alternative.  The calculator is solid, keys feel great, and the added connectivity is an added bonus.  


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, February 14, 2021

HP Prime and Numworks: Luhn Algorithm

 HP Prime and Numworks: Luhn Algorithm


The Luhn Algorithm:   Is Your Credit Card Number Valid?


The Luhn algorithm, created by IBM scientist Hans Peter Luhn in 1954, also known as the modulus 10 algorithm, is a checksum algorithm used to check the validity certain numbers used in financial transactions, such as identification numbers and credit card numbers. The algorithm is in public domain and serves as a basic check.  


The general steps of the Luhn Algorithm:


1.  Starting at the rightmost digit, double every other digit (2nd digit from the rightmost digit, 4th digit from right, 6th digit from right, and so on)


2.  If the digit that is doubled is at least 10, add the digits together.  


Replace 10 with 1.

Replace 12 with 3.

Replace 14 with 5.

Replace 16 with 7.

Replace 18 with 9.


3.  Take the sum of all the digits.


4.  If the sum is a multiple of 10 (sum modulo 10 is equal to zero), the number is considered valid.


Example:  4366357


For illustration purposes, let's separate each of the digits:


4  3  6  6  3  5  7


There are 7 digits.  


2nd digit from the most right:  5.  Double it to 10.  1 + 0 = 1


4  3  6  6  3  1  7


4th digit from the most right:  6.  Double it to 12.  1 + 2 = 3


4  3  6  3  3  1  7


6th digit from the most right:  3.  Double it to 6.  


4  6  6  3  3  1  7


Now add the digits:  4 + 6 + 6 + 3 + 3 + 1 + 7 = 30


10 divides into 30 evenly, or 30 mod 10 = 0.   The integer 4366357 is valid according to the Luhn algorithm.  


HP Prime Program:  LUNH


EXPORT LUHN()

BEGIN

// Luhn Algorithm - HP Prime

// strings are used to accommodate

// string: type 2

LOCAL s,l,k,c,t,n;


INPUT({{s,[[2]]}},

"Luhn Algorithm",

{"N?"},{"Integer"});

l:=DIM(s);

k:=l;


// total

t:=0;


// loop

WHILE k>0 DO

n:=EXPR(MID(s,k,1));

IF FP((l-k)/2)==0.5 THEN

IF n≠0 THEN

n:=(2*n-1) MOD 9+1;

END;

END;

t:=t+n;

k:=k-1;

END;


// final results

IF t MOD 10==0 THEN

RETURN "VALID";

ELSE

RETURN "NOT VALID";

END;


END;


Numworks Python Script:  luhn.py


from math import *

# Luhn Algorithm

# 2021-01-10 EWS

# Numworks Python


# strings are used

s=str(input('Integer? '))

l=len(s)

k=l


# total

t=0


# loop

while k>0:

  n=float(s[k-1])

  f=(l-k)/2

  if f-int(f)==0.5:

    if n!=0:

      n=fmod(2*n-1,9)+1

  t=t+n

  k=k-1


# final results

if fmod(t,10)==0:

  print("VALID")

else:

  print("NOT VALID")



Examples


38348 returns NOT VALID


14956 returns NOT VALID


4382 returns VALID



Source


"Luhn algorithm" GeeksforGeeks. Noida, Uttar Pradesh.  https://www.geeksforgeeks.org/luhn-algorithm/  Retrieved January 1, 2021.


"Luhn algorithm".  Wikipedia.  Last Updated December 23, 2020.  https://en.wikipedia.org/wiki/Luhn_algorithm  Retrieved January 1, 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, February 13, 2021

HP Prime CHOOSE for Repeated Use - Present Value

 HP Prime CHOOSE for Repeated Use - Present Value


Introduction:  Using the CHOOSE Command to Allow for Repeated Calculations


The use of REPEAT and CHOOSE will allow the programmer to set up a choose from a set of calculations and allows for additional calculations until the user exits the program.  


Here is a sample syntax, with comments followed by double slashes (//):


// Set up local variables:  a choice variable, a list of options, the size of the list

LOCAL ch, lst, s;


// Use a list of options.  Be sure to have the last option as "Exit", "Quit", etc.

lst:={"opiton 1", "option 2", ... , "Exit"};

s:=SIZE(lst);


// Set a choice variable to a starting value. Use a "dummy" value to begin with, like -1.  The choice variable will take on a positive integer value after the CHOOSE command has been executed.

ch:=-1;


// The REPEAT loop

REPEAT

CHOOSE(ch,"title",lst);


IF ch==1 THEN

[choice 1 - calculation]

END;


IF ch==2 THEN

[choice 2 - calculation]

END;


...


IF ch==n-1 THEN

[choice n-1 - calculation]

END;


UNTIL ch==s;   // This is the Exit option


Let's look at an example program.



HP Prime Program: PVACT


*  This is an example program that uses CHOOSE to allow for repeated calculations.   The application is for several types of present value for several types of annuities.


*  As a bonus, you can save some settings, such as format and number of digits, to variables before switching settings that the program requires.  This allows for the programmer to restore settings at the end of the program.  


EXPORT PVACT()

BEGIN

// EWS 2021-01-10

// CHOOSE demonstration

// loop until user exits


// Grab the settings

LOCAL h1,h2;

h1:=HFormat;

h2:=HDigits;


// ch choice varaible

LOCAL ch,n,p,r,m,w,v;

LOCAL lst,s,g;


// Set a "dummy" initial choice

// for ch

ch:=−1;


// Set a list of choices

lst:={"Constant Annuity",

"Growing Annuity",

"Perpetual Annuity",

"Exit"};

s:=SIZE(lst);


// Set decimal fix to 2 places

HFormat:=1;

HDigits:=2;


// Use a Repeat loop to allow

// more than one calculation

REPEAT


CHOOSE(ch,"Present Value",lst);

 

// Constant Annuity - Choice 1

IF ch==1 THEN

INPUT({n,r,m},"Constant Annuity",

{"n?  ","i%? ","PMT? "},

{"number of payments",

"periodic interest rate",

"payment"});

v:=Finance.TvmPV(n,r,−m,0,1);

PRINT();

PRINT("n = "+n);

PRINT("i% = "+r);

PRINT("PMT = "+m);

PRINT("PV = "+v);

// show the screen

// WAIT is needed in a loop

WAIT();

END;


// Growing Annuity - choice 2

IF ch==2 THEN

INPUT({n,r,g,m},"Growing Annuity",

{"n?  ","i%? ","g%? ","PMT? "},

{"number of payments",

"periodic interest rate",

"payment growth rate",

"base payment"});

w:=(1+0.01*g)/(1+0.01*r);

v:=m/(1+0.01*r)*(1-w^n)/(1-w);

PRINT();

PRINT("n = "+n);

PRINT("i% = "+r);

PRINT("g% = "+g);

PRINT("Base Payment = "+m);

PRINT("PV = "+v);

// show the screen

// WAIT is needed in a loop

WAIT();

END;


// Perpetual Annuity - choice 3

IF ch==3 THEN

INPUT({r,m},"Perpetual Annuity",

{"i%? ","PMT? "},

{"interest rate",

"payment"});

v:=m/(0.01*r);

PRINT();

PRINT("r% = "+r);

PRINT("PMT = "+m);

PRINT("PV = "+v);

// show the screen

// WAIT is needed in a loop

WAIT();

END;


// if Exit is selected

UNTIL ch==s;


// Restore the setting

HFormat:=h1;

HDigits:=h2;

END;



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. 


Monday, February 8, 2021

An Alternative Way of Finding the Angle in a Rectangular to Polar Conversion

An Alternative Way of Finding the Angle in a Rectangular to Polar Conversion


Welcome to a special Monday edition of Eddie’s Math and Calculator Blog. 


The Traditional Method


Often we are required to find polar coordinates of a given point (x,y).   Finding the radius, r, is fairly simple:


r = √(x^2 + y^2) 


When talking about complex numbers, r represents the absolute value of x + yi where i = √-1.


Finding the angle, θ, often uses the formula:


θ = atan(y/x)


In complex numbers, θ represents the argument (arg) function.


On a scientific calculator the range of the arctangent function is ( -90°, 90° ).  (open interval).   In finding the true angle, adjustments will be required:





Let a = atan(y/x). Then: 


Quadrant I (x and y are both positive):  θ = a

Quadrant II (x is negative, y is positive): θ = a + 180°

Quadrant III (x and y are both negative):  θ = a - 180°

Quadrant IV (x is positive, y is negative):  θ = a 


If you are working with radian angle measures, know that 90° = Ï€/2, and 180° = Ï€.


This does not take into consideration situations where either x or y is 0:


If x > 0 and y = 0:  θ = 0°

If x = 0 and y > 0:  θ = 90°

If x < 0 and y = 0:  θ = 180°

If x = 0 and y < 0:  θ = -90°


Is there a shorter way to calculate θ?  


The Vector Method


Consider the point (x, y) as a vector [x, y].   Now draw another vector [x, 0].  In a regular Cartesian coordinate system, angles are measured from the x-axis counter clockwise.  





Let a and b represent two vectors.  Then the angle between two vectors are:


cos θ = (a ● b) / ( ||a|| ||b|| ) = dot(a,b) / ( norm(a) * norm(b) )


with:

dot(a,b) = a1 * b1 + a2 * b2

norm(a) = √(a1^2 + a2^2)

norm(b) = √(b1^2 + b2^2)


Let a = [x, y] and b = [x, 0].  Then:


cos θ = (x^2) / (√(x^2 + y^2) * √(x^2))

cos θ = (x^2) / (√(x^2 + y^2) * x)

cos θ = x / √(x^2 + y^2)

θ = acos( x / √(x^2 + y^2) )


The range of the arccosine function of a calculator is [ 0°, 180° ].  


If y < 0, the angle would be measured clockwise, and therefore I would make the adjustment:

θ = -acos( x / √(x^2 + y^2) )


In summary:

If y ≥ 0, θ = acos( x / √(x^2 + y^2) )

If y < 0, then θ = -acos( x / √(x^2 + y^2) )


Examples:


Find the angle, in degrees, in a rectangular to polar conversions:


Quadrant I  (2, 4):  y ≥ 0:   θ = acos( 2 / √(2^2 + 4^2) ) ≈ 63.43494882°


Quadrant II (-2, 4):  y ≥ 0:    θ = acos( -2 / √((-2)^2 + 4^2) ) ≈ 116.5650512°


Quadrant II (-2, -4):  y < 0:  θ = -acos( (-2) / √((-2)^2 + (-4)^2) ) ≈ -116.5650512°


Quadrant IV (2, -4):  y < 0:  θ = -acos( 2) / √(2^2 + (-4)^2) ) ≈ -63.43494882°


Vector Method for Navigation


In navigation, angles start from true North (up) and rotate clockwise towards East (right).  Angles are measured from 0° to 360°.


Use the vectors [0, N] and [E, N], then the angle between these vectors are:

If E ≥ 0,  θ = acos( N / √(E^2 + N^2))

If E < 0, θ = 360° - acos( N / √(E^2 + N^2))


Note:  This is the first blog entry that I have typed on Google Docs.  I have been using Windows app Wordpad for the last three years.   I am testing Google apps as I am considering buying a Chromebook.


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, February 7, 2021

TI-86 and DM42/HP42S: Square Root Simplification

TI-86 and DM42/HP42S:  Square Root Simplification


Introduction


The program SQROOT attempts to factor √N into the form A√B (N, A, and B are positive integers).  The program tests whether X^2 evenly divides into N from X = 1 to int(√N).  If successful, let A = X and B = N/X^2.


Example:  


√88   (N = 88)

int(√88) = 9


Test:

88/9^2 ≈ 1.0864

88/8^2 = 1.375

88/7^2 ≈ 1.7959

88/6^2 ≈ 2.4444

88/5^2 = 3.52

88/4^4 = 5.5

88/3^2 ≈ 9.7778

88/2^2 = 22    


2^2 (4) divides into 88 evenly.  


Then A = 2, B = 22.  Therefore √88 = 2√22


TI-86 Program:  SQROOT


*  This code should work on the TI-83/TI-84 Plus family with no or very minor adjustments.


*  The arrow -> is made of two characters:  the minus sign (-) and the greater than sign (>).  


"2021-01-06 EWS"

Disp "√N -> A√B"

Prompt N

iPart(√N)→X

While X≠0

If fPart(N/X^2)==0

Then

X→A 

N/X^2→B

Goto A

Else

X-1→X 

End

End

Lbl A

Disp "√N = A√B : A=", A, "B=" , B



HP 42S/DM42/Free42 Program: SQROOT


*  The character ├ appends (attaches) alpha strings together.  To designate strings to be attached, press ENTER while in ALPHA entry mode.


*  Similarly, pressing RCL while ALPHA mode will allow you to recall the value of a register and attach it to current alpha string.


* The ALL mode is similar to the standard and float mode.


* Registers:  R00 = N, R01 = A, R02 = B


00 {52-Byte Prgm}

01 LBL "SQROOT"

02 "N?"

03 PROMPT

04 STO 00

05 SQRT

06 IP

07 STO 01

08 LBL 00

09 RCL 00

10 RCL 01

11 X↑2

12 ÷

13 STO 02

14 FP

15 X=0?

16 GTO 01

17 1

18 STO- 01

19 GTO 00

20 LBL 01

21 ALL

22 CLA

23 "√"

24 ARCL 00

25 ├"="

26 ARCL 01

27 ├"√"

28 ARCL 02

29 END


Examples


√88 = 2√22


√46 = 1√46


√178 = 1√178


√200 = 10√2


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, February 6, 2021

Retro Review: Texas Instruments TI-36X II

Retro Review:  Texas Instruments TI-36X II 







Quick Facts:


Model:  TI-36 XII

Company:  Texas Instruments

Years:  1999 - mid-2000s

Battery:  CR2025

Operating System:  Algebraic

Number of Memory Registers:  5: A, B, C, D, E


Datamath Calculator Museum page:  http://www.datamath.org/Sci/Modern/TI-36X-II.htm


Keyboard


I like the dark gray keyboard, giving a calculator a sleek look.  The dark mint green and white font on the keys and the keyboard provides a nice contrast.  The keys are a pleasure to push, however make sure the key registers on the screen before the next key is pushed; there is no key buffer.  


To keep the keyboard from possibly being cluttered, most of the funcitons are stored in menus.  This includes:


LOG:  log, 10^; ln, e^


HYP:  sinh, sinh^-1; cosh, cosh^-1; tanh, tanh^-1


COMPX (complex numbers):  conj (conjugate), real (real part); imag (imaginary part), abs (absolute value)


TRIG: sin, sin^-1; cos, cos^-1; tan, tan^-1


LOGIC:  and, or, xor; not, 2's


PRB (probability):  nPr (permutations), nCr (combinations), ! (factorial of positive integers up to 69); rand (random numbers between 0 to 1), randi (random integers between a and b)


Features


Base Conversion with Boolean Functions:  The TI-36X II overs conversions between integers in decimal (base 10), hexadecimal (base 16), or octal (base 8).  Somehow binary isn't included.  We get the nice basic set of Boolean functions.  The hexadecimal integers A through F are located on the shifted functions of keys [ 1 ] through [ 6 ].


Fractions:  Use the [A b/c] key to enter fractions.  There are two conversion functions:  F<>D converts between fractions and decimals, while A b/c<>d/e converts between mixed form and improper form.   Fractions are simplified automatically (example: entering 12/24 returns 1/2).


Operation Storage:  This is the programmable feature of the TI-36X II.  Two operations, OP1 and OP2, allow the user to store a simple operation (+, -, *, /, ^) followed by a number.  Operations are stored with >OP1 and >OP2.  


Example:  If I store +5 to OP1 and *2 to OP2, then: 

7 [ OP1 ] returns 12

7 [ OP2 ] returns 14

7 [ OP1 ] [ OP2 ] returns 24  (7+5=12, 12*2=24)

7 [ OP2 ] [ OP1 ] returns 19  (7*2=14, 14+5=19)


Conversions:  The TI-36X II features 20 metric-U.S. conversions.  It is really interesting how they are paired up.   Each conversion set is represented once, like cm←→in.  Pressing [ = ] gives the conversion "left to right", like cm to in.  However, pressing [ 2nd ] [ = ] gives the conversion "right to left", in to cm.


Constants:  The TI-36X II has 16 conversions in SI units.  


Complex Numbers:  Complex numbers are typed as ordered pairs:  (real, imaginary).   The complex operations are limited to arithmetic (+, -, x , /) and the COMPX menu only.  Strangely, there is no arg/angle function.


Integrals:  Integrals are done in Radian angle mode.   The variable of integration is A.   The steps to perform an integration:


1.  Store the lower limit in the variable A.

2.  Store the upper limit in the variable B.

3.  Store the number of divisions in the variable C.  The Simpson's rule is used, so the number of divisions is even, and the more divisions are used, the more accurate the answer but the longer the calculation takes.    

4.  Press the [ ∫dx ] key.  Type the function (in terms of A, use [MEMVAR], A).  Press [ = ].  During calculation, the calculator shows a clock icon with "CALC" displayed. 


The function must be continuous and defined everywhere.  


Example:  ∫ 4A^3 - 5e^A dA, lower (A) = 1, upper (C) = 5

C = 10 calculates the integral as -104.480831

C = 20 calculates the integral as -104.4747906


After each integral, the C is cleared  and the value of A matches value the B.  


Rectangular/Polar Conversions:  Like higher-end Texas Instrument calculators, conversions are handled on four functions:

R>Px(x, y)

R>Py(x, y)

P>Rx(r, θ)

P>Ry(r, θ)


Statistics:  The TI-36X II has four regression models:

Linear (LIN):  y = a + bx

Logarithmic (LN):  y = a + b ln x

Exponential (EXP):  y = a * b^x

Power (PWR):  y = a*x^b


A model, 1-Variable (1-VAR), or 2-Variable (2-VAR) must be selected first before data can be entered.  Up to 42 data points can be entered.  


Verdict


The TI-36X II is a predecessor to the TI-36X Pro and is a great calculator to use.  There are some missing functions that I think should have been present were the argument (angle) function, the conversion to binary integers, maybe integer and fraction parts.   I am not a fan of selecting variables through the menu, I personally prefer the use of ALPHA key.


Still a great calculator for the collection.  $20, $25 at most should be a good price, even though it is one of the rarer calculators from Texas Instruments. 

 


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, January 31, 2021

HP 42S/DM42 and TI-85: True Bearing vs. Compass Bearing

 HP 42S/DM42 and TI-85:  True Bearing vs. Compass Bearing


Introduction 





The program converts angles between true bearing and compass bearing.


True Bearing:  0° to 360°, going clockwise from due north.  North is typically represented as the positive y direction.  True bearing is also known as azimuth.


Compass Bearing:  The grid is divided into four quadrants, each given one direction.  Measurements from each quadrant range from 0° to 90°.


Northeast (NE):  the angle is measured from true north (positive y axis), clockwise

Southeast (SE):  the angle is measured from true south (negative y axis), counterclockwise

Southwest (SW): the angle is measured from true south (negative y axis), clockwise

Northwest (NW): the angle is measured from true north (positive y axis), counterclockwise


HP 42S/DM42 Program:  CNVANG 


00 { 263-Byte Prgm }

01▸LBL "CNVANG"

02 DEG

03 "∡?"

04 PROMPT

05 STO 00

06 "∡ CONVERSION"

07 AVIEW

08 ">COMP"

09 KEY 1 GTO 01

10 "NE>"

11 KEY 2 GTO 06

12 "SE>"

13 KEY 3 GTO 03

14 "SW>"

15 KEY 4 GTO 04

16 "NW>"

17 KEY 5 GTO 05

18 MENU

19▸LBL 00

20 STOP

21 GTO 00

22▸LBL 01

23 CLA

24 360

25 MOD

26 ENTER

27 ENTER

28 90

29 MOD

30 STO 00

31 X<>Y

32 90

33 ÷

34 IP

35 STO 01

36 0

37 X=Y?

38 GTO 07

39 R↓

40 1

41 X=Y?

42 GTO 08

43 R↓

44 2

45 X=Y?

46 GTO 09

47 GTO 10

48▸LBL 07

49 RCL 00

50 ARCL ST X

51 32

52 XTOA

53 78

54 XTOA

55 69

56 XTOA

57 GTO 01

58▸LBL 08

59 90

60 RCL- 00

61 STO 00

62 ARCL ST X

63 32

64 XTOA

65 83

66 XTOA

67 69

68 XTOA

69 GTO 01

70▸LBL 09

71 RCL 00

72 ARCL ST X

73 32

74 XTOA

75 83

76 XTOA

77 87

78 XTOA

79 GTO 01

80▸LBL 10

81 90

82 RCL- 00

83 STO 00

84 ARCL ST X

85 32

86 XTOA

87 78

88 XTOA

89 87

90 XTOA

91 GTO 01

92▸LBL 01

93 BEEP

94 AVIEW

95 GTO 11

96▸LBL 03

97 180

98 X<>Y

99 -

100 GTO 06

101▸LBL 04

102 180

103 +

104 GTO 06

105▸LBL 05

106 360

107 X<>Y

108 -

109 GTO 06

110▸LBL 06

111 STO 00

112 BEEP

113 CLA

114 "TRUE="

115 ARCL ST X

116▸LBL 11

117 CLMENU

118 EXITALL

119 RTN

120 .END.


TI-85 Program: CONVANG


ClLCD

"2020-12-31 EWS"

Degree

Input "θ? ",A

Menu(1,">COMP",A1,2,"NE>",A2,3,"SE>",A3,4,"SW>,A4,5,"NW>",A5)

Lbl A1

mod(mod(A,360),90)→B

iPart(A/90)→C

If C==0

Then

Outpt(3,1,B)

Outpt(3,17,"° NE ")

End

If C==1

Then

90-B→B

Outpt(3,1,B)

Outpt(3,17,"° SE ")

End

If C==2

Then

Outpt(3,1,B)

Outpt(3,17,"° SW ")

End

If C==3

Then

90-B→B

Outpt(3,1,B)

Outpt(3,17,"° NW ")

End

Lbl A2

A→B

Goto A6

Lbl A3

180-A→B

Goto A6

Lbl A4

180+A→B

Goto A6

Lbl A5

360-A→B

Goto A6

Lbl A6

Outpt(3,1,"TRUE= ")

Outpt(3,7,B)

Stop


Examples


To True Bearing:

35 NE> returns 35

74 SE> returns 106

20 SW> returns 200

76 NW> returns 284


From True Bearing:

35 >COMP returns 35 NE

106 >COMP returns 74 SE

200 >COMP returns 20 SW

284 >COMP returns 76 NW


Coming up in February:  a review of the TI-36 XII calculator, more programs for an old favorite, the TI-85, and much more.


Here's to the Groundhog delivering great news on 2/2/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, January 30, 2021

TI-Nspire Python: Linear Regression

 TI-Nspire Python:  Linear Regression


Introduction


The following is a simple script to fit bivariate data using linear regression:


y = ax + b


a = slope

b = y-intercept


Download the document here:  https://drive.google.com/file/d/1trsa6oLdb0SG-1cHzog1stcbE6XY6BTv/view?usp=sharing


TI-Nspire Python Script:  linreg.py


# 2020-12-31 EWS

# linear regression 

from math import *


# enter and calculate data

xlist=[]

ylist=[]

n=int(input('n? '))

nb=0

sx=0

sx2=0

sy=0

sy2=0

sxy=0


for i in range(n):

  nb=nb+1

  print("Data Point "+str(nb))

  x=float(input('x? '))

  y=float(input('y? '))

  sx=sx+x

  sy=sy+y

  sx2=sx2+x**2

  sy2=sy2+y**2

  sxy=sxy+x*y

  xlist.append(x)

  ylist.append(y)


# slope

a=(sxy-sx*sy/nb)/(sx2-sx**2/nb)

# y-intercept

b=sy/nb-a*sx/nb

# correlation

r=(sxy-sx*sy/nb)/(sqrt(sx2-sx**2/nb)*sqrt(sy2-sy**2/nb))


# results

print("y = ax + b")

print("a= "+str(a))

print("b= "+str(b))

print("r= "+str(r))


The following script adds a plot of both the real and predicted data.


TI-Nspire Python Script:  linregplus.py


# 2020-12-31 EWS

# linear regression with plot

from math import *

import ti_plotlib as plt


# enter and calculate data

xlist=[]

ylist=[]

n=int(input('n? '))

nb=0

sx=0

sx2=0

sy=0

sy2=0

sxy=0


for i in range(n):

  nb=nb+1

  print("Data Point "+str(nb))

  x=float(input('x? '))

  y=float(input('y? '))

  sx=sx+x

  sy=sy+y

  sx2=sx2+x**2

  sy2=sy2+y**2

  sxy=sxy+x*y

  xlist.append(x)

  ylist.append(y)


# slope

a=(sxy-sx*sy/nb)/(sx2-sx**2/nb)

# y-intercept

b=sy/nb-a*sx/nb

# correlation

r=(sxy-sx*sy/nb)/(sqrt(sx2-sx**2/nb)*sqrt(sy2-sy**2/nb))


# results

print("y = ax + b")

print("a= "+str(a))

print("b= "+str(b))

print("r= "+str(r))


# predictive list

plist=[]

for i in range(n):

  p=a*xlist[i]+b

  plist.append(p)


# plot routine

# clear the screen

plt.cls()

# automatically fits the screen to fit the data

plt.auto_window(xlist,ylist)

# display the axes

# "on" plots axes and endpoints

# "axes" just plots the axes

plt.axes("on")


# select color - use RGB style

# denim blue, real data

plt.color(21,96,189)

plt.plot(xlist,ylist,".")

# orange, predictive data

plt.color(255,165,0)

plt.plot(xlist,plist,".")

# plot the graph

plt.show_plot()



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. 


HP 67 Collection: October 2026

HP 67 Collection: Oct ober 2026 All examples are done in FIX 4. (DSP 4) Earth's Gravity at a Specific Latitude The true ea...