Tuesday, October 17, 2017

TI-84 Plus CE: Version 5.3 Highlights

TI-84 Plus CE:  Version 5.3 Highlights

Piecewise Function

The piecewise( function is added to the Math menu under the math submenu, option B.  As a result, the equation solver has been moved to option C.  The piecewise function can hold from 1 to 5 pieces.



Conditions Template

Version 5.3 adds 16 test templates involving the variable X to the Test menu ([2nd] [math]).  This is meant to compliment the new piecewise function, especially in function graphing.  However, the variable can be changed as needed.  The screen shot below shows a condition template with a piecewise function.



Demo:


Tangent Drawing Command Adds Option to Store Tangent line

When a function is drawn, you can calculate and draw the tangent line at any continuous point while you are on the graph screen.  Version 5.3 adds the option to store the Tangent line to any available graphing equation (Y# for example).  The new functionality is available only in the Function mode. 

To generate the Tangent line, press [2nd] [prgm] (draw), option 5 to call up the Tangent command.  Arrow to the desired point.  Press [graph/f5] (MENU) for options.  Select your options, then press [enter].   Use either arrow keys or enter a number to get to a point and commence drawing the tangent line.

A demonstration is shown below.



Program Editing Tools

It’s been a long time coming:  the TI-84 Plus CE now has editing tools!  We now can insert comments (comments are indicted with quotation marks), insert blank lines, copy, cut, and paste lines.  There is even an option to execute the program immediately.  It is all accessible from pressing [alpha] [graph/f5].


Running Archived Programs

You can now run archived programs without unarchiving the program into RAM first.  We still need to unarchive programs in order to edit them. 



Other

*  Running assembly programs will no longer require the asm( command.

* The fraction bar can be called by [alpha] [X,T,θ,n].

Documentation and Download

You can find additional details and other updates here and more tips here:  file:///C:/Users/Edward/Downloads/Whats-New-TI-84-Plus-CE-Graphing-Release-History%20(1).pdf

Download version 5.3 from Texas Instruments here:  https://education.ti.com/en/product-resources/whats-new-84-ce

Source:  Texas Instruments.  “TI-84 Plus CE Graphing Calculator Release History: v5.2 and above”  2017 (see above for the link)

Eddie


This blog is property of Edward Shore, 2017

Thursday, October 12, 2017

Adventures in Python: Plotting Sine and Cosine, The numpy Module

Adventures in Python:  Plotting Sine and Cosine, The numpy Module

This program will require that you have both numpy and matplotlib.  If you are working with Pythonista for the iOS, the two modules are included.  Other versions of Python require that you download matplotlib and numpy separately. 


Pointers:

1. The module numpy works with functions with lists as arguments.  There is a math function associated with numpy.  See the section on numpy functions below.

2.  It is helpful to set up all the graphing parameters before showing the graph with pylplot.show().

3. Color strings are six digit hexadecimal integers with the format ‘#RRGGBB’ (R = red, G = green, B = blue)

4.  To turn the plot grid on, use pyplot.legend().  To turn on the legend on use pyplot.legend().  Labels are defined in pyplot.plot


Program:

# this will require matplotlib
# download if needed

# radians mode is the default
import matplotlib
from matplotlib import pyplot

# will need numpy to generate lists
import numpy

# we will need math module for pi
import math

# generate lists
x = numpy.linspace(-2*math.pi, 2*math.pi, 50)
# sin and cos are included in numpy
y1 = numpy.sin(x)
y2 = numpy.cos(x)
y3 = numpy.sin(x)+numpy.cos(x)
# alt for y3: numpy.add(y1,y2)


# the plot begins
pyplot.plot(x,y1,color = '#228b22', label = 'sin x')
pyplot.plot(x,y2,color = '#ffa500', label = 'cos x')
pyplot.plot(x,y3,color = '#919811', label = 'sin x + cos x')


# turn grid on
pyplot.grid(True)
# labels
pyplot.title('Trig Plots 007')
pyplot.xlabel('x')
pyplot.ylabel('y')
# turn legend box on
pyplot.legend()
# show the plot
pyplot.show()

Output:




Some Numpy Functions

numpy.add(list 1, list 2)    Adds two lists, element by element.

numpy.subtract(list 1, list 2)   Subtracts list 2 from list 1, element by element.

numpy.mutiply(list 1, list 2)   Multiplies two lists, element by element.

numpy.divide(list 1, list 2)    Divides list 1 by list 2, element by element.

numpy.power(list 1, list 2)    Calculates list 1**list 2.

numpy.maximum(list 1, list 2)  Takes the maximum of each respective pair.

numpy.minimum(list 1, list 2)   Takes the minimum of each respective pair.

numpy.round(list, number of decimal places)  Round each element.

Other element by element operations: (one list arguments – Radians is the default angle measure)

numpy.square
numpy.sqrt
numpy.cbrt (cube root)
numpy.absolute
numpy.sin
numpy.cos
numpy.tan
numpy.radians (convert to radians)
numpy.asin
numpy.acos
numpy.atan
numpy.degrees (covert to degrees)
numpy.exp
numpy.log (ln)
numpy.real
numpy.imag
numpy.angle
numpy.log10 (log)
numpy.sinc
numpy.i0 (Bessel first kind, order 0)

Until next time,

Eddie


This blog is property of Edward Shore, 2017.

HP Prime and Casio fx-CG 50: Leap Year Test

HP Prime and Casio fx-CG 50: Leap Year Test

Introduction

The presented program tests whether a year is a leap year.  A leap year has 366 days instead of 365, with the extra day given to February (February 29).  The criteria for a leap year are:

* Leap years are year numbers evenly divisible by 4.  Example:  1992, 2016
* Exception:  years that are divisible by 100 but not divisible by 400.  Example:  2000 is a leap year, but 1900 and 2100 aren’t.

HP Prime Program ISLEAPYEAR

EXPORT ISLEAPYEAR(y)
BEGIN
IF FP(y/4) ≠ 0 OR (FP(y/100) == 0 AND FP(y/400) ≠ 0)
THEN
RETURN 0;
ELSE
RETURN 1;
END;
END;


Casio fx-CG 50 ISLEAPYR

“YEAR”? → Y
If Frac(Y ÷ 4) ≠ 0 Or (Frac(Y ÷ 100) = 0 And Frac(Y ÷ 400) ≠ 0)
Then
“No”
Else
“YES”
IfEnd

Eddie


This blog is property of Edward Shore, 2017.

HP 12C: Percent Markup and Percent Margin

HP 12C:  Percent Markup and Percent Margin

I would like to thank Gamo for this question. 

Calculating Percent Markup and Percent Margin

Two common calculations in business is calculating the percent margin and markup.  The formulas are:

Percent Markup = (Selling Price – Cost) / Cost

Percent Margin = (Selling Price – Cost) / Selling Prices

There is no dedicated keys on the HP 12C for this, but we can use either the percent change key ([ Δ% ]) key or the TVM keys.

Using the Percent Change Key

Percent Markup:  cost [ ENTER ] price [ Δ% ]

Percent Margin:  price [ ENTER ] cost [ Δ% ] [ CHS ] (note that the arguments are in reverse order)

Example:  Cost:  25.00,  Price:  36.00

Percent Markup:  25.00 [ENTER] 36.00 [ Δ% ],  result:  44.00

Percent Margin:  36.00 [ENTER] 25.00 [ Δ% ] [CHS], result:  30.56

Using the TVM Keys

Clear the registers before you begin.  For this exercise, PMT = 0.

Percent Markup with TMV solver (HP 12C):  
Let N = 1 and PMT = 0
[ i ] = percent markup
[ PV ] = cost (enter/displayed as a negative)
[ FV ] = price

For our example:
N = 1, PV = -25, FV = 36.  Solving for i gets 44.

Percent Margin with TMV solver (HP 12C):  
Let N = 1 and PMT = 0
[ i ] = percent margin (enter/displayed as a negative)
[ PV ] = price (enter/displayed as a negative)
[ FV ] = cost

For our example:
N = 1, PV = -36, FV = 25.  Solving for i, then pressing [CHS] obtains 30.56.

What is good about the above method is that you can solve for any of the variables.

More Methods:  Solutions Handbook

Detailed algorithms for business calculations can also be found in the HP 12C Advanced Solutions Handbook (see source below).  For the Platinum edition of the Solutions Handbook, refer to page 92. 

Source:
Tony Hutchins, Luiz Vieria, and Gene Wright.  HP 12C Platinum Solutions Handbook.  Hewlett Packard Development Company, L.P.  Rev. 03.04  2004

This book can be downloaded from this site (and others) at no cost:  https://support.hp.com/us-en/product/hp-12c-platinum-financial-calculator/384706/model/315565/manuals


Eddie


This blog is property of Edward Shore, 2017.

Sunday, October 8, 2017

Adventures in Python: Generating Random Numbers

Adventures in Python:  Generating Random Numbers

This program generates a list of random numbers between 0 and 1, using the pseudo-random number generator frac((π + t)^5). 

To use a pseudo-random number generator, you will need an initial seed.  This program uses the fractional part of the number of ticks from January 1, 1970.  To get ticks, you will need to import the time module.  Call the number of ticks by the time.time() function.

Python has no native fractional part.  To extract the fractional part of a number, the following formula is required, where t is any variable:

t = t – math.trunc(t)

The function math.trunc(t) truncates t and returns the integer part.

Keep in mind, to generate n items, use the for loop with the in range(0, n-1)

# Program 006 - Random Number Generation
print("Random number generation")

# import time, use as a seed
import time
t = time.time()
print

# since t is a floating number
# lets import math and use
# math.trunc

import math
t = t - math.trunc(t)

# We are going to use a psuedo-random
# formula to generate n numbers.  n
# will be an integer as range requires.
n = int(input("How many random numbers?"))
for k in range(0,n-1):
     t = (math.pi + t)**5
     t = t - math.trunc(t)
     print(t)

Output (15 numbers generated):

Random number generation
How many random numbers?15
0.8619577822222482
0.5526325838995945
0.045018018769951595
0.5829554424582284
0.7503835409480644
0.9988016770092827
0.770091723446285
0.8387765088751848
0.11795716208871454
0.9494124177641083
0.9088916269388392
0.2717401531838277
0.3329376152682926
0.38460892637095867
(your answers will vary)

Eddie


This blog is property of Edward Shore, 2017.

Adventures in Python: Combinations and Permutations

Adventures in Python: Combinations and Permutations

This program offers the user a choice of one of three calculations:

1.  Combinations, no repeats
2.  Permutations
3.  Combinations, with repeats

The program demonstrates how a menu is made.  Equality is tested with two equal signs (==).  A single equal sign (=) represents assignment for the Python.

The math.factorial function uses integers.

#  Program 005: Combinations, Permutations, Repeated Combination
#  Demonstration of the If structure

import math
# factorial is only for integers

# choices
# we will need to format the choice variable as an integer (number)
print("Make your choice:")
print("1.  Combination")
print("2.  Permutation")
print("3.  Repeated Combination")
choice = int(input("Choice: "))

# error condition, also input routine
if choice < 1 or choice > 3:
    print("Not a valid choice")
else:
    n = int(input("n = "))
    r = int(input("r = "))
    nf = math.factorial(n)
    rf = math.factorial(r)
    df = math.factorial(n-r)

# calculation test.  Equality is tested using 2 equal signs
if choice == 1:
    calc = nf/(df*rf)
    print("Combinations = ",calc)

if choice == 2:
    calc = nf/df
    print("Permutations = ",calc)

if choice == 3:
    calc = math.factorial(n+r-1)/(rf*math.factorial(n-1))
    print("Combinations = ",calc)

Example: n = 52, r = 5

Make your choice:
1.  Combination
2.  Permutation
3.  Repeated Combination
Choice: 1
n = 52
r = 5
Combinations =  2598960.0
>>>
Make your choice:
1.  Combination
2.  Permutation
3.  Repeated Combination
Choice: 2
n = 52
r = 5
Permutations =  311875200.0
>>>
Make your choice:
1.  Combination
2.  Permutation
3.  Repeated Combination
Choice: 3
n = 52
r = 5
Combinations =  3819816.0

Eddie


This blog is property of Edward Shore, 2017.

Thursday, October 5, 2017

Adventures in Python: List Manipulation

Adventures in Python: List Manipulation

This program creates two lists, one from 0 to 11, the other from 12 to 23.  Lists are enclosed by square brackets ( [ ] ).  Here is a short demo script.

# Program 004:  List manipluation

# Start with a range of 0 to 11
list1 = list(range(12))
# Let a second list range from 12 to 23
list2 = list(range(12,24))
print(list1)
print(list2)

# reverse the order
# use sorted in Python 3
print("Reverse List Elements")
list3 = sorted(list1, reverse=True)
list4 = sorted(list2, reverse=True)
print(list3)
print(list4)

# combine two (or more) lists
print("Combine lists with + ")
list5 = list1 + list2
print(list5)


# print the first two elements of each elements
print("First two elements of each list")
for k in range (0,2):
    a = list1[k]
    b = list2[k]
    print([a,b])


# sums, minimum, and maximum of each list
print("Sum, minimum, and maximum of each list")
print("Sum : ",sum(list1),sum(list2))
print("Minimum : ",min(list1),min(list2))
print("Maximum : ",max(list1),max(list2))


Output:

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
[12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]
Reverse List Elements
[11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
[23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12]
Combine lists with +
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]
First two elements of each list
[0, 12]
[1, 13]
Sum, minimum, and maximum of each list
Sum :  66 210
Minimum :  0 12
Maximum :  11 23


Coming up, combinations and permutations, random numbers, and plotting. 

Eddie


This blog is property of Edward Shore, 2017

Adventures in Python: Trigonometric Tables

Adventures in Python: Trigonometric Tables

One of the many mathematical modules available for Python is the math module.  The math functions work with real numbers. 

The program highlighted today also features the for loop.  The for loop is structured differently from what I’m used to.  The for loop works with a range or a list instead of a count of values. 

The range function creates a list of integers, which varies with the syntax:

range(n):  creates a list of integers from 0 to n-1 (the n-1 will take getting used to)
range(a,b):  creates a list of integers from a to b-1

The default angle measurement in Python is radians.  The program builds a tables in increments of 10°, so I must use the math.radians function to convert angles to radians for the table to work properly.

# Program 003:  Trig tables
# Python works with radians
# If you want degrees, use the math.radians, math.degrees to convert

# Import the math library
import math

# Header
print("Angle","sin","cos","tan")

# Build a table with 0 to 180 degrees of trig (sin, cos, tan)
# range:  range(start, stop, step)
# range ends when stop is equalled or exceeded
# since I want 180, I will tip the upper limit to 181
# The for structure defaults to integers
# For structure is used

# rounded values
print("Rounded to 6 decimal places")
print("A list format is used")
print(["angle"," sin "," cos "," tan "])
for k in range(0,181,10):
    # round each compoment
    s = round(math.sin(math.radians(k)),6)
    c = round(math.cos(math.radians(k)),6)
    t = round(math.tan(math.radians(k)),6)
    print([k,s,c,t])

Output:

Angle sin cos tan
Rounded to 6 decimal places
A list format is used
['angle', ' sin ', ' cos ', ' tan ']
[0, 0.0, 1.0, 0.0]
[10, 0.173648, 0.984808, 0.176327]
[20, 0.34202, 0.939693, 0.36397]
[30, 0.5, 0.866025, 0.57735]
[40, 0.642788, 0.766044, 0.8391]
[50, 0.766044, 0.642788, 1.191754]
[60, 0.866025, 0.5, 1.732051]
[70, 0.939693, 0.34202, 2.747477]
[80, 0.984808, 0.173648, 5.671282]
[90, 1.0, 0.0, 1.633123935319537e+16]
[100, 0.984808, -0.173648, -5.671282]
[110, 0.939693, -0.34202, -2.747477]
[120, 0.866025, -0.5, -1.732051]
[130, 0.766044, -0.642788, -1.191754]
[140, 0.642788, -0.766044, -0.8391]
[150, 0.5, -0.866025, -0.57735]
[160, 0.34202, -0.939693, -0.36397]
[170, 0.173648, -0.984808, -0.176327]
[180, 0.0, -1.0, -0.0]

Eddie


This blog is property of Edward Shore, 2017.

Tuesday, October 3, 2017

Adventures in Python: Input Requires Declaring Type of Input

Adventures in Python: Input Requires Declaring Type of Input

I work with calculators, and in calculator programming, the Input command usually defaults to numerical input.  That is not the case in Python.  Input, without declaration, defaults in strings.  Strings are nice, but don’t usually do well in mathematical calculation.

Ways to use the Input command:

input(‘prompt’)
Input accepted as a string.  We can also use string(input(‘prompt’)).
int(input(‘prompt’))
Input accepted as integers.
float(input(‘prompt’))
Input accepted as real (floating) numbers.
complex(input(‘prompt’))
Input accepted as complex numbers.  In Python, complex numbers are in the form x + yj (instead of x + yi). 

The prompt is an optional string. 

In the following program, thanks to complex(input()) format, inputs are accepted as complex numbers.  This solves the quadratic equation using the quadratic formula. 

One other note, I use the double asterisk (**) for powers.  Examples:  2**2 = 2^2 = 4,  16**0.5 = √16 = 4.  The double asterisk works on complex numbers, opposed to the math.sqrt function.

# Program 002: Quadratic Equation
# header
# note that all comments start with a hashtag

# header
print("a*x^2 + b*x + c = 0")

# the default format of input is string
# we must use complex to all for complex numbers
# complex numbers are in the format real + imag*j
# where j = sqrt(-1).  j is usally i but it is used
# for Python and electronic engineering
a = complex(input("a: "))
b = complex(input("b: "))
c = complex(input("c: "))

# discriminat
# note that powers y^x are used by double asterisk, like this y**x
d = b**2-4*a*c

# root calculation
root1 = (-b + d**(0.5))/(2*a)
root2 = (-b - d**(0.5))/(2*a)

# display results
print("Discriminant =  ",d)
print("Root 1 = ",root1)
print("Root 2 = ",root2)


Output (I give a = 1+6j, b = -9, c = 4 as inputs):

a*x^2 + b*x + c = 0
a: 1+6j
b: -9
c: 4
Discriminant =   (65-96j)
Root 1 =  (-0.1590249844353114-1.5691249198547j)
Root 2 =  (0.4022682276785546+0.10966546039524058j)

More adventures in Python to come! 

Eddie


This blog is property of Edward Shore, 2017.

Adventures in Python: Printing Mathematical Symbols with Unicodes

Adventures in Python:  Printing Mathematical Symbols with Unicodes

Got to start somewhere.  I confess that I am a beginner when it comes to Python. 

With the use of the backslash, followed by a u, then four hexadecimal numbers, Python can print all sorts of symbols not easily found on a standard keyboard.  Some common math symbols and their Unicode:

039A
Δ
03C0
π
2202
2248
03A3
Σ
00B0
°
221A
2260
03A6
ϕ
0283
2264
221E
03C3
μ
03B4
δ
2265
03B8
θ
03BB
λ
2220
03B1
α
03B2
β
03C3
σ
0413
Γ
2205
29A8
2282
2283
221B
221D

A short program that demonstrates calling the Unicode characters:

# Program 001: Python Program
# Unicode is the format \uxxxx
# print command is used
print("This is some of my favorite constants (to 8 places).")
print("\u221A \u2248 1.41421356")
print("\u03C0 \u2248 3.14159265")
print("e \u2248 2.71828183")
print("\u03A6 \u2248 1.61803399")

Anything that comes after the hashtag (#) is a comment. 

Output:

This is some of my favorite constants (to 8 places).
√ ≈ 1.41421356
π ≈ 3.14159265
e ≈ 2.71828183
Φ ≈ 1.61803399
>>> 

Fairly simple.  Next up, I learn about input and the type of objects (the hard way).

Eddie


This blog is property of Edward Shore, 2017.

TI-84 Plus CE: Version 5.3 Highlights

TI-84 Plus CE:  Version 5.3 Highlights Piecewise Function The piecewise( function is added to the Math menu under the math submenu...