Friday, August 29, 2014

Why sin^2 x + cos^2 x = 1

Why does sin^2 x + cos^2 x = 1?  Find out in this video. 
 
 
- Eddie
 
 
 
 

Moore-Penrose Inverse of a Matrix

Moore-Penrose Inverse of a Matrix
(E.H. Moore (1920), Arne Bjerhammar and Roger Penrose (1955))

Programs for the HP Prime and Casio Prizm (can be used for fx-9860g II and fx-9750g II) included

Also known as a pseudoinverse, the Moore-Penrose inverse of a matrix, denoted by A^+ (capital A with a supersubscript of a plus sign), is an inverse of matrix. Different from the "true" matrix inverse, the Moore-Penrose inverse allows for non-square matrices. Primarily, the Moore-Penrose inverses are calculated is assist in solving linear least-square equations.

Properties: Moore-Penrose Inverse

A A^+ A = A
A^+ A A^+ = A^+
(A A^+)^T = A
(A^+ A)^T = A^+

A^+ is unique

Calculation

One method of calculating the Moore-Penrose Inverse is the following:

For matrix A of size m × n:

Let r = row rank of A (number of linearly independent rows)
Let c = column rank of A (number of linearly independent columns)
Usually r = c
The matrix rank, denoted rank(A) = min(r, c)

If r ≤ c and rank(A) = r,
Then A^+ = A^T (A A^T)^-1

If r ≥ c and rank(A) = c,
Then A^+ = (A^T A)^-1 A^T

The programs listed on this blog entry assume the first conditions of each of the test are met, since usually, r = c.

Sources

Schott, James R. "Matrix Analysis for Statistics: 2nd Edition". Wiley & Sons. Hoboken, NJ. 2005

Wikipedia article, retrieved 8/29/2014 - URL:
http://en.m.wikipedia.org/wiki/Moore–Penrose_pseudoinverse


HP Prime Program MPINVERT

Input: MPINVERT(matrix). Execute this from Home or CAS screen.

Program:
EXPORT MPINVERT(mtx)
BEGIN
// 2014-08-27 EWS
// Moore-Penrose Matrix Inverse
LOCAL r,c,d,n;
d:=SIZE(mtx);
r:=d(1);
c:=d(2);
n:=RANK(mtx);
CASE
IF n==c THEN
RETURN (TRN(mtx)*mtx)^-1*mtx;
END;
IF n==r THEN
RETURN TRN(mtx)*(mtx*TRN(mtx))^-1;
END;
DEFAULT
RETURN "No Solution Found";
END;

END;


Casio Prizm Program MPINVERT

The program prompts for the matrix. Since the Prizm does not have a matrix rank command, it is determined by use of the rref command and pair of For loops. This program should work verbatim on the fx-9860g II and fx-9750g II.

The matrix is stored in Mat X. List 1 and Mat Y are used for calculation. The result is stored in Mat Z.

If you are using a TI-84, you would probably use an approach similar to what is presented:

Program MPINVERT
"MOORE-PENROSE INVERSE"
"EWS 2014-08-27"
"MATRIX X"? → Mat X
Dim Mat X→List 1
List 1[1] → R
List 1[2] → C
Rref Mat X → Mat Y
0 → T
For 1 → I To R
For 1 → J To C
If Mat Y[I, J] ≠ 0
Then
T + 1 → T
Break
IfEnd
Next
Next
If T = R
Then
Trn Mat X * (Mat X * Trn Mat X) ^ -1 → Mat Z
"Mat Z"
Mat Z ◢ // display
Stop
IfEnd
If T = C
Then
(Trn Mat X * Mat X) ^ -1 * Trn Mat X → Mat Z
"Mat Z"
Mat Z ◢ // display
Stop
IfEnd
"NO INVERSE"



Examples

Matrix:
[ [ 1, 2, 3 ] [ 3, 4, 0 ] ]

Moore-Penrose Inverse:
[ [ -8/229, 31/229 ] [ 6/229, 34/229 ] [ 75/229, -33/229 ] ]

Matrix:
[ [7, 4, 6, -7] [-1, 5, 3, 3] ]

Moore-Penrose Inverse: (to four decimal places)
[ [0.0489, -0.0338] [0.0194, 0.1092] [0.0360, 0.0600] [-0.0520, 0.0800] ]

This blog is property of Edward Shore. 2014

Saturday, August 23, 2014

General Calculator Advice for School (and Possibly Beyond)


General Calculator Advice for School (and Possibly Beyond)


Last week, I received several emails that ask me to make recommendations for which calculators to purchase. Today I will outline my general thoughts about calculators.


Note: I will assume that tablets, such as the Microsoft Surface and Apple iPad are not allowed in classroom tests. Therefore, the focus of this blog entry will be on physical, tangible calculators and not calculator apps found on tablets and phones.


Non-Graphing Calculators

Today's non-graphing scientific calculators are packed with features. The high-end models include:

* numerical derivatives and numerical integration calculations
* textbook input and output, which includes fractions, exact expressions of π, and exact roots
* a general root finder, along with solvers for two simultaneous equations, three simultaneous equations, quadratic equations, and cubic equations
* statistics with regression analysis
* basic matrix operations (determinant, inverse)
* table generator of a function f(x)
* decimal, binary, hexadecimal, and octal conversions
* a library of conversions and constants (all vary)

If you are interested in obtaining a non-graphing calculator and aim to get the most for your money, I recommend any of the following models. Links of my review are listed below:

Texas Instruments TI-36X Pro
http://edspi31415.blogspot.com/2011/04/ti-36-pro-review.html

Casio fx-115ES Plus
http://edspi31415.blogspot.com/2012/04/review-casio-fx-115-es-plus-review.html

Cannon F-792SGA
http://edspi31415.blogspot.com/2014/05/review-canon-f-792sga-scientific.html

Sharp EL-W516X
http://edspi31415.blogspot.com/2011/09/sharp-el-w516x-review.html

All are solar powered (partially) and that extends the life of the battery. Each can be obtained for approximately $16 - $20, although some office stores do sell the TI-36X as high as $25. The differences between each of the calculators are fairly minor. The interface of the TI-36X has more integrated interface than the others, that is, you will not need to go into separate modes to use matrices and complex numbers. Other than that, any of the four listed above is a solid choice.

The non-graphing calculator that is not solar is the HP 35s from Hewlett Packard. What separates the HP 35s from the others listed is:

* The HP 35s is programmable. Each program is a list of keystrokes. The 35s has about 32,000 bytes of memory.
* The 35s operates in both algebraic and RPN (Reverse Polish Notation) modes. The algebraic mode is not textbook entry.
* Complex number support includes powers, trigonometric functions, exponential functions, and logarithmic functions.
* The factorial function (x!) accepts any real number, not just positive integers.
* The 35s runs on batteries (two CR 2032 batteries)
* The 35s is typically priced in the $50 - $60 range.

Solvers on the 35s include simulteanous equations of order 2 and 3, and a general root finder. Numerical integrals are included.


Graphing Calculators

Most students will probably use a graphing calculator sometime during their studies. Here are some of my thoughts:

TI-83 Plus vs TI-84 Plus: I lean towards the TI-84 Plus simply because it has a faster processor, the display is crisper, and the TI-84 Plus offers textbook entry and output mode (known as MathPrint).

Programming wise, they have 24,000 bytes of RAM. Fortunately, they have a lot more of flash ROM memory which acts like archived storage. (512,000 bytes for the 83 Plus vs 1 MB for the 84 Plus). The archived storage contains programs and calculator applications.

Retail wise, the difference in price is about $10. The 83 Plus costs about $90 retail versus $100 for the 84 Plus.

TI-84 Plus vs TI-84 Plus C Silver Edition: A question of color. Back to school time is a best time to find the TI-84 Plus C Silver Edition at its best price, which normally is about $120 to $140.

My review of the color edition is here:
http://edspi31415.blogspot.com/2013/04/ti-84-plus-c-silver-edition-review.html

Basically, while the color and the rechargeable battery are good additional features, processing sometimes suffers. Other not so good points about the TI-84 C Silver Edition is that the graphing screen is smaller, and we only have 21,000 bytes of RAM to work with.

Of these two, I have to give the edge to the older, monochrome displayed TI 84 Plus.

I personally would not recommend the TI nSpire CX unless you get the CAS edition. I will talk about calculators with CAS in the next edition.

Casio may be cheaper, but is it better? I believe the Casio calculators can go toe to toe with the Texas Instruments counterparts. The user interface is comparable if not easier, and you can mix graph types (function, parametric, and polar) on one graphing screen. All three models I am about to describe have 62,000 bytes of programmable memory and uses a menu and soft key interface. Basically, if you can operate one, you should be easily be able to handle the others.

No worries about whether the teacher can operate a Casio, I recently have seen the Casio models fly off the shelves (at least in the eastern Los Angeles area).

fx-9750G II: This is the basic model, priced around $50. All input and output is algebraic (no textbook input or output). Otherwise, it may be something to consider if you don't want to spend much money or not a fan of math and just need a graphing calculator to get by. I don't have an fx-9750G II - yet and interested in adding this to my collection.

fx-9860G II: This has all the features of the fx-9750G II plus a geometry app, spreadsheet app, textbook input and output (MathIO), backlit screen, and Flash ROM memory. Price typically range from $75 to $90.

fx-CG 10 (fx-CG 20 outside of the United States), better known as the Prizm: This is the fx-9860G II but with color and higher Flash ROM memory. The screen on the Prizm is awesome. Priced about $100.

Prizm vs TI-84 Plus C Silver Edition: Prizm is my choice, hands down.


My choices for recommendations would be: TI-84 Plus (classic monochrome), Casio Prizm.

If you are on a budget and textbook input and output is not a must have, you may want to consider the Casio fx-9750G II.


Calculators with CAS

This class is the upper echelon of calculators, those with a CAS (computer algebraic system). I would only recommend that you consider buying a calculator with CAS if any of the following apply:

* You are in college and plan to obtain a degree in mathematics, engineering, or physics.
* You are planning to take multi-variable calculus, differential equations, and any math classes beyond this level.
* You are a mathematics enthusiast.

Models to consider are these:

Hewlett Packard: HP 50g. I would consider this the standard when it comes to calculators with a CAS. Features include an equation writer, RPN mode, matrix entry mode, multi variable solver, solver templates for general equations, polynomials, and simultaneous equations, and 3D graphing. The 50g has an SD card slot. RPN mode truly shines with the 50g. The current price is about $100.

Hewlett Packard: HP Prime: This is HP's color graphing calculator. I think this has the fastest processor of any calcualtor. The memory is 32 MB, which is a ton. The calculator also has a touch screen, which allows for cursor placement and zooming on graphs. It is powered with a rechargeable battery. Check out the Advanced Graphing app where it is easy to execute implicit plots and open statements. (For example x^2 + y^2 <= 4). The downside is that the RPN mode is very limited. The current price is around $150.

Three other calculators with CAS to consider are:

Texas Instruments: TI nSpire CX CAS: This does not have a touch screen but has a touchpad. I really like the geometry app on this model. Like the Prime, the CX CAS has a color screen and has a rechargeable battery. The user interface is like Microsoft Office, files are created for each project. My biggest gripe about the nSpire is the programming is severely limited and can only interact with home pages. Price is about $150.

Texas Instruments TI-89 Titanium: I would rank this calculator higher except that the screen kind of sucks. The font is tiny and there is little contrast to the screen. Feature wise, then TI-89 is the most advanced of all Texas Instruments calculators, despite the latest operating system was release in 2005. Price is about $150.

Casio ClassPad fx-CP400: I don't have the newest ClassPad, but from what I read it is an upgrade to the ClassPad 330. The screen is large, the keyboard is limited, you do mostly everything with a stylus, and the screen rotated. I think the price is about $150.


My recommendations for calculators with a CAS are the HP 50g and HP Prime. Search my blog for basic programming tutorials for both the HP 50g (RPL Programming Tutorial) and HP Prime.


Hope this helps, and if you have questions, please ask and I will try the best I can to assist. Many thanks for the comments and questions.

Eddie

This blog is property of Edward Shore. 2014


Friday, August 22, 2014

Ice Bucket Challenge (Overtime)

A little bit of a detour from mathematics...

I have been challenged by my best friend since childhood, Robert, and his family to do the ALS Ice Bucket Challenge.  This is to help raise awareness and funds to help find a cure for ALS, commonly known as Lou Gehrig's Disease.   Cold water is refreshing given how hot the summer days and nights have been!   

My video:  http://youtu.be/56UGAtazrwE

Website:  www.alsa.org

I will be making a donation and encourage anybody who wants to participate in the ice bucket challenge and/or (more importantly) make a donation. 

Eddie

 

Thursday, August 21, 2014

Pythonista 2.7 and HP 35S: Given roots of a polynomial, find the coefficients of a polynomial

General

Variables:
Number of Roots: N
Roots: R, S, T, U
Coefficients: A, B, C, D, E

N = 2, roots R and S:
(x - R) * (x - S) → A * x^2 + B * x + C

Formulas:
A = 1
B = -(R + S)
C = R * S

N = 3, roots R, S, and T:
(x - R) * (x - S) * (x - T) → A * x^3 + B * x^2 + C * x + D

Formulas:
A = 1
B = -(R + S + T)
C = R * S + R * T + S * T

N = 4, roots R, S, T, and U:
(x - R) * (x - S) * (x - T) * (x - U) → A * x^4 + B * x^3 + C * x^2 + D * x + E

Formulas:
A = 1
B = -(R + S + T + U)
C = R * S + R * T + R * U + S * T + S * U + T * U
D = -(R * S * T + R * S * U + R * T * U + S * T * U)
E = R * S * T * U


HP-35S: Coefficients To Roots

Program:
C001 LBL C
C002 SF 10 // SF, decimal point, 0
C003 NO OF ROOTS // enter message as an equation
C004 CF 10 // CF, decimal point, 0
C005 INPUT N
C006 4 // error checking
C007 xC008 GTO C113
C009 R-down
C010 2
C011 x>y?
C012 GTO C113
C013 1 // main routine
C014 STO A
C015 INPUT R
C016 INPUT S
C017 RCL N
C018 3
C019 x=y?
C020 GTO C033
C021 R-down
C022 4
C023 x=y?
C024 GTO C054
C025 RCL R // two roots
C026 RCL+ S
C027 +/-
C028 STO B
C029 RCL R
C030 RCLx S
C031 STO C
C032 GTO C101
C033 INPUT T // three roots
C034 RCL R
C035 RCL+ S
C036 RCL+ T
C037 +/-
C038 STO B
C039 RCL R
C040 RCLx S
C041 RCL R
C042 RCLx T
C043 +
C044 RCL S
C045 RCLx T
C046 +
C047 STO C
C048 RCL R
C049 RCLx S
C050 RCLx T
C051 +/-
C052 STO D
C053 GTO C101
C054 INPUT T // four roots
C055 INPUT U
C056 +
C057 RCL+ S
C058 RCL+ R
C059 +/-
C060 STO B
C061 RCL R
C062 RCLx S
C063 RCL R
C064 RCLx T
C065 +
C066 RCL R
C067 RCLx U
C068 +
C069 RCL S
C070 RCLx T
C071 +
C072 RCL S
C073 RCLx U
C074 +
C075 RCL T
C076 RCLx U
C077 +
C078 STO C
C079 RCL R
C080 RCLx S
C081 RCLx T
C082 RCL R
C083 RCLx S
C084 RCLx U
C085 +
C086 RCL R
C087 RCLx T
C088 RCLx U
C089 +
C090 RCL S
C091 RCLx T
C092 RCLx U
C093 +
C094 +/-
C095 STO D
C096 RCL R
C097 RCLx S
C098 RCLx T
C099 RCLx U
C100 STO E
C101 VIEW A // results
C102 VIEW B
C103 VIEW C
C104 RCL N
C105 3
C106 x≤y?
C107 VIEW D
C108 RCL N
C109 4
C110 x=y?
C111 VIEW E
C112 RTN
C113 0 // invoking the error condition
C114 1/x





Pythonista

Input: Enter a vector of coefficients, up to 4 roots
Output: A list of coefficients, in descending order

Note: the triple periods indicate a tab (...)

# let roots be the list of roots, up to 4
# EWS 2014-08-20
import math
roots=input('List of Roots (up to 4):')
n=len(roots)
poly=[1]
# check for order
if n==2:
...# quadratic
...poly.append(-(roots[0]+roots[1]))
...poly.append(roots[0]*roots[1])
...print('List of coefficients: ',poly)
elif n==3:
...# cubic
...temp=-(roots[0]+roots[1]+roots[2])
...poly.append(temp)
...temp=roots[0]*roots[1]+roots[0]*roots[2]+roots[1]*roots[2]
...poly.append(temp)
...temp=-roots[0]*roots[1]*roots[2]
...poly.append(temp)
...print('List of coefficients: ',poly)
elif n==4:
...# quartic
...temp=-(roots[0]+roots[1]+roots[2]+roots[3])
...poly.append(temp)
...temp=roots[0]*roots[1]+roots[0]*roots[2]+roots[0]*roots[3]+roots[1]*roots[2]+roots[1]*roots[3]+roots[2]*roots[3]
...poly.append(temp)
...temp=-(roots[0]*roots[1]*roots[2]+roots[0]*roots[1]*roots[3]+roots[0]*roots[2]*roots[3]+roots[1]*roots[2]*roots[3])
...poly.append(temp)
...temp=roots[0]*roots[1]*roots[2]*roots[3]
...poly.append(temp)
...print('List of Coefficients: ',poly)
else:
...print('Error: not a valid list')


Examples:

Quadratic:
R = 2, S = -4
A = 1, B = 2, C = -8

Cubic:
R = 3, S = -1, T = -3
A = 1, B = 1, C = -9, D = -9

Quartic:
R = 3, S = -1, T = -3, U = 4
A = 1, B = -3, C = -13, D = 27, E = 36

Eddie


This blog is property of Edward Shore. 2014

Saturday, August 16, 2014

Pythonista 2.7: List of Primes, Rotating a List, Maximum of a List, Vandermonde Matrix

List of Primes

# list of primes to n
# 8/13/2014
import math
n=input('maximum n (n>2):')
# start the list of primes
l=[2]
# test all integers from 3 to n
for k in range(3,n+1):
# set flag
x=0
for j in range(2,k-1):
# test for composite menu
if math.fmod(k,j)==0:
x=1
if x==0:
# add to list that k is prime
l.append(k)
# return list of primes
print l


Example: n = 44 returns

[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 41, 43]


I am getting used to the way the range command operates and how the indices go from 0 to n-1, instead of how programming calculators have it: 0 to n.

Rotate a List to the Right

# rotate a list to the right r places
import math
l=input('list: ')
r=input('number of places: ')
n=len(l)
# rotation loop
for k in range(r):
# remember range starts at 0
# remove last element
w=l.pop()
# insert that element at position 0
l.insert(0,w)
# print rotated list
print l


Example:

List: [0, 4, -6, 8]

Number of Places: 2; return [-6, 8, 0, 4]
Number of Places: 3; return [4, -6, 8, 0]

Maximum of a List

import math
l=input('list: ')
# sort the list - without a loop
l.sort()
print l.pop()


Example: [12, 16, 28, 3, 4] returns 28

Vamdermonde Matrix

# building the Vandermonde matrix a row at a time
import math
v=input('vector: ')
n=len(v)

print('Vandermonde Matrix')

# main routine
# power
for i in range(n):
l=[]
# element build
for k in range(n):
l.append(math.pow(v[k],i))
print l


Example:
[0.8, 0.6, -0.5] returns

[1, 0.8, 0.64]
[1, 0.6, 0.36]
[1, -0.5, 0.25]


Enjoy!

Have a great weekend!


Eddie



This blog is property of Edward Shore. 2014

Saturday, August 9, 2014

HP RPN Advance Functions Video Up and Running

This is part two of the RPN Mode for HP Prime tutorial.  This time I am taking about advanced functions, such as numeric integrals, numeric derivatives, summation, and solving equations.

Link to the video:

http://youtu.be/YAJwjpldiak

DETAILS:


Syntax - RPN Mode:
-----
MAX and MIN
Path:  Toolbox, Math, 2, 1 for MAX (2 for MIN)

Syntax:
1:  list or vector
MAX(1) or MIN(1)
 - or -
Numbers on the stack
MAX(n) or MIN(n)   (n is 9 or less)
-----
Factorizing Integers – CAS.ifactor

1.  Enter the integer to be factorized, press the Enter key.
2.  Press Toolbox, CAS, 5, 2, 1 to execute CAS.ifactor(1)
-----
Generating a Sequence - MAKELIST
Path:  Toolbox, Math, 6, 1

Stack:
5:  ‘function in single quotes’
4:  ‘variable in single quotes’
3:  beginning point
2:  ending point
1:  increment/decrement
MAKELIST(5)
-----
Finding the Roots of a Polynomial - CAS. proot
Path:  Toolbox, CAS, 6, 1

Stack:
1:  vector or list of coefficients (decreasing power of x)
CAS.proot(1)
-----
Summation – CAS.sum
Path: Toolbox, Math, 2, 5

Stack:
4:  ‘function in single quotes’
3:  ‘variable’
2:  starting point
1:  finishing point
CAS.sum(4)
-----
Numerical Integration
1.  Press the Template Key, choose ∫ (2nd row, 4th column)
2.  Fill in the template – use capital letters for the variable
3.  Press the Enter Key
4.  Finally, press Toolbox, CAS, 1, 1 to execute CAS.simplify(1)
-----
Numerical Derivative
1.  Store value in the variable: Number, Enter Key, Variable in single Quotes, Shift Key, EEX Key
2.  Press the Template Key, choose ∂ (1st row, 4th column).  Fill in the template – use capital letters
for the variable, and press the Enter Key
3.  Finally, press Toolbox, CAS, 1, 1 to execute CAS.simplify(1)
-----
Matrix Operations
Put the matrix on the stack.  Use the Template Key, choose matrix (1st row, 6th column).

Determinant:  Press Toolbox, Math, 7, 2.  Determinant is calculated automatically. 
Inverse:  Press Shift, then the division key. (x^-1).  This works for square matrices only.
Eigenvalues:  Press Toolbox, Math, 7, 6, 1.  CAS.EIGENVAL is called.  Execute CAS.EIGENVAL(1).
-----
Finding Numerical Roots using FNROOT
Path:  Toolbox, Math, 2, 4
Stack:
3:  ‘function in single quotes’
2:  ‘variable’
1:  guess
Execute FNROOT(3)

Format:   function = 0
-----


Eddie


This blog is property of Edward Shore.  2014
 

Thursday, August 7, 2014

HP Prime Tutorial Videos

There are three new videos up on my YouTube page, which all are tutorials for the HP Prime:

Calculating the Signed Area (Integral):
http://youtu.be/HeX_jLB5s1w

Using the Solve App:
http://youtu.be/PVZNP1NMhvk

RPN Mode Basics:
http://youtu.be/_eHXyGm9sEE


Eddie
 

Thursday, July 31, 2014

Sharp EL-501X (today) vs TI-35 Plus (1989)

TI-35 Plus Notes vs Sharp EL-501X (and almost all of its clones)

Ever wanted a TI-35 Plus? First you could go to eBay or other online stores and try to hunt one down or invest up to $10 for one of the many close-version that are still manufactured and sold today. There is even a version sold at the Dollar Store! (The keyboard of that $1 Store I bought is crappy.) Today I will be comparing the Sharp EL-501X against the 1989 TI-35 Plus (and its solar sister, TI-36 Solar (no X)).

Since I never actually owned a TI-35 Plus, all the information will be from its manual. I did buy a TI-36 Solar guidebook, 20 years ago or so, from a clearance bin at Toys R Us of all places. The Sharp EL-501X I bought this week primarily for this blog entry, and to replace a blue cased EL-501X I gave to my cousin's daughter.

Source of the TI-35 Plus information: www.datamath.org

TI-35 Plus Page: http://www.datamath.org/Sci/Modern/TI-35-PLUS.htm

Side plug: Datamath is an excellent web page for all things Texas Instruments calculators, past and preset.

Commonalities

Internal Digits: 12

Modes:
Computational
Complex Mode
Base Display Modes: Binary, Decimal, Octal, Hexadecimal
One Variable Statistics

Complex Mode is limited to arithmetic. The real part is stored and recalled using the [ a ] key and the [ b ] key is for the imaginary part. ( a + bi )

Base Display Modes (except for Decimal) is limited to arithmetic. To convert numbers, just call their respective mode.

Number of memory registers: 1

Factorial Function: n!. Only takes positive integers or zero unless an error occurs.

Polar/Rectangular Conversions:
[ a ] is used for x and r
[ b ] is used for y and θ

Basic Scientific Function set: hyperbolic functions, trigonometric functions and inverses, exponential functions and inverses, reciprocal, square root, cube root, power, arithmetic, π, 3-decimal random number (usually labeled RND)

Differences

Display:
TI-35 Plus: 10 digits plus 2 digit exponent
EL-501X:10 digits or 8 digit plus 2 digit exponent

Exchange Key:
TI-35 Plus has two: EXC to change the number in the display with the number in the memory register. x<>y exchanges operands in power, root, division, and subtraction calculations.
EL-501X: Only the latter is present, often symbolized by a vertical line with up and down arrows. ( [2ndF] [ ( ] )

Decimal Display Settings:
TI-35 Plus: Four permanent modes: floating, fixed, scientific, engineering
EL-501X: Two permanent modes: floating and fixed. Numbers can be toggled between floating/fixed and scientific notation by pressing [ F ←→ E ]

Things the TI-35 Plus had that the EL-501X and most of the clones do not:

Permutations and Combinations. The TI-35 Plus facilitated the use of the [ a ] and [ b ] keys.

Normal Cumulative Distribution Functions (mean = 0, variance = 1, given z):
R(z): area between 0 and z
Q(z): area from z to positive infinity (upper tail)
P(z): area from negative infinity to z (lower tail)

In more advanced calculators and mathematical software, the normalcdf function calculates P(z) (lower tail).

One variate of the EL-501X, the Canon F-604 has permutations, combinations, memory exchange, and fractions. Unfortunately the one I bought not to long ago, the zero key reseted the calculator, so I had to return it. Hopefully it is not the case with all F-604s.




Yes - entry level scientific calculators still exist in the market.


Take care everyone, thanks for comments and questions. Much appreciated. Eddie


This blog is property of Edward Shore. 2014

Roots of the Cubic Equation - Pythonista 2.7

Roots of the Cubic Equation - Pythonista 2.7

Script:



# Cubic Equations: 2014-07-30 EWS
# need the root
import math
print('ax^3+bx^2+cx+d=0','a!=0')
a=float(input('a='))
b=float(input('b='))
c=float(input('c='))
d=float(input('d='))
# is a root 1?
test=a+b+c+d
if test==0:
r=1
if test!=0:
# first root by Newton's Method
xn=1
x1=xn-(a*xn**3+b*xn**2+c*xn+d)/(3*a*xn**2+2*b*xn+c)
while math.fabs(xn-x1)>1e-13:
xn=x1
x1=xn-(a*xn**3+b*xn**2+c*xn+d)/(3*a*xn**2+2*b*xn+c)
r=x1
print('r=',r)
# second and third roots
ap=a
bp=a*r+b
cp=a*r**2+b*r+c
disc=bp**2-4*ap*cp
if disc<0:
real=-bp/(2.*ap)
imag=math.sqrt(math.fabs(disc))/(2.*ap)
print(r)
print(real,'+/-',imag,'i')
else:
s=(-bp+math.sqrt(disc))/(2.*a)
t=(-bp-math.sqrt(disc))/(2.*a)
print(r)
print(s)
print(t)



Examples:

x^3 - 4*x^2 - 17*x + 60 = 0
a = 1, b = -4, c = -17, d = 60
Roots: 3, 4, 5

2*x^3 + x^2 - 2*x + 1 = 0
a = 2, b = 1, c = -2, d = 1
Roots (approximately): -1.43756, 0.46878 ± 0.35784i

This blog is property of Edward Shore. 2014

Saturday, July 26, 2014

HP Prime: Drawing the Pareto Curve

This program draws the Pareto Curve given a list of frequencies.

Program Name:  PARETO(list of frequencies)

This is best called from the Home Screen and not the program catalog.  The curve drawn is not tracable, but is able to used without having to switch apps.  

 EXPORT PARETO(flist)
// 2014-07-25 EWS
BEGIN
// frequency list
LOCAL lx,ly,I,J,n;
// Setup
n:=SIZE(flist);
lx:=MAKELIST(X,X,1,n);
ly:=flist/ΣLIST(flist);
ly:=REVERSE(SORT(ly));
ly:=cumSum(ly);
// Draw the Curve
RECT();
Xmin:=0; Xmax:=n+1; Xtick:=1;
Ymin:=0; Ymax:=1.1; Ytick:=0.1;

FOR I FROM 1 TO n-1  DO
LINE(lx(I),ly(I),lx(I+1),ly(I+1),#FFh);
END;

FOR I FROM 1 TO n DO
TEXTOUT(ROUND(ly(I),2),lx(I),ly(I),1,#80h);
TEXTOUT(I,I,0,1,#FF0000h);
LINE(I,0,I,1,#D0D0D0h);
END;

FOR I FROM 0.1 TO 1 STEP 0.1 DO
LINE(0,I,n,I,#D0D0D0h);
END;

WAIT(0);
RETURN ly;
END;







Example:  A list of frequencies:  {4, 8, 9, 5}.  Note that the biggest frequency is plotted first, as the program first arranges the frequencies from largest to smallest.  Each point will show the cumulative percentage of the total population.  A list of the cumulative percentages will be returned to the home screen.

Pareto Curve Plot
List of Cumulative Percentages






Eddie


This blog is property of Edward Shore.  2014



Friday, July 25, 2014

Pythonista 2.7: Triangle: Lengths of the side and angle given three points

Pythonista Program: fans.py
Version 2.7

Draws a triangle given three points: S, A, and B with coordinates (sx, sy), (ax, ay), and (bx, by), respectively. Lines formed are SA, SB, and AB. This program finds the lengths of SA, SB, and AB, calculates the angle between SA and SB, and draws the triangle.

Note, the modules math and canvas are used. I think the math module is universal but the canvas module seems to exclusive to Pythonista. Not 100% sure. So if you don't have the canvas module, you can omit the second part of the script out. You will just have text.

Example (see screen shot 2):
S = (10,6)
A = (24,25)
B = (12, -2)

Lengths:
SA = 23.600847442411894
SB = 8.246211251235321
AB = 29.546573405388315
Angle = 129.57940471623766°



Scrpit: fans.py

import math
# find distances and angle
# vertex
print('Vertex Point s')
sx=float(input('sx= '))
sy=float(input('sy= '))
# outer points
print('Point A')
ax=float(input('ax= '))
ay=float(input('ay= '))
print('Point B')
bx=float(input('bx= '))
by=float(input('by= '))
# calculate side lengths sa, sb, and ab
# using the hypot function
sa=math.hypot(sx-ax,sy-ay)
sb=math.hypot(sx-bx,sy-by)
ab=math.hypot(ax-bx,ay-by)
print('|SA|', sa)
print('|SB|', sb)
print('|AB|', ab)
# calcuate the angle between sa and sb
ang=math.acos((sa**2+sb**2-ab**2)/(2.*sa*sb))
ang=math.degrees(ang)
print('Angle beteeen SA & SB:', ang)

# drawing lines - Pythonista
import canvas
# set canvas of 100 x 100 to allow room
canvas.set_size(100,100)
# use pixel (50,50) as the origin
# set stroke line
canvas.set_line_width(.25)
# draw lines
# lines sa and sb are blue
canvas.set_stroke_color(0,0,1)
canvas.draw_line(sx+50,sy+50,ax+50,ay+50)
canvas.draw_line(sx+50,sy+50,bx+50,by+50)
# line ab is dark green
canvas.set_stroke_color(0,0.5,0)
canvas.draw_line(ax+50,ay+50,bx+50,by+50)
# draw axis - gray
canvas.set_stroke_color(0.5,0.5,0.5)
canvas.draw_line(0,50,100,50)
canvas.draw_line(50,0,50,100)



Kind of a little intro to Pythonista, at least for me.

Eddie


This blog is property of Edward Shore. 2014


Tuesday, July 22, 2014

My experience with Python so far (Pythonista iOS App 2.7)

Overall, my experience with Python has not been a great one, especially trying it with using iOS apps. (Update: but it's getting better - see below)

The iOS Python 3.2 app by Jonathan Hosmer crashes a lot on my iPad (3rd generation). Not worth the $2.99 in my opinion.

I also tried the pythoni3.3 iOS app by XiaoWen Huang, which is free to download but has in app purchases. Sadly, this app fails in even in giving simple instructions as the help file will tell you everything of the history and how to use it on other machines, but forget it if you want to find how to invoke the interpreter on the app itself. And it crashes if I try to erase the word "in".

Then there is Pythonista 2.7 which has a great interface. However, I am not sure if the mathematics used by this app is not solid or I lack some obvious command. For instance:


Solving 2 by 2 Systems

Solve for x and y:
Ax + By = E
Cx + Dy = F

where:
x = (D*E-B*F)/(A*D-B*C)
y = (A*F-C*E)/(A*D-B*C)

Below is the code for it:
# solving 2 x 2 systems
print('Ax+By=E, Cx+Dy=F')
A=float(input('A='))
B=float(input('B='))
C=float(input('C='))
D=float(input('D='))
E=float(input('E='))
F=float(input('F='))
det=A*D-B*C
x=(D*E-B*F)/det
y=(A*F-C*E)/det
print(det)
print(x)
print(y)




Example:
A = 2
B = 3.5
C = -1
D = 0.4
E = 0.6
F = -2

The results I get are these:
x = 1.68372093023, y = -7.90697674429

Which is fine. I get comparable results when using other calculators and the MathStudio app to verify my answer.

However, the volume of a sphere tells another story.

Volume of the Sphere

Formula = 4/3 * π * r^3

Here is the program and results for r = 3. First the screenshots:

Script:

import math
r=float(input('Radius='))
vol=4/3*math.pi*r**3
print('volume = ',vol)


r = 2.45; result Pythonista gives: 46.200654262773026

Verifying the answer with an fx-5800p and HP Prime I get: 61.60087235 (correct answer)

r = 3; result Pythonista gives: 84.82300164692441

However, my calculators return 113.0973355.


Again, am I missing something obvious? Or is Pythonista (maybe the language itself) not reliable?


(Updated) Thank you so much Bhuvanesh Bhatt!

Here is the corrected code:

import math
r=float(input('Radius='))
vol=4/3.*math.pi*r**3
print('volume = ',vol)



In version 2.7, which Pythonista runs, the slash operator (/) is treated as integer divsion. So a decimal point after the denominator is required in order to use floating divsion. In version 3, the extra decimal point is not required.


Under the updated code, I get the correct answers. Thanks once again Bhuvanesh!




Let me know your experiences in the comments below. Thanks as always, Eddie.



This blog is property of Edward Shore. 2014

Monday, July 21, 2014

My Mathematical Notes for Python (so far)

Official website: www.python.org

Latest version: 3.4 (at the time of this blog entry)


My mathematical notes on Python so far:

This is from the 3.4 instructions but should hold in the 2.7 version as well. I am trying to find a good iOS app to do this.

* A good suggestion is to watch a few tutorial YouTube videos on Python. Onestopprogramming has a good set of tutorials. Python is capable of doing many things, including working with computer files, my focus will be on some of the mathematical capabilities of Python.

* The uses of the equals symbol ( = ) in Python:

(1) A single equal sign means assignment.
x = 4 stores "4" in the variable x.
str = "Eddie" or str = 'Eddie' stores "Eddie" in the variable str.

(2) Two equals signs mean comparison, does x equal y? ( x = y ?)
12==12 returns True

(3) An exclamation mark in front of an equals sign means the comparison, does x not equal y? ( x ≠ y ?)
12!=12 returns False

* Variables that are assigned are defaulted to strings. In order to use variables to represent numbers, we must first declare them as such. The declarations are:

int: integer
long: long integer
float: floating numbers
complex: complex numbers

Example: float(x) declares x as a floating variable.

* Working with floating numbers can bring "weird results" due to Python internally representing every number as a binary representation (0s and 1s). For example,

2.2 * 2 returns 4.40000000000000004

Although the PC version returns 4.4. So this may just be he iOS or a not so good app I was using a the time (Python 3.3 iOS app).

In order to get this answer in more acceptable form. This requires the format declaration. It's syntax is generally this:

"{:.xf}".format(answer, expression, variable, etc..)

Where x is the number of decimal places desired.

Back to our example, let's express 2.2 * 2 using four decimal places:

"{:.4f}".format(2.2*2) returns '4.4000'

* To access mathematical functions beyond arithmetic, we must first import the math library. This is done usually at the beginning of each script (program).

Syntax: import math

Common math functions are what you would expect:

math.ceil(x): ceiling
math.fabs(x): absolute value
math.factorial(x): factorial of x, integers only
math.gamma(x): the gamma function, Γ(x)
math.erf(x): error function
math.fsum(list): sum of a lists elements (in single square brackets)
math.exp(x): e^x
math.log(x, base): logarithm. Leave base out for natural logarithms ( ln x ).
math.pow(x, y): x^y. More expansive than using the double asterisk. ( x ** y )
math.sqrt(x): √x

math.sin(x), math.cos(x), math,tan(x): sine, cosine, and tangent, respectively. The angle is always in radians.
math.asin(x), math.acos(x), math.atan(x): arcsine, arccosine, and arctangent, respectively. The angle returned is in radians.
There are hyperbolic versions of these functions.

math.degrees(x): convert from radians to degrees
math.radians(x): convert from degrees to radians
math.pi: π
math.e: e

A complete list can be found in the python documentary.

* Quick math symbols that don't need the math library to be imported:

Arithmetic functions: +, -, *, and /. (For those new to programming, * represents × and / represents ÷)

Power: ** (two asterisks)

Modoluo: %

Representing exponential powers of 10: e+N or e-N


That is my quick notes for now. I want to post some programs using the Python language in the upcoming weeks.

Eddie

DM42 and HP 42S: Quadratic Equation, Characteristic Polynomial, and Eigenvalues

DM42 and HP 42S: Quadratic Equation, Characteristic Polynomial, and Eigenvalues The programs are listed for the Swiss Micros DM42 an...