## Thursday, July 30, 2015

### Generating Permutations: TI-84 Plus, Casio Prizm, and HP Prime (updated 10/18/15)

Generating Permutations:  TI-84 Plus, Casio Prizm, and HP Prime

In combinatorics, a permutation is an ordered arrangement of numbers, typically 1 to n.  For n = 3, there are 6 (3!) possible permutations:  {1,2,3}, {1,3,2}, {2,1,3}, {2,3,1}, {3,1,2}, and {3,2,1}.

This blog will focus on generating a random permutation given n elements.

TI-84 Plus:  Using the randIntNoRep function.

For the TI-84 Plus, generating a permutation is rather simple with the randIntNoRep (random integers no reputation function).  The syntax to be used is:

randIntNoRep(1,n,n)

For n = 3, the syntax would be randIntNoRep(1,3,3).  You can find this function by pressing [math], PROB submenu, selecting option 8.

For the Casio Prizm and the HP Prime, a program will be needed.  I gave the program the title SAM for sample (no repeating numbers).  Generally, SAM uses two lists.  The first list is generated by a sequence from 1 to n.  The second is rearranged list.  In order to get sample to not have repeats, during the main loop, as numbers are picked, they are replaced by 0.  During subsequent picks from the first list, the loop tests to see for a nonzero list.  The second list is the output.

Note that with the Casio Prizm that lists must have at least one element to be initialized, where the HP Prime allows for blank lists (lists with zero elements).

Casio Prizm:  SAM

“N”?→N
Seq(x,x,1,N,1)→List 1
RanInt#(1,N)→C
List 1[C]→M
{M}→List 2
0→List 1[C]
1→I
Do
RanInt#(1,N)→C
List 1[C]→M
If M≠0
Then
Augment(List 2,{M})→List 2
0→List 1[C]
1+I→I
IfEnd
LpWhile I≠N
List 2

HP Prime: SAM

Input:  SAM(n)

EXPORT SAM(n)
BEGIN
LOCAL s,L0,L1,I,c;

L0≔MAKELIST(X,X,1,n,1);
L1≔{ };
I≔0;

REPEAT
c≔RANDINT(1,n);
IF L0(c)≠0 THEN
L1≔CONCAT(L1,{L0(c)});
L0(c)≔0;
I≔I+1;
END;
UNTIL I==n;

RETURN L1;

END;

Update:  Changing c:=RANDINT(n) to c:=RANDINT(1,n) forces the random integer function to choose a number between 1 and 0, since RANDINT(n) allows for zero, allowing for a number to repeat, which is what we don't want.   Eddie

Note:  This is different from the permutation function (nPr, PERM) on your calculator, which calculates the number of arrangements of r from n objects.  (Formula: n!/(n-r)!)

Eddie

This blog is property of Edward Shore, 2015.

## Tuesday, July 28, 2015

### Extracting the First Digit

NOTICE:  The author does not use third-party features on this blog.   In order to comply with European Union laws, Google added a notice to explain Google’s use of certain Blogger and Google cookies.

Extracting the First Digit

Define the function FD(x) as:

FD(x) = int(x/10^(int log |x|))

If x > 0 (positive), this form can also be used:

FD(x) = int(x/10^(int log x))

The function int represents the integer part function (iPart on TI calculators, IP on most HP calculators).    This function extracts the first digit (most significant digit) of x, where the domain is:

FD(x) = 0  if -1 < x < 1,
FD(x) is Undefined when x = 0, and
FD(x) ϵ {1, 2, 3, 4, 5, 6, 7, 8, 9} for all other x.

Examples:

FD(0) = 0
FD(26) = 2
FD(324) = 3
FD(9273) = 9

FD(23) = 2
FD(23.28109) = 2
FD(-23) = 2
FD(-23.28109) = 2

FD(π) = 3
FD(1/2) = 0

Here are some graphs of FD(x), FD(e^x), FD(x^2), FD(x^2-2*x+2), and FD(e^(x-5)+1)  for integers x from 1 to 40.  This was done using a stat plot on a TI-84 Plus CE.

 FD(x)

 FD(e^x) – this looks like a dragon.

 FD(x^2)

 FD(x^2-2*x+2)
 FD(e^(x-5)+1) - a party? Something to explore… Eddie This blog is property of Edward Shore.  2015.

## Sunday, July 19, 2015

### HP Prime & TI-84: Bearing and Azimuth Conversions

HP Prime & TI-84:  Bearing and Azimuth Conversions

 Azimuth vs Bearing

AZ2BE (Azimuth to Bearing)
Note:  Bearings start clockwise from due north.  Bearings will be reduced to angles between 0° to 360°.

Three outputs will be returned:  bearing, direction string, and quadrant reference number (for reference).  The HP Prime version will return a list.

HP Prime AZ2BE:
EXPORT AZ2BE(θ)
BEGIN
// Azimuth to Bearing
// EWS 2015-07-19
LOCAL q,b,s;
θ≔θ MOD 360;
q≔IP(θ/90)+1;
// Determining the Bearing Angle
IF q==1 THEN
b≔θ; s:=”NE”;
END;
IF q==2 THEN
b≔ABS(θ-180); s≔”SE”;
END;
IF q==3 THEN
b≔θ-180; s≔”SW”;
END;
IF q==4 THEN
b≔ABS(θ-360); s≔”NW”
END;
RETURN {b,s,q};
END;

TI-84+ AZ2BE:
Input "ANGLE:",θ
360*fPart(θ/360)+360*(θ<0)→θ
iPart(θ/90)+1→Q
If Q=1:Then
θ→B
"NE"→Str1:End
If Q=2:Then
abs(θ-180)→B
"SE"→Str1
End
If Q=3:Then
θ-180→B
"SW"→Str1
End
If Q=4:Then
abs(θ-360)→B
"NW"→Str1
End
Disp "BEARING",B
Disp Str1,Q

BE2AZ  (Bearing to Azimuth)
Note:  Bearings outside of range of 0° to 90° or quadrant numbers outside of 1 to 4 will result in an “UNEXPECTED RESULT” message.

HP Prime BE2AZ:
EXPORT BE2AZ(b,q)
BEGIN
// Bearing to Azimuth
// 1 = NE, 2 = SE, 3 = SW, 4 = NW
// 2015-07-19 EWS

LOCAL θ;

// Are b and q in the proper range?
IF b<0 OR b>90 OR q<1 OR q>4 THEN
RETURN “Unexpected Value”;
KILL;
END;

// Calculation
q≔IP(q);
IF q==1 THEN
θ≔b;
END;
IF q==2 THEN
θ≔180-b;
END;
IF q==3 THEN
θ≔b+180;
END;
IF q==4 THEN
θ≔360-b;
END;
RETURN θ;
END;

TI-84+ BE2AZ:
Input "BEARING:",B
Disp "1=NE"
Disp "2=SE"
Disp "3=SW"
Disp "4=NW"
Input "Q:",Q
If B<0 or B>90 or Q<1 or Q>4
Then
Disp "UNEXPECTED VALUE"
Stop
End
iPart(Q)→Q
If Q=1:Then
B→θ:End
If Q=2:Then
180-B→θ:End
If Q=3:Then
B+180→θ:End
If Q=4:Then
360-B→θ:End
Disp "AZIMUTH:",θ

Examples:

Azimuth:  68°, Bearing: 68° bearing NE (q=1)
Azimuth: 164°, Bearing:  16° bearing SE (q=2)
Azimuth: 224°, Bearing:  44° bearing SW (q=3)
Azimuth: 321°, Bearing:  39° bearing NW (q=4)

This blog is property of Edward Shore.  2015

## Thursday, July 16, 2015

### Review: "Cosmic Numbers: The Numbers That Define Our Universe" by James D. Stein

Cosmic Numbers

One of the books I purchased recently was “Cosmic Numbers: The Numbers That Define Our Universe” by James D. Stein.  What attracted me to the book is that I am fascinated by mathematical constants (my favorite number is π) and how they came about. Stein talks about the following constants in the book:

1.    The Gravitational Constant (G)
2.    The Speed of Light (c)
3.    The Ideal Gas Constant
4.    Absolute Zero
5.    Avogardo’s Number
6.    Electricity and the Proportionality Constant
7.    The Boltzmann Constant
8.    The Plank Constant
9.    The Schwarzschild Radius (which the value depends on the object’s mass)
10.  The Efficiency of Hydrogen Fusion
11.  The Chandrasekhar Limit
12.  The Hubble Constant
13.  Omega

While I have not yet finished the book (got three more chapters to go), I recommend this book.  Stein writes in a straight-forward, entertaining matter.  Here of some of my favorite highlights of the book:

Gravitational Constant:
* The concept of the gravitational constant comes from Issac Newton’s Principia (1687), and as we are aware, we have two constants:  Big G for the universal constant and little g for the local constant.
* Little g (local gravity) was fairly easy to get, at least for Earth, using the relationship d = 1/2*g*t^2.  It would take until the mid-1700s before Henry Cavendish would propose a way to calculate big G, and even later before the first values of G were found.

Speed of Light:
* The first calculation of the speed of light was inspired by Galileo Galilei’s discovery of moons in front of Jupiter in 1610, which inspired Ole Rømer to come up with the first estimation of the speed of light.
* Albert Michelson is most connected with the speed of light, which will lead to the famous Michelson-Morely experiment, in which a beam of light was split into two separate, divergent beams.  Each of the diverged beams would reach two separate mirrors, and the difference between the wave’s speeds were calculated.
* An interesting paradox was presented in the chapter, involving lighthouse and a beach with the wall behind the lighthouse, and the speed of light is calculated using the distance between the lighthouse and the beam, in which the speed would reach a limit.

Absolute Zero:
* I know how refrigerators keep its food cold:  Liquid chlorine circulates in coils which evaporates into chlorine hydrate from the surrounding environment.  An electric pump pressurizes the gas, allowing the chlorine to turn back into a liquid, and the absorbed heat is released into the refrigerator.  Thank you Michael Faraday.  (OT?)
* In practice, temperatures near absolute zero have been reached (0 K, -273.15°C), both using a Bose-Einstein condensate and lasers to atoms almost to the point where atoms are completely still.

Electricity and the Proportionality Constant:
* Ever notice how similar the force of gravity and the force of electricity are similar?  For gravity, F = G*m*M/r^2 and for electricity, F = k*q*Q/r^2.

Boltzmann Constant:
* If you want a good mnemonic for the equation of work, just get mad:  W = m*a*d.
* Using the relationship of a monatomic molecule’s transitional energy and it’s kinetic energy, Ludwig Boltzmann solved for his constant (k) by solving 3/2*k*T = 1/2*m*v^2

Efficiency of the Hydrogen Fusion:
* I’m thankful that hydrogen fuses at a constant rate (.007 weight loss per nuclei).  If it didn’t, life may have not been possible.
* Measuring the fusion came first came from Lord Kelvin asking “How does the sun keep shining?”  The greatest contributions came during the decade of 1895-1905, and a value was finalized before the beginning of World War II.

If you want a good read, check “Cosmic Numbers” out.

Eddie

This blog is property of Edward Shore.  2015.

## Saturday, July 11, 2015

### Powers of Integers: Last Digit

Powers of Integers: Last Digit

Let x^n where x is a non-negative integer (x = 0, 1, 2, 3, …) and n is a positive integer (n = 1, 2, 3, …).

Starting with n = 1, note the last digit of each integer.  A table of where 0 ≤ x ≤ 19 and 0 ≤ n ≤ 12 is shown below:

 x^n:  x = 0 to 19, n = 0 to 12
Note:  The numbers in bold I typed in because the number of digits Excel 2013 will carry in its integers will only go so far.

Now, let’s look at just the last integer.  On Excel, the last digit can be extracted by the following formula:

=number-ROUNDOWN(number/10,0)*10

 Last digit of x^n

Starting to see a pattern?  I know this is not a rigorous proof, but four patterns definitely present themselves:

For 1 ≡ n mod 4  (n = 1, 5, 9…), the last digits of x^n follow this pattern:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9

For 2 ≡ n mod 4  (n = 2, 6, 10, …), the last digits of x^n follow this pattern:
0, 1, 4, 9, 6, 5, 6, 9, 4, 1

For 3 ≡ n mod 4 (n = 3, 7, 11, …), the last digits of x^n follow this pattern:
0, 1, 8, 7, 4, 5, 3, 6, 2, 9

And for 0 ≡ n mod 4  (n = 4, 8, 12, ….), the last digits of x^n follow this pattern:
0, 1, 6, 1, 6, 5, 6, 1, 6, 1

Eddie

This blog is property of Edward Shore.   2015.

## Thursday, July 9, 2015

### HP Prime: Diatomic Molecules

HP Prime: Diatomic Molecules

 Diatomic Molecules

The program DIATOMIC will calculate:

*  Distance from the center of mass for each molecule
*  Inertia of the molecule
*  Rotational Energy at level j  (j = 0, 1, 2, 3…)
*  Vibrational Energy at level n  (n = 0, 1, 2, 3…)

A diatomic molecule is a molecule made of two atoms.  Examples are H2, O2, NaCl (sodium chloride), and CO (carbon monoxide).

Input:

*  Mass of the two molecules, in atomic mass units (u).  The program will convert them to kilograms.  The conversion is 1 u ≈ 1.660538921 * 10^-27 kg
*  Distance of the “bar” between the two molecules.  Give this in ångströms, which an ångström is 10^-10 m.
*  Rotational and Vibrational Energy levels.  They do not have to be the same.
*  Frequency of the diatomic molecule in 10^12 Hz.  Typically, molecules and atoms exhibit frequencies in the order of 10^13 Hz.

The formulas are derived from the use of the Schrödinger Equation.  While I won’t give much details, a derivation can be found in many resources, such as this link:  http://chemwiki.ucdavis.edu/Physical_Chemistry/Spectroscopy/Rotational_Spectroscopy/Rotational_Spectroscopy_of_Diatomic_Molecules

This program can be adopted to other graphing calculators, but here is a version for the HP Prime:

Program DIATOMIC

EXPORT DIATOMIC()
BEGIN
// EWS 2015-07-09
// Diatomic Molecule
LOCAL m1,m2,r,l1,l2,I;
LOCAL j,n,w;
LOCAL Er,Ev;

// Input
INPUT({m1,m2,r,j,n,w},
"Diatomic Molecule",
{"Mass 1:","Mass 2:",
"r:","J:","N:","freq:"},
{"Mass in atomic units",
"Mass in atomic units",
"Distance in Angstroms",
"Rotational energy level",
"Vibration energy level",
"Frequency (10^12 Hz)"});

// Integer Parts
n:=IP(n);
j:=IP(j);

// Convert to kg
m1:=m1*1.660538921ᴇ−27;
m2:=m2*1.660538921ᴇ−27;

// Convert Angstroms to m;
r:=r/1ᴇ10;

// Convert to Hz;
w:=w*1ᴇ12;

// Lengths
l1:=m2*r/(m1+m2);
l2:=m1*r/(m1+m2);

// Inertia:
I:=m1*l1^2+m2*l2^2;

// Rotational Energy:
Er:=1.054571726ᴇ−34^2/(2*I)*j*(j+1);

// Vibrational Energy:
Ev:=(n+1/2)*1.054571726ᴇ−34*w;

// Results
PRINT();
PRINT("Distance to Center (m):");
PRINT("From Mol. 1: "+STRING(l1));
PRINT("From Mol. 2: "+STRING(l2));
PRINT("Inertia:");
PRINT(STRING(I)+" kg m^2");
PRINT("Rotational Energy:");
PRINT(STRING(Er)+" J");
PRINT("Vibrational Energy:");
PRINT(STRING(Ev)+" J");

RETURN({l1,l2,I,Er,Ev});

END;

Example

Mass 1:  Hydrogen:  1.00794 u
Mass 2:  Chlorine:  35.4270 u
Distance:  6 ångströms
Frequency:  3.6 x 10^13 Hz

Input Screen:

Output Screen:

Energy:
Rotational:  approx. 1.90*10^-23 J
Vibration:  approx. 5.69*10^-21 J

Sources:

Strong, Benjamin.  “Rotational Spectroscopy of Diatomic Molecules”  http://chemwiki.ucdavis.edu/Physical_Chemistry/Spectroscopy/Rotational_Spectroscopy/Rotational_Spectroscopy_of_Diatomic_Molecules   March 26, 2015.   Retrieved July 5, 2015.

Wikipedia.  “Atom Vibrations”  https://en.wikipedia.org/wiki/Atom_vibrations  Retrieved July 9, 2015.

Young, Hugh D. & Roger A Freedman   “University Physics with Modern Physics”  11th Ed.  Pearson:  San Francisco.  2003

Eddie

This blog is property of Edward Shore.  2015.

### TI-Nspire: Templates to Plot Functions, Parametric Equations, and Sequences

TI-Nspire:  Templates to Plot Functions, Parametric Equations, and Sequences Introduction The following are sample templates to plot functi...