Showing posts with label pendulum. Show all posts
Showing posts with label pendulum. Show all posts

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.

Friday, May 16, 2014

fx-5800p Programs (can apply to Casio graphing calculators also, e.g. fx-9860g, Prizm)

This is a collection of programs I wrote on the Casio fx-5800p. These programs should also work on any Casio Graphing calculator (fx-9860g, fx-9750g, Prizm) since the programming language between Casio calculators remains largely the same.

Now if I can find my fx-5800p that I misplaced last night... *sigh*. Thank goodness for notes!

Notes for the fx-5800p programs:


There are no SIGN or MOD functions. Here are the work arounds I used (see SUN):

SIGN(x):
...
X > 0 ⇒ 1 → X
-X > 0 ⇒ -1 → X
...

n MOD d:
...
N - D Intg( N ÷ D ) → result variable
....

Table of Contents:

1. Rotation of (x, y) (ROTATEXY)
2. Law of Cosines (COSINES)
3. Pendulum: Period and Average Velocity (PENDULUM)
4. Arc Length of a Parabola (QUADLENGTH)
5. Position of the Sun (SUN)



1. fx-5800p: ROTATEXY

Rotates the coordinate (X, Y). The direction of rotation follows the conventional direction (counterclockwise). The variable A represents the angle (θ).

Program:
"X"? → X
"Y"? → Y
"ANGLE"? → A
[ [ X, Y ] ] × [ [ cos(A), sin(A) ] , [ -sin(A), cos(A) ] ]


2. fx-5800p: COSINES

Sides: D, E, F
Corresponding Angles: A, B, C

Program:
Lbl 0
Cls
"KNOWN:"
"1. D,E,F"
"2. A,E,F"
?→I
I = 1 ⇒ Goto 1
I = 2 ⇒ Goto 2
Goto 0
Lbl 1
"D"? → D : "E"? → E : "F"? → F
"A" : cos ⁻¹ (( E ² + F ² - D ² ) ÷ ( 2EF )) → A ◢
"B": cos ⁻¹ (( D ² + F ² - E ² ) ÷ ( 2DF )) → B ◢
"C" : 180° - A - B
Stop
Lbl 2
"A"? → A : "E"? → E : "F"? → F :
"D": √ (E ² + F ² - 2 E F cos A ) → D ◢
"B" : cos ⁻¹ ( ( D ² + F ² - E ² ) ÷ (2DF)) → B ◢
"C": 180° - A - B

3. fx-5800p: PENDULUM

Variables:
D = length of the step or bar holding the pendulum
L = length of the rod or string that is swinging
R = large radius of the circular ring

At the units, enter 0 for US units (set g = 32.174 ft/s^2), anything else for SI units (g = 9.80665 m/s^2).

Calculated:
T = period of the pendulum (the amount of time it takes for the pendulum from one end to the other)
V = average velocity of the pendulum (once in its in full swing)


Program:
Cls
"=0 U.S."
"≠0 SI"
? → G
If G = 0
Then 32.174 → G
Else g → G IfEnd // g from the constant menu (9.80665)
Lbl 0
Cls
"1. ROD 2. STRING"
"3. RING"
?→ I
I = 1 ⇒ Goto 1
I = 2 ⇒ Goto 2
I = 3 ⇒ Goto 3
Goto 0
Lbl 1
"D"? → D : "L"? → L
2 π √( L ÷ 3G ) → T : Goto 4
Lbl 2
"D"? → D : "L"? → L
2 π √(L ÷ G) → T : Goto 4
Lbl 3
"D"? → D : "L"? → L : "R"? → R
2 π √( R ² ÷ GL → T : Goto 4
Lbl 4
"T =" : T ◢ "V =": D ÷ T → V

-----

Test Examples:

Rod: D = 1 m, L = 1.6 m. Results: T = 14.36943096 sec, V = .0695921782 m/s

String: D = 2 m, L = 1.75 m. Results: T = 2.65423008 sec, V = .07535141995 m/s

Circular Ring: D = 2 ft, L = 2 ft, r = 1.2 ft
Results: T = 1.879851674 sec, V = 1.063913727 m/s

4. fx-5800p: QUADLENGTH

Find the length of a parabola given height and width and a corresponding equation:

f(x) = Ax^2 + Bx

Where
A = -4h/l^2
B = 4h/l

Program:
Cls
"LENGTH"? → L
"HEIGHT"? → H
Cls
"COEF OF X ²"
-4 H ÷ L ² ◢
"COEF OF X"
4 H ÷ L ◢
"ARC LENGTH"
∫ ( √ ( 1 + ( -8 H X ÷ L ² + 4 H ÷ L ) ) , 0, L)


Test Data:
L: 16.4, H: 8.2
X^2 coefficient: -.1219512195
X coefficient: 2


5. fx-5800P: SUN

Source for the formulas: http://aa.usno.navy.mil/faq/docs/SunApprox.php

Gives the RA (right ascension) and δ (declination) of the sun at any date. U is the universal time, the time it would be at Greenwich Village (Int'l Date Line).

For the Pacific Time Zone:
Standard Time: PST + 8 hours = UT
Daylight Savings Time: PDT + 7 hours = UT

Program:
"MONTH"? → M
"DAY?" → D
"YEAR"? → Y
"UNIV. TIME"? → U
Deg
100 Y + M - 190002.5 → X
X > 0 ⇒ 1 → X
-X > 0 ⇒ -1 → X
367 Y - Intg( 7 ( Y + Intg( ( M + 9 ) ÷ 12 ) ) ÷ 4 )
+ Intg( 275 M ÷ 9 ) + D + 1721013.5 + U ÷ 24
- .5 X + .5 → D
D - 2451545 → D
357.529 + .98560028 D → G
G - 360 Intg( G ÷ 360 ) → G
280.459 + .98564736 D → Q
Q - 360 Intg( Q ÷ 360 ) → Q
Q + 1.915 sin( G ) + .02 sin( 2G ) → L
L - 360 Intg( L ÷ 360 ) → L
1.00014 - .01671 cos( G ) - .00014 cos( 2 G ) → R
23.439 - .00000036 D → E
tan ⁻¹ (cos(E) tan(L)) → A
If L ≥ 90 And L < 270
Then A + 180 → A
IfEnd
If L ≥ 270 And L < 360
Then A + 360 → A
IfEnd
A ÷ 15 → A
sin ⁻¹ ( sin(E) sin(L) ) → C
"APPROX:"
"RA (HRS)": A ◢
"DEC (DEG)": C


Test Data:
M: 5
D: 14
Y: 2014
U: 19

RA: 3.43 hours
DEC: 18.746°


Eddie

This blog is property of Edward Shore. 2014

Sunday, May 11, 2014

Casio fx-3650p: Programming

HAPPY MOTHER'S DAY! Love you Mom! Thanks for all you do - Eddie

Casio fx- 3650p Programs

To celebrate the recent procurement of a Casio fx-5800p, let's dedicate the next several posts to Casio programming calculators. This one is for the fx-3650p, a programming calculator sold world wide (not so much the United States :( ).

Some pointers about the fx-3650p:

* The fx-3650P has only 7 variables (A, B, C, D, X, Y, and M). To save space, variables are recycled.

* You can apply storage arithmetic to memory M, mainly M+ and M-. On the fx-3650P, M+ and M- can be programmable steps. I am not sure if this is possible on programming models (fx-50f, fx-4500p, etc), but this option is not present in Casio's fx-5800p and current graphing calculators (fx-9860, Prizm, etc).

* With Goto and Label, loops can be constructed. The fx-3650p has four comparative tests (=, ≠, >, and ≥).

* Take advantage of not having to close the final parenthesis and begin able to use implicit multiplication to save space.

With that, here are some programs.

Contents:
1. Circular Sectors
2. Stopping Sight Distance
3. Resistors in Parallel
4. Net Present Value
5. Rod Pendulum
6. Vectors: Dot and Cross Products

Circular Sector

Input:
A = radius
B = angle in degrees

Formulas:
arc length = 2 * r * sin(θ*π/360)
chord length = (r * θ * π)/180

Program: (28 steps)
? → A : ? → B : Deg :
2 A sin ( B π ÷ 360 ◢ A B π ÷ 180


Example:
A = 3.6
B = 44°

Input: Prog # 3.6 EXE 44 EXE

#: 1, 2, 3, or 4, depending on where your program is stored.

Results (to four decimal points);
0.04825 (chord length) EXE
2.7646 (arc length)

Stoping Sight Distance (U.S. Units)

Input:
A = design vehicle speed in miles/hour
B = grade, as a percentage

Standard constants (acceleration of the car of 11.2 ft/s^2 and 2.5 seconds of reaction time) are used.

Source: Goswami, Indramil Ph.D. P.E. "All In One Civil Engineering PE Breadth and Depth Exam Guide" 2nd Edition. McGraw Hill: 2012

Formula:
SSD = 11/3 * v + (1.075*v^2)/(11.2 + .32G)

Program: (32 steps)
? → A : ? → B :
11 A ⌟ 3 + 1.075 A ² ⌟ ( 11.2 + .32 B


Example 1: 50 mph, grade of 0%
Input: Prog # 50 EXE 0 EXE
Result: 423.4 mph

Example 2: 65 mph, grade of -2%
Input: Prog # 65 EXE -2 EXE
Result: 668.8 mph

The next two programs make use of loops.

Total Resistance: Resistors in Parallel

Formula: (1/R1 + 1/R2 + 1/R3 + ... )⁻¹

Note: The fx-3650P allows us to take the M+ to our advantage. Enter each resistor in Ohms. When completed, enter 0 to exit the loop.

Program: (30 steps)
0 → M :
Lbl 0 : ? → A : A = 0 ⇒ Goto 1 :
A ⁻¹ M+ : Goto 0 :
Lbl 1 : M ⁻¹


Example: A circuit has three resistors in parallel of 4 Ω, 3. Ω, and 6 Ω.
Input: Prog # 4 EXE 3 EXE 6 EXE 0 EXE
Result: 1.33333333

Net Present Value

Formulas: Σ (A_M / (1 + B%)^M) for M = 0 to C

Variables:
A = cash flows
B = periodic interest rate
C = number of cash flow (entered in advance)

Calculated Variables:
M = counter
D = total

Program: (51 steps)
? → C : ? → B : 0 → M : 0 → D :
Lbl 0 : ? → A :
D + A ÷ ( 1 + .01 B ) ^ M → D : 1 M+ :
C ≥ M ⇒ Goto 0 : D


Example:
Cash Flow:
CF0 = -$1,000.00
CF1 = $0.00
CF2 = $500.00
CF3 = $750.00
CF4 = $1,000.00
Periodic Interest Rate = 10%
Number of Flows = 4 (don't count the initial flow)

Input:
Prog #
4 EXE (number of flows)
10 EXE (periodic Interest rate)
-1000 EXE (cash flows)
0 EXE
500 EXE
750 EXE
1000 EXE

Results: $659.72 (NPV)

Pendulum of the Rod (U.S. units)

(See the above diagram).
A = length of rod
D = length of the board holding the rod

Formulas:
T = 2 π √( I / (m*g*A))
I = inertia of the pendulum
m = mass of the object
g = gravity constant (9.80665 m/s^2, 32.174 ft/s^2)

Using the rod, where I = 1/3 * m * r^2,
T = 2 * π * √(A/96.522) (US units) or
T = 2 * π * √(A/29.41995) (SI units)

Average velocity: V = D/T

Source: Michael Browne, Ph.D. "Schaum's Outlines: Physics for Engineering and Science" 2nd Edition. McGraw Hill, 2010

Program: (24 bytes for US Units)
? → A : ? → D :
2 π √ ( A ÷ 96.522 ◢ D ÷ Ans


Example:
A = 6 ft., D = 1.4 ft
Input: Prog # 6 EXE 1.4 EXE
Results:
1.566543062 sec (T) EXE
0.89368753 ft/sec (V)

Vectors: Dot and Cross Products

Formulas:
Dot Product:
[A, B, C] • [D, X, Y] = A*D + B*X + C*Y
[A, B, C] × [D, X, Y] = [ B*Y-C*X, C*D-A*Y, A*X-B*D ]

Program: (50 bytes)
? → A : ? → B : ? → C :
? → D : ? → X : ? → Y :
A D + B X + C Y ◢
B Y - C X ◢
C D - A Y ◢
A X - B D


Example:
[ 3, 4, 6 ] • [ -1, 2, 3 ] = 23
[ 3, 4, 6 ] × [ -1, 2, 3 ] = [ 0, -15, 10 ]

Input:
Prog # EXE 3 EXE 4 EXE 6 EXE -1 EXE 2 EXE 3 EXE

Results:
23 (dot product) EXE
0 (cross product, x) EXE
-15 (cross product, y) EXE
10 (cross product, z)

Hope that you enjoy these programs, maybe got a few pointers. Have a great day. I will be working with the Casio fx-5800p for my next blog, which I target to put out next week.

Peace!

Eddie


This blog is property of Edward Shore. 2014

The MU Key on a Four Function Calculator and Programs for the DM42/HP 42S

  The MU Key on a Four Function Calculator and Programs for the DM42/HP 42S Not too long ago, I purchased this very colorful, four funct...