Showing posts with label day number. Show all posts
Showing posts with label day number. Show all posts

Saturday, June 5, 2021

7000G Retro Month - June 5 Edition

7000G Retro Month - June 5 Edition





Introduction


Welcome to the 7000G Retro Month, which features programming for the classic Casio calculators from the mid/late 1980s:  primarily fx-7000G and fx-7500G.  Since the programming language stays similar throughout the years, programs can be translated to the fx-6300G and later graphing calculators with little to no adjustments.  Non graphic programs should be ported to the fx-4000P, fx-4500P (A), fx-3650p (II), fx-50F Plus (II), and fx-5800P with little to no adjustments.  


7000G Retro Month takes place every Saturday during June 2021.


To make text easier to type, I can going to use the following text friendly symbols for the following:


->  for →


/I for ⊿


=> for ⇒


What do you think?   Unicode or simple text equivalents?  


- - - - - - -- - -- - -


Today's subject revolves around General Mathematics.  Enjoy!


- - - -- - - -- - -- -- -



Day Number of the Year


Returns the day number of a year, with January 1 being Day 1 and December 31 being day 365 (or 366 on leap years).  For LEAP? enter 0 for non leap years or 1 for leap years.   


"MONTH"? -> M

"DAY"? -> D

"LEAP"? -> L

M≤2 => D+Int(30.6M+368.8)-399 -> N

M>2 => D+Int(30.6M+1.6)-34+L -> N


Arithmetic-Geometric Mean


The arithmetic-geometric mean of two positive numbers x and y is a convergence of repeated means:


Arithmetic:  a = (x + y)/2

Geometric:  g = √(x y) 


Tolerance:  decimal to determine desired accuracy.  For example, to eight decimal places, set tolerance to 1E-8.  


"AGM"

"A0"? -> X

"G0"? -> Y

"TOL"? -> T

Lbl 1

(X+Y)÷2 -> A

√(XY) -> G

A -> X : G -> Y

Abs (A-G) ≥ T => Goto 1

A /I

G


The final A and G are displayed to show the convergence.  


Now for two classics.


Determinant of a 3 x 3 Matrix


Here the program makes use of the square brackets and indirect storage.  Yes, indirect storage and recall are possible with the fx-7000G and fx-7500G.  Of course, this program is not necessary in later graphing calculators.


A[0] = A

A[1] = B

A[2] = C

A[3] = D

A[4] = E

A[5] = F

A[6] = G

A[7] = H

A[8] = I


Elements are entered left to right, completing row by row.


The determinant is stored in the variable T.


The Isz command is used to increment K by 1.  Since K starts at 0 and K increases by 1 before comparing it, the next command is never going to be skipped.


"3 X 3 DET"

0 -> K

Lbl 1

? -> A[K]

Isz K

K < 9 => Goto 1

A(EI-FH)-B(DI-FG)+C(DH-EG) -> T


Quadratic Formula


I would consider this the "Hello World" of mathematics programs.   


Ax^2 + Bx + C = 0


Let D be the discriminant:  D = B^2 - 4AC.   D is displayed where you can determine the characteristics of the roots:


D ≥ 0:  roots are real, stored in X and Y

D < 0:  roots are complex, that take the form of X + Yi, X - Yi


"A"? -> A

"B"? -> B

"C"? -> C

B^2-4AC -> D /I

D<0 => Goto 1

(-B+√D)÷(2A) -> X

(-B-√D)÷(2A) -> Y

Goto 2

Lbl 1

-B÷(2A) -> X

√ Abs D ÷(2A) -> Y

Lbl 2

X /I Y


Eddie


All original content copyright, © 2011-2021.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


Tuesday, January 21, 2014

HP Prime and HP 32SII: Day Number of the Year

HP Prime and HP 32S: Day Number of the Year

This formula calculates the day number of any date (given month and day). A 365 day year is used. If you are operating with a leap year with dates after February 28, add 1.

Hence in non-leap years, January 1 is Day 1, February 1 is Day 32, etc..., December 1 is 335, and December 31 is 365.

Derivation

Formula Used: Gregorian Calendar

Let: Y = year, D = day, and M = month. Then:

N = IP(365T) + IP(T/4) - IP(T/100) + IP(T/400) + D + IP((153X + 8)/5)

where IP represents the integer portion of number and:

if M≤2, T=Y-1, X=M+12,
otherwise T=Y and X=M.

Source: Dr. Math ( http://mathforum.org/library/drmath/view/66857.html )

To find the day number, use the above formula to get the "Gregorian" day number (better term?) for the date in question and subtract the "Gregorian" day number for January 1. This gives the number of days between January 1 and said date. Since the days between dates does not include January 1, we need to include January 1 by adding 1.

For derivation purposes, let's calculate the days between January 1, 1 (AD) and target month and date of year 1. Add 1 to include January 1. I arbitrary chose 1 as the year for ease of calculation and the "year 1" would have been a 365 day year.

Day Number from January 1 to February 28 (29 for leap years)

Let M = month number (1 for January, 2 for February), D = date number

Day Number: (N_(M,D) - N_(1,1)) + 1

Since M≤2, T=1-1=0 and X=M+12

(IP(365*0) + IP(0/4) - IP(0/100) + IP(0/400) + D + IP((153(M+12)+8)/5)
- (IP(365*0) + IP(0/4) - IP(0/100) + IP(0/400) + 1 + IP((153(1+12)+8)/5)) + 1

= (D + IP((153M+1836+8)/5) - (1 + IP(1997/5))) + 1

= (D + IP(30.6M + 368.8) - (1 + 399)) + 1

= D + IP(30.6M + 368.8) - 399

Day Number for March 1 to December 31

Since M>2, T=Y and X=M. Then, again assuming Y=1:

(IP(365*1) + IP(1/4) - IP(1/100) + IP(1/400) + D + IP((153M+8)/5))
- (IP(365*0) + IP(0/4) - IP(0/100) + IP(0/400) + 1 + IP((153(1+12)+8)/5)) + 1

= (365 + D + IP(30.6M + 1.6)) - (1 + IP(1997/5)) + 1

= (365 + D + IP(30.6M + 1.6) - 399

= D + IP(30.6M + 1.6) - 34

For leap years, add 1.


Summary:

Day Number, 365 Day Year, M≤2:
D + IP(30.6M + 1.6 + 367.2) - (34 + 365) = D + IP(30.6M + 368.8) - 399

M>2:
D + IP(30.6M + 1.6) - 34


HP Prime Program DAYNO

EXPORT DAYNO(M,D)
BEGIN
IF M≤2 THEN
RETURN IP(30.6*M+368.8)+D-399;
ELSE
RETURN IP(30.6*M+1.6)+D-34;
END;
END;


Here it is in RPN format. I broke up some of the larger numbers into an addition of two smaller ones and used flags to keep the program within one label.


HP 32SII

N01 LBL N
N02 CF 0 \\clear flag 0 (any user flag will do)
N03 INPUT M
N04 2
N05 x≥y?
N06 SF 0 \\set flag 0
N07 R-down \\bring M to the X stack
N08 30.6
N09 ×
N10 1.6
N11 +
N12 FS? 0
N13 367.2
N14 FS? 0
N15 +
N16 IP
N17 INPUT D
N18 +
N19 34
N20 -
N21 FS? 0
N22 365
N23 FS? 0
N24 -
N25 CF 0
N26 RTN


Eddie


This blog is property of Edward Shore. 2014

RPN HP 12C: Fibonacci and Lucas Sequences

  RPN HP 12C: Fibonacci and Lucas Sequences Golden Ratio, Formulas, and Sequences Let φ be the Golden Ratio: φ = (1 + √5) ÷ 2...