Showing posts with label Wikipedia. Show all posts
Showing posts with label Wikipedia. Show all posts

Saturday, December 27, 2025

Casio fx-991CW: Second Derivative

Casio fx-991CW: Second Derivative


Calculating Higher Order Derivatives


A general formula to estimate derivatives of order n, where n is a positive integer (see Sources, Wikipedia):


d^n/dx^n = lim h→0 (1÷h^n * Σ((-1)^(k+n) * comb(n,k) * f(x+k*h), k=0, n)


The first, second, and third derivatives are derived from the above formula like so:


n = 1:

d/dx

= lim h→0 (1÷h * Σ((-1)^(k+1) * comb(1,k) * f(x+k*h), k=0 to 1)

= lim h→0 (1÷h * ((-1)^(0+1)*f(x) + (-1)^(1+1)*f(x+h))

= lim h→0 (1÷h * (-f(x) + f(x+h))

= lim h→0 (f(x+h) - f(x)) ÷ h


This is the famous forward difference formula.


n = 2:

d^2/dx^2

= lim h→0 (1÷h^2 * Σ((-1)^(k+2) * comb(2,k) * f(x+k*h), k=0 to 2)

= lim h→0 (1÷h^2 * ((-1)^2*comb(2,0)*f(x) + (-1)^3*comb(2,1)* f(x+h) + (-1)^4*comb(2,2)*f(x+2*h))

= lim h→0 (f(x) - 2*f(x+h) + f(x+2*h)) ÷ h^2


n = 3:

d^3/x^3

= lim h→0 (1÷h^3 * Σ((-1)^(k+3 * comb(3k) * f(x+k*h), k=0 to 3)

= lim h→0 (1÷h^3 * ((-1)^3*comb(3,0)*f(x) + (-1)^4*comb(3,1)*f(x+h) + (-1)^5*comb(3,2)*f(x+2*h)

+ (-1)^6*comb(3,3)*f(x+3*h))

= lim h→0 (-f(x) + 3*f(x+h) - 3*f(x+2*h) + f(x+3*h)) ÷ h^3



Using the fx-991CW


- - - - - - - - - -

Start with a note: Commentary and limitations: The functions f(x) and g(x), along with the calculus functions sum (Σ), integral (∫), and derivative (d/dx), has x as variable. It makes it a challenge that x is the only variable the functions f and g can take.


Example:


f(x)=x^2

g(x)=Σ(f(x),x=0 to 5)


Executing g(x) will take the values x=0 through x=5 no matter what value we put for g. The answer, in this example, will always return 0^2 + 1^2 + 2^2 + 3^2 + 4^2 + 5^2 = 55.

- - - - - - - - - -


We can still use f and g to set up specific derivatives in order n. For the second dervative, set up f and g:


f(x) = <function in terms of x>

g(x) = (f(x+2×A)-2×f(x+A)+f(x))÷A²


Store h in A. We can also choose an h and write in the formula directly.


Remember, this will calculate an approximation. With the most appropriate settings for h, we can get the best approximation.


Examples


For all the examples, A is set as 10^-7. The calculator is set to Radians. g(x) is the second derivative approximation.


Example 1:


f(x) = sin(x), f''(x) = -sin(x)

g(x) = (f(x+2×A)-2×f(x+A)+f(x))÷A²


x = 0.6; g(x): -0.564642551 (actual: -0.5646424734)

x = 2.8; g(x): -0.334988057 (actual: -0.3349881502)


Example 2:


f(x) = 2×e^(0.3×x), f''(x) = 0.18×e^(0.3×x)

g(x) = (f(x+2×A)-2×f(x+A)+f(x))÷A²


x = 0; g(x): 9/50 = 0.18 (actual: 0.18)

x = 1.2; g(x): 0.25799928 (actual: 0.2579992946)


Example 3:


f(x) = 1.1×x^3, f''(x) = 6.6×x

g(x) = (f(x+2×A)-2×f(x+A)+f(x))÷A²


x = 0; g(x): 6.6×10^-7 (actual: 0)

x = 2.2; g(x): 14.52 (actual: 14.52)



Sources



McCarty, George. Calculator Calculus. EduCALC Publications. E. & F.N. Spon: London. 1975, ISBN 0- 419-12910-3



Wikipedia "Numeric differentiation" Wikimedia Foundation, Inc. Last Edited June 17, 2025. Last Accessed July 7, 2025. https://en.wikipedia.org/wiki/Numerical_differentiation


Eddie


All original content copyright, © 2011-2025. 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.


The author does not use AI engines and never will.



Sunday, January 13, 2019

HP Prime, TI-84 Plus, and Casio fx-CG 50: Julian Date/Gregorian Calendar Conversions

HP Prime, TI-84 Plus, and Casio fx-CG 50:  Julian Date/Gregorian Calendar Conversions

Introduction

One conversion that is common in astronomy is to convert dates from our Gregorian calendar (the most commonly used day-to-day calendar) to a Julian Date Number, and visa versa.

JD:  Convert Gregorian Date to Julian Date Number

GREG:  Convert Julian Date Number to Gregorian Date

The Julian date number of 2451545 corresponds to January 1, 2000.

Gregorian Date to Julian Date Number

HP Prime Program JD:  Gregorian Date to Julian Date Number
Arguments:  four digit year, month, day
JD(y,m,d)

EXPORT JD(y,m,d)
BEGIN
// Gregorian to Julian
// year, month, day
// 2019-01-12 EWS
//  Wikipedia
LOCAL x0:=IP((m-14)/12);
LOCAL x1:=IP(((1461*(y+4800+x0))/4));
LOCAL x3:=IP(367*(m-2-12*x0)/12);
LOCAL x5:=IP((y+4900+x0)/100);
LOCAL x6:=IP(3*x5/4);
LOCAL j:=x1+x3-x6+d-32075;
RETURN j;
END;

TI-84 Plus Program JD:  Gregorian Date to Julian Date Number

"GREGORIAN TO JULIAN"
"2019-01-13 EWS"
Input "YEAR: ",Y
Input "MONTH: ",M
Input "DAY: ",D
iPart((M-14)/12)→X
iPart(((1461*(Y+4800+X))/4))→A
iPart(367*(M-2-12*X)/12)→B
iPart((Y+4900+X)/100)→C
iPart(3*C/4)→C
A+B-C+D-32075→J
Disp "JD: ",J

Casio fx-CG50 Program JD:  Gregorian Date to Julian Date Number
This version can be typed in directly in the calculator (not a text file)

"GREGORIAN TO JULIAN"
"2019-01-19 EWS"
"YEAR?"→Y
"MONTH"?→M
"DAY"?→D
Int ((M-14)÷12)→X
Int (((1461×(Y+4800+X))÷4)) →A
Int (367×(M-2-12×X)÷12) →B
Int ((Y+4900+X) ÷ 100) →C
Int (3×C÷4)→C
A+B-C+D-32075→J
ClrText
Locate 1,1,"JD"
Locate 1,2,J

Julian Date Number to Gregorian Date

HP Prime Program GREG:  Julian Date Number to Gregorian Date
Argument:  Julian Date Number
GREG(j)

EXPORT GREG(j)
BEGIN
// Julian to Gregorian
// Wikipedia
// 2019-01-12 EWS
LOCAL x1:=IP((4*j+274277)/146097);
LOCAL x2:=IP(x1*3/4);
LOCAL f:=j+1401+x2-38;
LOCAL E:=4*f+3;
LOCAL G:=IP((E MOD 1461)/4);
LOCAL H:=5*G+2;
LOCAL D:=IP((H MOD 153)/5)+1;
LOCAL M:=((IP(H/153)+2) MOD 12)+1;
LOCAL Y:=IP(E/1461)-4716+IP((12+2-M)/12);
RETURN {Y,M,D};
END;

TI-84 Plus Program GREG:  Julian Date Number to Gregorian Date

"JULIAN TO GREGORIAN"
"2019-01-13 EWS"
Input "JD: ",J
iPart((4*J+274277)/146097)→X
iPart(X*3/4)→X
4*(J+1401+X-38)+3→E
5*iPart(remainder(E,1461)/4)+2→H
iPart(remainder(H,153)/5)+1→D
remainder(iPart(H/153)+2,12)+1→M
iPart(E/1461)-4716+iPart((12+2-M)/12)→Y
Disp "YEAR, MONTH, DAY:",Y,M,D

Casio fx-CG50 Program GREG: Julian Date Number to Gregorian Date 
This version can be typed in directly in the calculator (not a text file)

"JULIAN TO GREGORIAN"
"2019-01-13 EWS"
"JD"?→J
Int ((4 ×J+274277) ÷146097) →X
Int (X ×3 ÷4) →X
4 ×(J+1401+X-38)+3 → E
5 × Int( MOD(E,1461) ÷ 4)+2 → H
MOD(Int  (H ÷153)+2,12)+1 →M
Int (E ÷1461) -4716+Int ((12+2-M) ÷12) → Y
ClrText
Locate 1,1,"YEAR, MONTH, DAY"
Locate 1,2,Y
Locate 1,3,M
Locate 1,4,D

Examples

Gregorian Date:  1988, October 31
JD:  2447466

Gregorian Date:  1999, January 11
JD:  2451190

Gregorian Date:  2017, March 21
JD:  2457834


Source:

"Julian Day"  Wikipedia.  Edited (when retrieved) November 19, 2018.  Retrieved January 11, 2019.  https://en.wikipedia.org/wiki/Julian_day

Eddie

All original content copyright, © 2011-2019.  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.  Please contact the author if you have questions.

Sunday, September 25, 2016

HP Prime Basic Planetary Data

HP Prime Basic Planetary Data

The program PLANETS and PLANETDATA retrieve data about our solar system planets, including our dwarf planet, Pluto. 

PLANETS presents you with a choose menu which will present a screen of all the data for a planet.



PLANETDATA allows you to retrieve a specific item for a planet.  PLANETDATA has two arguments:  n for the planet, k for the data point.  This is useful if you want to pull out a specific data point for calculations.

Table for PLANETDATA(n, k):                              
Value
Planet (n)
Data Point (k)
1
Mercury
Name of the Planet
2
Venus
Radius (km)
3
Earth
Mass (kg)
4
Mars
Gravity (m/s^2)
5
Jupiter
Density (g/cm^3)
6
Saturn
Axial tilt (°)
7
Uranus
Period (days)
8
Neptune
Number of Moons
9
Pluto (dwarf planet)


Example:

The gravity on Mars.  PLANETDATA(4,4) returns 3.71 m/s^2.

The diameter of Saturn.  PLANETDAT(6,2) returns 58,232 km.



HP Prime Program:  PLANETS
EXPORT PLANETS()
BEGIN
// Solar System Data
// solarsystem.nasa.gov
// EWS 2016-09-25

LOCAL head, data, n, k, str;
head:={"Planet","Radius (km)",
"Mass (kg)","Gravity (m/s^2)",
"Density (g/cm^3)",
"Axial tilt (°)",
"period (days)",
"# Moons"};
data:={{"Mercury",2439.7,
3.30104ᴇ23,3.7,5.427,.034,
58.646,0},
{"Venus",6051.8,
4.86732ᴇ24,8.87,5.243,177.36,
243.018,0},
{"Earth",6371,
5.9722ᴇ24,9.80665,5.513,23.4393,
365.24,1},
{"Mars",3389.5,
6.4169ᴇ23,3.71,3.934,25.19,
687,2},
{"Jupiter",69911,
1.89813ᴇ27,24.79,1.326,3.1,
4332.59,67},
{"Saturn",58232,
5.68319ᴇ26,10.4,.687,26.7,
10759.22,62},
{"Uranus",25362,
8.68103ᴇ25,8.87,1.27,97.8,
30688.5,27},
{"Neptune",24622,
1.0241ᴇ26,11.15,1.638,28.3,
60182,14},
{"Pluto",1151,
1.3090ᴇ22,0.66,2.05,122.53,
90560,5}
};

CHOOSE(n,"Planet",{"Mercury","Venus",
"Earth","Mars","Jupiter","Saturn",
"Uranus","Neptune"});

// Print Screen

PRINT();
FOR k FROM 1 TO SIZE(head) DO
str:=head(k)+": "+data(n,k);
PRINT(str);
END;

RETURN "Done.";

END;

HP Prime Program: PLANETDATA
EXPORT PLANETDATA(n,k)
BEGIN
// Solar System Data
// solarsystem.nasa.gov
// Individual data
// Get data on the fly
// EWS 2016-09-25


LOCAL head, data;
head:={"Planet","Radius (km)",
"Mass (kg)","Gravity (m/s^2)",
"Density (g/cm^3)",
"Axial tilt (°)",
"period (days)",
"# Moons"};
data:={{"Mercury",2439.7,
3.30104ᴇ23,3.7,5.427,.034,
58.646,0},
{"Venus",6051.8,
4.86732ᴇ24,8.87,5.243,177.36,
243.018,0},
{"Earth",6371,
5.9722ᴇ24,9.80665,5.513,23.4393,
365.24,1},
{"Mars",3389.5,
6.4169ᴇ23,3.71,3.934,25.19,
687,2},
{"Jupiter",69911,
1.89813ᴇ27,24.79,1.326,3.1,
4332.59,67},
{"Saturn",58232,
5.68319ᴇ26,10.4,.687,26.7,
10759.22,62},
{"Uranus",25362,
8.68103ᴇ25,8.87,1.27,97.8,
30688.5,27},
{"Neptune",24622,
1.0241ᴇ26,11.15,1.638,28.3,
60182,14},
{"Pluto",1151,
1.3090ᴇ22,0.66,2.05,122.53,
90560,5}
};

IF n==0 THEN
RETURN head;
ELSE
RETURN data(n,k);
END;

END;

Sources:

NASA Solar System Exploration.  https://solarsystem.nasa.gov/


We pages retrieved during September 21, 2015 to September 25, 2015



This blog is property of Edward Shore, 2016.

HP 71B Basic and Casio fx-CG 100: Weighted Random Sample

HP 71B Basic and Casio fx-CG 100: Weighted Random Sample Introduction In calculators, it is fairly easy to generate a rand...