Sunday, November 9, 2014

Two New Videos: Derivatives on the HP Prime, Derivative and Integral of abs(x)

Derivatives on the HP Prime Calculator

Video:  http://youtu.be/LXwLiPlKO2M

Notes:

Derivative Template:  Template Key, template is on the top row, 4th column

Numeric Format:  (d* function)/(d varaible = point), press Enter
In RPN Mode: You also need to press Shift+Comma (Eval)
Symbolic Format (CAS Mode):  (d function)/(d variable)

*d represents the derivative symbol

diff command:
diff(function, variable)


Derivative and Integral of abs(x)

Video:  http://youtu.be/8PikrlA5UlQ

A short derivation of the derivative and integral of absolute value function (abs(x)), and how the signum (sign(x)) function plays a part its calculation. 

Graphs made with the online Desmos calculator.  Please visit and explore at www.desmos.com
(This is NOT a paid endorsement)

Eddie


Blog Entry #403

This blog is property of Edward Shore.  2014

Saturday, November 8, 2014

My Morning at Honnold/Mudd Library: 2014-11-08 (Game Shows, Bravias Lattice, Prime Numbers)

My Morning at Honnold/Mudd Library

Honnold/Mudd Library - Claremont, CA


What I love about visiting the mathematics and science sections in a university library is that there is a feast of information.  Every time, there is something new to learn.   Here are some notes from today’s visit:

Game Shows and Winning

Source:  John Haigh.  “Taking Chances: Winning with Probability”  2nd Edition Oxford Press: 2003

Haigh introduces two central ideas of probability:  exclusive events and independence.  Is it impossible for two events to occur simultaneously?  Does one event have any effect on another?  Let’s explore some popular concepts of probability found in game shows.

“Find the Lady” – also known as the “Monty Hall Problem”.  You have three boxes, two are worthless and one has the prize.  After the contestant selects the box, the host shows one of the boxes that are worthless.  Statistically, if the contestant switches their initial choice, the contestant doubles the chance of winning.  That is, since the contestant initially is incorrect 2/3 of the time, and the host shows one of the incorrect boxes; the contestant who switches has a 2/3 chance of switching from a losing box to the winning box.

“Showcase Showdown” (The Price is Right) – spinning last may not be the most advantageous place to be.  It depends on the scores of the first two spinners, and the chance of getting the best score. 

“Who Wants to be a Millionaire” – In the classic structure of the game, before the time clock and the shuffle format, contestants were offered three lifelines:  Ask the Audience, 50:50, and Phone a Friend.  Haigh suggests using the lifelines in this order: 50:50, Ask the Audience, and Phone a Friend.  The risk between higher level questions increase as the game goes on.  

“Blockbusters”

A two-person team (white) goes against an individual player (blue in the UK, red in the US).  For each question the team has 2/3 chance of getting the question correctly, but will have to answer a minimum of five question correctly, while the individual can win the game as a few as four correct answers.

My calculation:  assuming that there are no blocks, the probability that the team wins with five consecutive answers is (2/3)^5 = .13169 versus (1/3)^4 = .01235. 

Ideal Crystals and Bravais Lattices

Source:  M.G. Cottam and D.R. Tilley  “Introduction to Surface and Superlattice Excitations”  Cambridge University Press:  Cambridge.  1989.

Ideal crystals are described as a basis of atoms (or ions) located on each point of a lattice, which is defined as a regular periodic array in space.  In an ideal crystal, all the lattice points are equivalent.

Each lattice is defined by the non-coplanar vector a1, a2, and a3.  That is, a1, a2, and a3 do not lie on one specific plane.  The space lattice is formed through a collection of vectors, symbolized as R, as:

R = n1*a1 + n2*a2 + n3*a3, where n1, n2, and n3 are integers. 

Since the ideal crystal has translational symmetry, the transition f(r+R)=f(r) is satisfied for all points in space, which such a point is represented by r. 

The reciprocal lattice vector of R, symbolized by Q, takes the form:

Q = v1*b1 + v2*b2 + v3*b3, where v1, v2, and v3 are integers, and

b1 = ((2*π*a2) x a3) / dot(a1, a2 x a3)
b2 = ((2*π*a3) x a1) / dot(a1, a2 x a3)
b3 = ((2*π*a1) x a2) / dot(a1, a2 x a3)

Where x represents the vector cross product and dot(v,u) represents the dot product.
Two-Dimensional Lattices

Let a1 and a2 be two translation vectors and the set R be defined as:

R = n1*a1 + n2*a2, where n1 and n2 are integers

The ends points of R from what is called the Bravais lattice.  There are five Bravais lattices which take the shape of one of these five forms:

1.    Square, |a1| = |a2|, θ = 90°
2.    Primitive Rectangle (general rectangle), |a1| ≠ |a2|, θ = 90°
3.    Centered Rectangle (rhombic), |a1| ≠ |a2|, θ = 90ׄ°
4.    Hexagonal, |a1| = |a2|, θ = 60° or 120°
5.    Oblique, all other cases

Cottam and Tilley illustrates the concept of bulk and surface excitation by using how Rayleigh’s descriptions of waves in a semi-infinite isotropic elastic medium.  In searching for plane-wave solution, in which the wave propagates parallel to the surface with vector q with velocity v and frequency w:

f’’(z) – (q^2 – w^2/v^2)*f(z) = 0

If q^2 < w^2/v^2, we have a bulk wave where

f(z) = B1*e^(i*√(w^2/v^2-q^2)*z) + B2*e^(-i*√(w^2/v^2-q^2)*z) where B1 and B2 are constants.

If q^2 > w^2/v^2, we have a decaying surface wave where

f(z) = B3*e^(√(q^2-w^2/v^2)*z)


Prime Number Goodies

Source:  Richard Carndall and Carl Pomeance.  “Prime Numbers: A Computational Perspective.  Second Edition” Springer.  2005

Twin Primes:  

Two primes that differ by 2.  Examples include 3 and 5, 29 and 31, and 311 and 313.  Is there an upper bound on twin primes, or is there an infinite set of pairs? 

V. Brun showed the upper bound for the number of twin prime sets under the integer x is:

‘π(x) = O(x*(ln ln x/ln x)^2) -> x*(ln x)^-2

Brun also showed that the sum of the reciprocal of the twin primes is finite.  That sum is denoted as the Brun constant which is:

B = (1/3 + 1/5) + (1/5 + 1/7) + (1/11 + 1/13) + …

The Brun constant is at least 1.71077 (using twin primes from 1 to 1,000,000).  As imagined, this series converges slowly.

Formulas to Produce Primes:

Euler used the polynomial x^2 + x + 41 to produce primes, which worked for all integers 0 to 39.  After x = 39, the polynomial continues produce primes at a remarkable probability. 

Mersenne Primes:

Mersenne primes, in the form of 2^q – 1 where q is a prime greater than 2.  It has been proven that if 2^q – 1 is prime, then so is q.  This form does not always produce primes (see q = 11 or q = 23).  In fact, the distribution of Mersenne primes gets scarce quickly as q increases.

Perfect numbers, integers in which the sum of its divisors except itself equals that integer (example: 6 = 1 + 2 + 3), can be characterized by Euler and Euclid:

An even number is perfect if and only if n = 2^(q-1)*(2^q-1) where 2^q-1 is prime.

Quadratic Residues:

The integer a is said to be a quadratic residue of coprime integer m if the congruence

x^2 ≡ a mod m

can be solved such as x is an integer and gcd(a, m) = 1. 

For example, 19 is a quadratic residue mod 5 since 19 mod 5 = 4 = 2^2 and gcd(19,5) = 1.

The next two basic definitions play a role in solving polynomials and equations involving prime numbers.

Legendre Symbol defined as (a/p) [normally written vertically]:

Let p be an odd prime.  Then:

(a/p) = legendresymbol(a,p) =
0 if a ≡ 0 mod p
1 if a is a quadratic residue of p
-1 if a is not a quadratic residue of p

Example:  p = 19.  The Legendre symbols of (4/19), (5/19), and (19/19) are 1, -1, and 0, respectively. (corrected on 2014-11-10 - with apologizes)

Jacobi Symbol defined as (a/m) [normally written vertically]:

Let m be any odd integer and a be any integer.  Then:

(a/m) = jacobisymbol(a, m) =  product( legendresymbol( a, prime factor of m )).

Example:  m = 27 = 3 * 9, a = 55

Jacobisymbol(55, 27) =

Legendresymbol(55, 3) * legendresymbol(55, 9) = 1 * 1 = 1

Is it shown that jacobisymbol(a, m) = 0 if and only if gcd(a, m) > 1.


Enjoy!  

Eddie

Blog Entry # 402

This blog is property of Edward Shore.  2014


Monday, November 3, 2014

Derivative of abs(x) and Integrals of abs(x), abs(e^x), abs(e^(a*x) + e^(a*y))

Derivative of abs(x) and Integrals of abs(x), abs(e^x), abs(e^(a*x) + e^(a*y))

For this blog entry, assume that are functions are in terms of x and a, x, y represent real numbers.

Definition of abs(x) (also symbolized as |x|)

Piecewise definition:

abs(x) = x if x > 0
abs(x) = 0 if x = 0
abs(x) = -x if x < 0

Also:

abs(x) = x * sign(x)

Where the sign(x), sometimes labeled sgn(x), is the sign or signum function. It is defined as:

sign(x) = 1 for x > 0
sign(x) = 0 for x = 0
sign(x) = -1 for x < 0

d/dx sign(x)

We can clearly demonstrate that d/dx sign(x) = 0 since:

d/dx sign(x) = 0 for x > 0
d/dx sign(x) = 0 for x = 0
d/dx sign(x) = 0 for x < 0

d/dx abs(x)

Using the chain rule:
d/dx abs(x)
= d/dx (x * sign(x))
= d/dx (x) * sign(x) + x * d/dx (sign(x))
= sign(x)

This can also be done with the piecewise representation:

d/dx abs(x) = 1 if x > 0
d/dx abs(x) = 0 if x = 0
d/dx abs(x) = -1 if x < 0

∫ abs(x) dx

∫ abs(x) dx
= ∫ x * sign(x) dx

Using integration by parts:
where u = sign(x), dv = x dx
Then: du = 0 dx, v = x^2/2

∫ abs(x) dx
= ∫ x * sign(x) dx
= x^2/2 * sign(x) - ∫ 0 dx
= x^2/2 * sign(x) + C

C is the arbitrary integration constant

With the piecewise representation:

∫ abs(x) dx = x^2/2 if x > 0
∫ abs(x) dx = 0 if x = 0
∫ abs(x) dx = -x^2/2 if x <0

Note that this is x^2/2 * sign(x).

∫ abs(e^(a*x)) dx

∫ abs(e^(a*x)) dx
= ∫ e^(a*x) * sign(e^(a*x)) dx
= 1/a * e^(a*x) * sign(e^(a*x)) - ∫ 0 dx
= 1/a * e^(a*x) * sign(e^(a*x)) + C

∫ abs(e^(a*x) + e^(a*y)) dx

∫ abs(e^(a*x) + e^(a*y)) dx
= ∫ (e^(a*x) + e^(a*y)) * sign(e^(a*x) + e^(a*y)) dx
= (e^(a*x)/a + x*e^(a*y)) * sign(e^(a*x) + e^(a*y)) - ∫ 0 dx
= (e^(a*x) + a*x*e^(a*y))/a * sign(e^(a*x) + e^(a*y)) + C

Eddie

This blog is property of Edward Shore. 2014

(Blog Entry # 401)

Tuesday, October 28, 2014

Happy 20^2 (400th Blog Post)

Hello everyone,

This is the 400th blog entry.  I want to thank everyone who follows my blog, reads, and comments on my blog.  You rock!

For today’s blog entry, here are some mathematical, and fun facts regarding the number 400.



Mathematical Facts:

20^2 = 400

The divisors of 400 are: 1, 2, 4, 5, 8, 10, 16, 20, 25, 40, 50, 80, 100, 200, and 400.  The sum of these divisors is 961. 

The prime factorization of 400:  400 = 2^4 * 5^2

400 is a composite number.  The nearest primes to 400 are 397 and 401.

Totient function:  ϕ(400) = 160.  That is, there are 160 positive integers less than 400 that are coprime to 400.  That is, the GCD of 400 and such coprime numbers is 1.

A square matrix of 400 x 400 has 160,000 elements.

A gradian (also symbolized as gon) is an angle measure, splitting a circle in 400 angular units.  The gradian is primarily used in civil engineering and surveying in Europe. 

180° = π radians = 200 gon


Computing and Calculator Facts:

The Hewlett Packard HP 12C Platinum Edition finance calculator has a programmable memory of 400 steps. 

Atari released the Atari 400 computer in late 1979.  It was an entry-level computer.  Specifications include:  1.8 MHz processor, 8K RAM (expandable to 48K), and uses a TV screen a monitor.  Resolution of the computer varies, 320 x 192 monochrome to 160 x 96 color screen.  The Atari 400 used cartridges to run programs and games. 

A YouTube Video on the Atari 400, one of many:  https://www.youtube.com/watch?v=UNf8OQaud2M

  
Science Facts:

Visible light that has a wavelength of 400 nm (nanometers) has the color of violet.

On average, the average distance from the Sun to Earth is about 400 times the average distance from the Moon to Earth.     (http://space-facts.com/solar-eclipse/)

A person who has lived 400 days is of age 1 year, and a little more than 1 month.

Rules of the Gregorian Calendar:  Most century years, 1900 and 2100 for example, are not leap years.  However, century years that are divisible by 400, such as 1600, 2000, and 2400, are leap years. (http://www.timeanddate.com/date/leapyear.html)

Games:

If you went around the entire board on a Monopoly game 10 times, you would traveled 400 spaces.

The card game 400, originated in Lebanon, is a trick taking game between two teams of two players.  In 400, players individually make bids to how many tricks they can win.  Hearts is the trump suit.


If you want to play online: http://www.400cards.com/index.php


Business and Entertainment Facts:

This will probably make you jealous, inspired, or maybe both:  Forbes Magazine keeps track of the richest 400 individuals in the United States.  In 2014, the net worth of the Forbes 400 is a combined $2.29 trillion.  (http://www.forbes.com/forbes-400/)

The Barron's 400 index is an index of 400 top stocks.  (http://online.barrons.com/public/page/barrons_400.html)

The Brickyard 400 is an annual NASCAR race in Indianapolis, Indiana.  The race is 400 miles, or about 643.739 km.  (http://en.wikipedia.org/wiki/Brickyard_400,  http://www.indianapolismotorspeedway.com/events/brickyard)

The Walking Dead: The First Season video game by Telltale had a downloadable episode titled “400 Days”, designed as an episode bridge between seasons 1 and 2.  (http://walkingdead.wikia.com/wiki/400_Days)

There is a German music electronic artist named Kenkraft 400.  Chances are if you been to a recent sports event, you have heard “Zombie Nation”. 


Happy 20^2!

Eddie

This blog entry is property of Edward Shore.  2014

Monday, October 27, 2014

HP 12C: Games, Black Scholes, It's History and Solver

At the request of Gene and Thomas Klemm,  here are some more articles and goodies regarding the classic HP 12C calculator:

Article:  "The HP-12C, 30 Years and Counting"  - Richard Nelson and Gene Wright.  

Published in the HP Solve web-letter, October 2011.  This article explains why Hewlett Packard's HP 12C has been a mainstream in the financial calculator market for more than 30 years.  The HP 12C was originally released in 1981. 

Some of the praises of the HP 12C include its long battery life, unclutter keyboard, programming ability,  and a good financial function set.  In 2003, Hewlett Packard released the Platinum Edition of the HP 12C. 

Link:

https://dl.dropboxusercontent.com/u/10022608/_HP-12C%2030%20Yrs%20%26%20Counting%20V6.pdf

Solving Polynomial Equations

In this article, Valentin Albillo shows how the cash flow feature of the HP 12C can be used to solve polynomial equations.  (Datafile V21 N2 - March/April 2002)

Link:

http://www.hpcc.org/datafile/V21N2/V21N2P35.pdf

Games on the HP 12C

Want some games on the HP 12C?  Check out eight programs programmed by Tony Hutchins:
(Datafile V25 N4 - July/August 2006)

Games include:

Craps:  Start by assigning a random seven digit decimal and storing it in [i] and your initial bankroll in [FV].  Each bet is placed in the display before pressing [R/S].  Each dice roll will show tt.xxxx: where tt = total of the dice, xxxx represents the two individual dice.  Example:  7.52:  you rolled a 7 and the dice showed a 5 and a 2.

Dealer/Lotto Routine:  This works with sample without replacement. 

Jive Turkey: Or for you The Price is Right fans, the Clock Game, minus the clock.  The score is indicated by the number of guess you needed to get the right number.  The secret number is between 0 and 99. 

Super Bagels:  Another guess the number game.

Sum of Digits: A number guess game that uses the sum of the digits.

Pontoon/Blackjack:  Simulate the drawing and strategy of each player.  Start by giving a seven-digit seed and storing it in [i].  Press [R/S] to draw new cards.  A negative score indicates a bust. 

Fruit Machine:  Slot machine simulator. 

Lunar Lander:  Land a rocket on the Moon - if you can.  It is a classic calculator game of the 1970s.

Link:  http://www.hpcc.org/datafile/hp12/12c_EightGames.pdf

Full Accuracy of Trigonometry Functions

Not to long ago, I posted two short programs that you can get rough approximations of sine and cosine. This article by Valentin Albillo presents a 99 step program where you can calculate trigonometric functions to full calculator accuracy:

http://web.archive.org/web/20121216113919/http://membres.multimania.fr/albillo/calc/pdf/DatafileVA003.pdf

(DataFile VA003)

Thanks to Jeff Kearns for this suggestion.

Black-Scholes

If you are looking to input an algorithm for Black-Scholes, this article may be what you need.  The article is presented by Tony Hutchins, featuring programs by Dr. Peter Carr (UCLA).

Link:  http://www.hpcc.org/datafile/V23N3/V23N3P25.pdf

(DataFile V23 N3 - May/June 2004)


Amazing what can be done with a financial programming calculator.   Here's to at least another 30+ years of the amazing HP 12C. 

This blog is property of Edward Shore - 2014




 

More Fun with HP 12C (sine, cosine, error function approximations)


Fun with HP 12C Part II


Sine Approximation

Source:  Ted’s Math World, Calculator Magic #4

 
Retrieved 2014-10-13

sin x ≈ (((x^2/72 – 1)*x^2/42 + 1)*x^/20 – 1)*x^2/6 + 1)*x

 Registers:  R0 = x in radians, R1 = sin x

 
STEP
KEY
CODE
STEP
KEY
CODE
01
STO 0
44, 0
21
0
0
02
2
2
22
÷
10
03
y^x
21
23
*
20
04
ENTER
36
24
1
1
05
ENTER
36
25
-
30
06
ENTER
36
26
X<>Y
34
07
7
7
27
6
6
08
2
2
28
÷
10
09
÷
10
29
*
20
10
1
1
30
1
1
11
-
30
31
+
40
12
X<>Y
34
32
RCL 0
45, 0
13
4
4
33
*
20
14
2
2
34
STO 1
44, 1
15
÷
10
35
GTO 00
43, 33, 00
16
*
20
 
 
 
17
1
1
 
 
 
18
+
40
 
 
 
19
X<>Y
34
 
 
 
20
2
2
 
 
 

 
Examples:

sin 0.25 ≈ 0.2474

sin -1.82 ≈ -0.9691

Cosine Approximation

Source:  Ted’s Math World, Calculator Magic #4


Retrieved 2014-10-13

cos x ≈ (((x^2/56 – 1)*x^2/30 + 1)*x^2/12 – 1)*x^2/2 + 1

Registers:  R0 = x in radians, R1 = cos x
 
STEP
KEY
CODE
STEP
KEY
CODE
1
STO 0
44, 0
17
1
1
2
2
2
18
+
40
3
Y^X
21
19
X<>Y
34
4
ENTER
36
20
1
1
5
ENTER
36
21
2
2
6
ENTER
36
22
÷
10
7
5
5
23
*
20
8
6
6
24
1
1
9
÷
10
25
-
30
10
1
1
26
X<>Y
34
11
-
30
27
2
2
12
X<>y
34
28
÷
10
13
3
3
29
*
20
14
0
0
30
1
1
15
÷
10
31
+
40
16
*
20
32
STO 1
44, 1
 
 
 
33
GTO 00
43,33,0
 
 
 
 
 
 

 
cos 0.33 ≈ 0.23847605343

cos -0.58 ≈ 0.83646264991

 
Rough Approximation for erf(x)

If x ≤ 1, accuracy is at least 3 digits.  Method:  3/8 Integration Rule

Source:  Ball, John A.   “Algorithms for RPN Calculators” John Wiley & Sons:  1978.

STEP
KEY
CODE
STEP
KEY
CODE
1
STO 0
44, 0
26
CHS
16
2
3
3
27
e^x
43, 22
3
÷
10
28
+
40
4
2
2
29
8
8
5
Y^X
21
30
÷
10
6
CHS
16
31
3
3
7
e^x
43, 22
32
*
20
8
ENTER
36
33
RCL 0
45, 0
9
RCL 0
45, 0
34
*
20
10
2
2
35
3
3
11
*
20
36
÷
10
12
3
3
37
1
1
13
÷
10
38
.
48
14
2
2
39
1
1
15
Y^X
21
40
2
2
16
CHS
16
41
8
8
17
e^x
43, 22
42
3
3
18
+
30
43
7
7
19
3
3
44
9
9
20
*
20
45
7
7
21
1
1
46
*
20
22
+
40
47
GTO 00
43,33,00
23
RCL 0
45, 0
 
 
 
24
2
2
 
 
 
25
Y^X
21
 
 
 

 

Examples:

x = .15;  Result ≈ 0.1680

x = .50;  Result ≈ 0.5205

x = 1.25; Result ≈ 0.9220  (actual ≈ 0.9229)
 
 
This blog is property of Edward Shore, 2014.

 

 

Python: Drawing a Ring of Circles

Python: Drawing a Ring of Circles The goal: Draw a number of circles that revolve around the origin (0,0). The center of each circle i...