Sunday, November 27, 2016

TI-84 Plus and HP Prime: Differential Equations and Half-Increment Solution, Numerical Methods

TI-84 Plus and HP Prime:  Differential Equations and Half-Increment Solution, Numerical Methods

Introduction

The program HALFSTEP solves the numerical differential equation

d^2y/dt^2 = f(dy/dt, y, t)  given the initial conditions y(t0) = y0 and dy/dt (t0) = dy0

In this notation, y is the independent variable and t is the dependent variable.

The Method

Let C = f(dy/dt, y, t).  Give the change of t as Δt.

First Step:

With t = t0:
h_1/2 = dy0 + C * Δt/2
y1 = y0 + dy0 * Δt

Loop:

t = t0 + Δt
h_I+1/2 = h_I-1/2 + C * Δt
y_I+1 = y_I +h_I+1/2 * Δt

Repeat as many steps as desired.

This method was presented by Robert M. Eisberg in his 1976 calculator programming book (see source below).

Variables

The program uses the following variables:

C:  d^2y/dt^2.   Represent dy/dt as the variable A, y as the variable Y, and t as the variable T.

The program will always designate Y as the independent variable and T as the dependent variable.

Examples:

Application
C
C for HALFSTEP
Free-Fall
d^2y/dt^2 = g
“9.80665” (SI) or “32.1740468” (US)
Free-Fall with Friction
d^2y/dt^2 = g - α (dy/dt)^2
(α = F/m)
“g - α * A^2”
(sub numeric values for g, α)
Spring
d^2x/dt = -k/m * x
“-k/m * T”
(sub numeric values for k, m)
Pendulum
d^2θ/dt = -α*sin(θ)
(α = -g/l)
“-α * sin(Y)”
(sub numeric values for α)
Damped, Driven Oscillations
d^2x/dt = -α*x – β*dx/dt + γ * sin(ω*t)
“-α*Y-β*A+γ*sin(ω*T)”
(sub numeric values for α, β, γ)


HP Prime Program HALFSTEP

Input:  C.  Use single quotes to enclose d^2y/dt^2.  Represent dy/dt as A, y as Y, and t as T. 

Output:  A matrix of two columns, t and y.

EXPORT HALFSTEP(c,A,Y,D,tmax)
BEGIN
// d^2y/dt^2=C,dy0,y0,Δt,tmax
// EWS 2016-11-17
// C use single quotes
// 'dy=A, y=Y, t=T'

// Radian mode
HAngle:=0;

LOCAL mat:=[[0,Y]],T,H;
LOCAL K:=3,I;

T:=D;
H:=A+EVAL(c)*D/2;
Y:=Y+H*D;
mat:=ADDROW(mat,[D,Y],2);

FOR I FROM 2*D TO tmax STEP D DO
T:=I; A:=H;
H:=H+EVAL(c)*D;
Y:=Y+H*D;
mat:=ADDROW(mat,[I,Y],K);
K:=K+1;
END;

RETURN mat;

END;

TI-84 Plus Program HALFSTEP

Input:  For C, use enclose d^2y/dt^2 in quotes.  Represent dy/dt as A, y as Y, and t as T. 

Output:  A matrix of two columns, t and y.

"EWS 2016-11-27"
Func
Radian
Disp "D²Y/DT²=C"
Disp "USE A=DY/DT,Y,T"
Input "C, USE A STRING:",Y1
Input "DY0:",A
Input "Y0:",Y
Input "DELTA TIME:",D
Input "TIME MAX:",N
[[0][Y]]→[A]
D→T
A+Y1*D/2→H
Y+H*D→Y
augment([A],[[D][Y]])→[A]
For(I,2D,N,D)
I→T:H→A
H+Y1*D→H
Y+H*D→Y
augment([A],[[I][Y]])→[A]
End
[A]^T→[A]

Examples:

Please see the screen shots below.  Both are screen shots from the TI-84 Plus.







Source:  Eiseberg, Robert M.  Applied Mathematical Physics with Programmable Pocket Calculators  McGraw-Hill, Inc:  New York.  1976.  ISBN 0-07-019109-3


This blog is property of Edward Shore, 2016.

Thursday, November 24, 2016

Casio fx-7400g Plus: Program Library

Casio fx-7400g Plus: Program Library


Contents:
* Polar Graphing (POLAR)
* Summation and Integration (FX, SUMFX, INTFX)
* Binomial Expansion (BINOMEXP)
* Forward Triangle Intersection (FORDINT)
* Coordinates of a Traverse (TRAVEZ)
* Quadratic Equation (QUAD)


The classic fx-7400g (we’re talking about the early 2000s) lacked numerical integration, summation, and polar graphing.  Let’s remedy that through programming.

Fortunately any of the programs created on the fx-7400g Plus can be translated literally to later Casio graphing calculators. 


Casio fx-7400g Plus Program POLAR
  
Program POLAR
ClrGraph
Rad
“THETA MIN”? → A
“THETA MAX”? → B
“THETA STEP”? → S
For A → I To B Step S
sin (2I) →  R       (see note below)
PlotOn R cos I, R sin I
Next
DrawGraph

Notes:
*  This is best used when the function list is clear.
*  Set up graph screen parameters (Xmin, Xmax, Ymin, Ymax) before hand.
*  Insert polar functions by editing the 7th line (in italics), using I for θ.  The result must be stored to R  (by → R).

Casio fx-7400g Plus Programs FX, SUMFX, INTFX

The programs SUMFX and INTFX will require the subroutine program FX.  FX is where you insert the function f(x).   The result is stored to Y. 

Program FX
X^2+1 → Y
Return

Program SUMFX
“LOWER”? → L
“UPPER”? → U
0 → T
For L → X To U
Prog “FX”
T + Y → T
Next
“SUM=”
T

Example:  FX contains X^2 +1, with L = 1, U = 15.  Result:  1255
Program INTFX
“LOWER”? → L
“UPPER”? → U
“NO. PARTS”? → N
Rad
L → X
Prog “FX”
Y → T
U → X
Prog “FX”
T + Y → T
(U – L) ÷ N → H
For 1 → I To N-1
L + I * H → X
Prog “FX”
If I Rmdr 2 = 0
Then T + 2*Y → T
Else T + 4*Y → T
IfEnd
Next
T * H ÷ 3 → T
“INTEGRAL=”
T

Example:  FX contains X^2 +1, with L = 1, U = 15, N = 24.  Result:  1138.666667

Casio fx-7400g Plus Program BINOMEXP

The program BINOMEXP shows the coefficients of the binomial expansion (Ax + B)^N.

Program BINOMEXP
“(AX+B)^N”
“A”? → A
“B”? → B
“N”? → N
For 0 → I To N
N nCr I * A^(N-I) * B^I → T
“{COEF, POWER}”
{T, N-I}
Next

Example:  (2x – 3)^2
Results:  {4, 2}, {-12, 1}, {9, 0}   (4x^2 – 12x + 9)


 Casio fx-7400g Plus Program FORDINT

The program FORDINT calculates the third point on a triangle where the coordinates of points A  (xa, xb) and B (xb, yb) are known.  Also, a line towards P point is aimed from point A at angle α° and from point B at angle β°. 

Variable
Casio fx-7400g Plus
Variable
Casio fx-7400g Plus
Variable
Casio fx-7400g Plus
xa
N
ya
S
α
A
xb
O
yb
T
β
B
xp
P
yc
U
γ
C


Source: Casio.   Casio fx-FD10 Pro User’s Guide Tokyo. 2014

Program FORDINT
Deg
“XA”? → N
“YA”? → S
“ANGLE A”? → A
“XB”? → O
“YB”? → T
“ANGLE B”? → B
1 ÷ tan A + 1 ÷ tan B → C
(N ÷ tan B + O ÷ tan A + (T – S)) → P
(S ÷ tan B + T ÷ tan A + (N – O)) → U
180 – A – B → C
“{XP, YP, C}”
P
U
C

Example:
Point A:  (1000, 950), angle towards point P:  30°
Point B:  (1012, 997), angle towards point P:  44°

Result:
Point P:  (approximately) (1024.49237, 975.078358)
Angle γ: 106°

Casio fx-7400g Plus Program TRAVEZ

TRAVEZ calculates the new point knowing the original coordinates, direction, and angle of travel.  The angle 0° comes from due east and rotates counterclockwise.

Program TRAVEZ
Deg
“1ST EAST”? → E
“1ST NORTH”? → N
0 → D
Lbl 1
“DISTANCE”? → I
“ANGLE”? → A
I * cos A + E → E
I * sin A + N → N
D + I → D
“POINT”
{E, N}
“DONE? Y=1”
? → Y
Y ≠ 1 Goto 1
“DISTANCE =”
D

Example:  Initial point (1000,1000)
Distance: 750, Angle:  276; Point {1078.396347, 254.1085785}
Distance: 600, Angle:  35; Point {1569.887574, 598.2544403}
Distance: 700, Angle:  118; Point {1241.25748, 1216.317755}
Total Distance:  2050

Casio fx-7400g Plus Program QUAD

The program QUAD is the quadratic equation which finds the roots of

Ax^2 + Bx + C = 0

Yes, I just can’t resist.

Program QUAD
“A”? → A
“B”? → B
“C”? → C
B^2 – 4AC → D
If D≥0
Then “REAL ROOTS”
(-B + √D) ÷ (2A) → S
(-B - √D) ÷ (2A) → T
Else “ROOTS S+TI”
-B ÷ (2A) → S
√(Abs D) ÷ (2A) → T
IfEnd
{S, T}


Example:
A = 2.5, B = -3, C = -1.1
Roots:  “REAL ROOTS”, 1.494427191, -0.294427191


A = 2.5, B = -3, C = -1.1
Roots:  “ROOTS S+TI”,  -0.375 ± .3665719575i   (T:  -3.665719575)

Happy Thanksgiving!  Eddie


This blog is property of Edward Shore, 2016.





Retro Review: Casio fx-7400g Plus

Eddie’s Math and Calculator Blog:  Retro Review:  Casio fx-7400g Plus

Specifications

Time:  Early 2000s, I have the early style where all the keys are rectangular
Screen:  48 x 80 pixels, 6 x 13 text
Power:  2 AA batteries with 2032 backup
Accuracy:  10 digits shown on screen, 15 digits internally
Memory:  20,000 bytes for programming (despite the 32K label on the calculator)

The calculator feels pretty good to hold, it is lightweight.



A Scaled Down fx-9850g

The fx-7400g Plus is a simplified version of fx-9850g family, marketed as entry level graphing calculator.  The features have been scaled down.  As a result the fx-7400g Plus lacks matrices, distribution functions, numerical integral, and polar graphing.

Casio is known as for their icon menus and the fx-7400g is no exception.  Here is the icon menu:



1:  Run
2:  Statistics
3:  List
4:  Graph
5:  Table
6:  Program
7:  Link
8:  Contrast
9:  Memory

For statistics, the fx-7400g offers the following regressions:  linear, med-med, quadratic, logarithmic, exponential, and power.

Curiosities of the fx-7400g Plus

Instead of the usual six function keys (F1 – F6), the fx-7400g Plus has four function keys, with two of them replaced with [ G<>T ] (graph-table switch) and [ > ] (next menu page).  I don’t know if the [G<>T] key is used today, but it is used two switch between the graph and home screen.  Today, the command only works when the current Casio graphing calculators (like the Prizm fx-CG 10) is in the Linear Input/Output mode. 

When a program is executed, the calculator is returned to the Run mode rather than stay in Program mode.  Exit program execution by pressing [AC/ON].

When Program Mode is entered, all the programs are listed chronically (when they first created).  There is no option to sort the programs alphabetically.

The fx-7400g handles calculations pretty quickly. 

Programming on the fx-7400g Plus

The programming command set on the fx-7400g Plus may be scaled down, but most of the commands we expect on the Casio Graphing calculators are present.  The lack of matrices, complex numbers, and a simplified list command set does provide a challenge, but we should be able to program for a lot of applications.

To get the quotes ( “ “ ), press [ALPHA] then [ F2 ].  This is the only way to get the quotation marks.

Programming Commands Available (not exhaustive):

[“prompt”]?  → var
   (right triangle)
:     (colon for multiple commands)

If Then [Else] IfEnd
Cond do if true: next
Do commands LpWhile cond
While cond commands WhileEnd
Dsz  var:  do if var ≠ 0: stmts  (-1)
Isz var:  do if var  ≠ 0stmts   (+1)
Goto,  Lbl

Break   (break from loops)
Prog “filename” (subroutines)
Return
Stop
ClrGraph
ClrList
ClrText
DrawStat
DrawGraph
DrawTable


Fortunately any of the programs created on the fx-7400g Plus can be translated literally to later Casio graphing calculators. 

I will present programs on next blog entry.

Final Verdict

The fx-7400g Plus is not a bad entry-level calculator.  The early version is more an old-school graphing calculator. 

The updated fx-7400gII Casio now includes integral, polar graphing, base calculations, and complex numbers.  ( Link:  https://edu.casio.com/products/graphic/fx7400g2/ )


Happy Thanksgiving!

Eddie

This blog is property of Edward Shore, 2016.





Saturday, November 19, 2016

HP Prime and TI-84 Plus: Method of Equal Proportions: Number of U.S. Representatives

HP Prime and TI-84 Plus:  Method of Equal Proportions:  Number of U.S. Representatives 

Introduction

The 2016 United States Elections still fresh on the minds of some Americans, even with talk of repealing the Electoral College.  But how does the Electoral College work? 

Each of the 50 states receives a set amount of electoral votes, which is based on the number of House Representatives and Senate members.  Each state gets two Senators. The number of House Representatives is determined by popular.  Every ten years, specifically 1990, 2000, 2010, 2020, and so on, the United States takes nationwide census.  That population becomes the basis of determining the number of House of Representatives.   Currently, there are 435 members of the House.

After the election, each state gives the set number of electoral votes to the candidate who wins the popular vote in that state.  For example, California, where I’m from, has 55 electoral votes.  If Candidate A wins by popular vote in California, that candidate gets 55 votes.  The exceptions are Maine and Nebraska, which use a congressional district method. 

Note:  In the Electoral College, 3 additional votes goes to the District of Columbia.  However, since D.C. is not a state, it won’t get seats in the House of Representatives. 

The Method of Equal Proportions: Determining the Number of Seats

In order to represent the population as fair as possible, methods must be used to distribute the number of seats.  The method currently used is the Method of Equal Proportions, which has been in use since 1940.

The first step is to give each state one seat at the House of Representatives.  For the United States, after each state gets one seat, there are 385 seats to assign.

The population of the states are recalculated by the following formula:

A_n = P / √(m * (m + 1))

where P = the state population, and m = the next potential seat (so for example, if the state currently has 5 seats, m = 6)

A recursive method, the method used in the program EQPROP is used:

A_1 = P / √2

A_n+1 = A_n * √(n/(n+2))

where n = the number the seats the state currently has

Example:  Small Hypothetical Nation

Suppose we have a small hypothetical nation, called the Country of Celestia that consists of five states.  The government is similar to the United States, having both a House and Senate.  Each state has 2 Senators.  The five states have the following population for which 24 seats need to be distributed:

Virgo
148,000
Andromeda
107,500
Orion
95,500
Sagittarius
95,000
Pegasus
93,000
Total
539,000

As the first step, each state gets 1 seat.  That means there are 19 seats remaining. (24  - 5)  I am going to use the recursive definition.

We need to adjust the population (to determine the priority number) by dividing each population by √2.  Note:  calculations in this example are rounded to the nearest integer.

Virgo
104,652
1
Andromeda
76,014
1
Orion
67,259
1
Sagittarius
67,175
1
Pegasus
65,761
1

The next seat (6 out of 24), will go to Virgo because Virgo has the highest adjusted population.  Then Virgo’s next adjusted population will be:  104,652 * √(1/3) = 60,421

Virgo
60,421
2
Andromeda
76,014
1
Orion
67,259
1
Sagittarius
67,175
1
Pegasus
65,761
1

Seat #7, goes to Andromeda, because Andromeda now has the largest adjusted population at 76,014.  Adjusting the population:  76,014 * √(1/3) = 43,887, and Andromeda gets another seat.

After 7 seats, this is what the adjusted population looks like:

Virgo
60,421
2
Andromeda
43,887
2
Orion
67,259
1
Sagittarius
67,175
1
Pegasus
65,761
1

We continue:

Virgo
Andromeda
Orion
Sagittarius
Pegasus
Seat #
Adj. Pop.
# Seats
Adj. Pop.
# Seats
Adj. Pop.
# Seats
Adj. Pop.
# Seats
Adj. Pop.
# Seats
8
60421
2
43887
2
38832
2
67175
1
65761
1
9
60421
2
43887
2
38832
2
38784
2
65761
1
10
60421
2
43887
2
38832
2
38784
2
37967
2
11
42724
3
43887
2
38832
2
38784
2
37967
2
12
42724
3
31033
3
38832
2
38784
2
37967
2
13
33094
4
31033
3
38832
2
38784
2
37967
2
14
33094
4
31033
3
27458
3
38784
2
37967
2
15
33094
4
31033
3
27458
3
27424
3
37967
2
16
33094
4
31033
3
27458
3
27424
3
26847
3
17
27021
5
31033
3
27458
3
27424
3
26847
3
18
27021
5
24038
4
27458
3
27424
3
26847
3
19
27021
5
24038
4
21269
4
27424
3
26847
3
20
27021
5
24038
4
21269
4
21243
4
26847
3
21
22837
6
24038
4
21269
4
21243
4
26847
3
22
22837
6
24038
4
21269
4
21243
4
20796
4
23
22837
6
19627
5
21269
4
21243
4
20796
4
24
19777
7
19627
5
21269
4
21243
4
20796
4

Final Distribution for Celestia (our example):  Virgo, 7 House seats, Andromeda, 5 House seats, Orion, Sagittarius, and Pegasus get 4 each.

On to the programming!

The Program EQPROP

The program EQPROP takes two arguments:  the list of populations, and the number of House of Representative seats to be assigned.  The program assumes that two Senators will also be assigned.

Output:  A matrix of three columns:
Column 1:  The population of each state.  The population is sorted in descending order.
Column 2:  The number of House Representatives.
Column 3:  The number of House Representatives plus the 2 senators.

For the TI-84 Plus:  L1 is used as the population list, lists L2, L3, and L4 are used for calculations, and the results are returned in Matrix [A].

HP Program EQPROP

EXPORT EQPROP(lp,n)
BEGIN
// Method of equal proportions
// 2016-11-18 EWS
// population, no of seats

LOCAL la,s,lr,k,m,p,w;

// initialization
lp:=REVERSE(SORT(lp));
la:=lp/√2;
s:=n-SIZE(lp);
lr:=MAKELIST(1,X,1,SIZE(lp));

// loop
FOR k FROM s DOWNTO 1 STEP 1 DO
m:=MAX(la);
p:=POS(la,m);
w:=lr(p);
la(p):=la(p)*√(w/(w+2));
lr(p):=w+1;
END;

// output, organize matrix
// [population, senate, + house]
LOCAL l2,m2,l3;
l3:=lr+2;
l2:={lp,lr,l3};
l2:=TRN(list2mat(l2,3));
m2:=l2(1);
RETURN m2;

END;

TI-84 Plus Program EQPROP

"EQUAL PROPORTIONS"
"2016-11-18 EWS"
Input "POP. LIST: ",L
Input "NO. OF SEATS: ",N
SortD(L)
L→L
N-dim(L)→S
L→L
Fill(1,L)
L/√(2)→L
"LOOP"
For(K,S,1,­1)
max(L)→M
"POS"
1→P
While L(P)≠M
1+P→P
End
"REST"
L(P)→W
L(P)*√(W/(W+2))→L(P)
W+1→L(P)
End
"OUTPUT"
L+2→L
List>matr(L,L,L,[A])
Pause [A]


Sources:

Burnett, Kristin D.  “Congressional Apportionment:  2010 Census Briefs”  U.S. Census Bureau.  November 2011.  Download the PDF file here:  http://www.census.gov/library/publications/2011/dec/c2010br-08.html

Wikipedia   “Electoral College (United States)”  https://en.wikipedia.org/wiki/Electoral_College_(United_States)  Retrieved November 16, 2016

Wikipedia “United States Congressional Apportionment”  https://en.wikipedia.org/wiki/United_States_congressional_apportionment#cite_note-22   Retrieved November 16, 2016

This blog is property of Edward Shore, 2016


Casio fx-CG50 and TI-84 Plus CE: Multiple Linear Regression

Casio fx-CG50 and TI-84 Plus CE: Multiple Linear Regression We have arrived at the last month of 2024. What a crazy year. I hope for...