Showing posts with label numerical analysis. Show all posts
Showing posts with label numerical analysis. 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.



Saturday, October 18, 2025

Numworks: Estimating the Speed of Sound in Water

 Numworks: Estimating the Speed of Sound in Water


Generally, the speed of sound in water is faster than the speed of sound in air. Is there an easy way to estimate the speed of sound in water using curve fitting? I will use the Numworks’ Regression App. The online simulator of Numworks: https://www.numworks.com/simulator/ .


* For readability, I consolidated some screen shots.


The data, from The Engineering Toolbox (see Source below) is shown in below:


SI Units

Temperature in °C

Speed of sound in m/s (meters/second)

0

1403

5

1427

10

1447

20

1481

30

1507

40

1526

50

1541

60

1552

70

1555

80

1555

90

1550

100

1543


https://www.engineeringtoolbox.com/sound-speed-water-d_598.html





Of the curve fits available, I found the best fits were to be with polynomial regression.


Quadratic Regression: y = a2 * x^2 + a1 * x + a0



y = -0.02736013 * x^2 + 4.059449 * x + 1407.3398


where y is the speed of sound in water (m/s) and x is the temperature (°C). The r^2 parameter is 0.9980768, which is pretty good given the raw data is only rounded the nearest integer. The Numworks also offers residual plot, which is the difference between predicted and given data. From the residual plot, the biggest difference was at x = 0.


Quartic Regression: y = a4 * x^4 + a3 * x^3 + a2 * x^2 + a1 * x + a0



If we are looking for better accuracy, we could use the quartic regression, where r^2 parameter is 0.99981. From the residual plot, the biggest difference was located at x = 60.


y = -7.955665 * 10^-7 * x^4 + 2.523644 * 10^-4 * x^3 – 0.05122094 * x^2 + 4.782147 * x + 1403.692


For a quick calculation, the quadratic equation could be sufficient enough.



Source


The Engineering ToolBox (2004). Water - Speed of Sound vs. Temperature. [online] Available at: https://www.engineeringtoolbox.com/sound-speed-water-d_598.html. Accessed May, 2025.


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.


Saturday, September 27, 2025

fx-991CW: Sums with a Step Not Equal to One

fx-991CW: Sums with a Step Not Equal to One



Step ≠ 1? An Adjustment is Necessary


The summation function on the Casio fx-991 CW calculator, and a lot of other advanced scientific calculators, calculates the sum of f(x) from x = a to x = b, with an increment of 1.


But what if have a sum of following:


log(2) + log(4) + log(6) + log(8): sum(f(x) from x = 2 to x = 8, step = 2)


Clearly, the increment is not 1, but 2 instead. Believe it or not, we can still use the summation function. We will need to adjust both the function and the limits to fit the requirements of the summation function.


1. Adjust f(x) to f(step * x)

2. Adjust the limits to x = a ÷ step and x = b ÷ step


For this particular problem:


1. f(x) becomes log(2 * x)

2. The limits become x = 2 ÷ 2 = 1 to x = 8 ÷ 2 = 4 (this allows the step to be 1)


Which transforms:

sum(log(x) from x = 2 to x = 8, step = 2)

to:

Σ(log(2 * x) from x = 1 to x = 4)



Sum: 2.584331224


A Couple More Examples


Example 1:

sum(x^2 from x = 0.5 to x = 2, step = 0.5), f(x) = x^2


The key here is the step (also known as the increment). The adjustments needed are:

1. f(x) becomes (0.5 * x)^2 = (x / 2)^2

2. The limits become x = 0.5/0.5 = 1 to x = 2/0.5 = 4





Sum: 15/2 = 7.5


Example 2:

sum(e^(x) from x = 1.5 to x = 2.1, step = 0.1), f(x) = e^(x)


The adjustments needed are:

1. f(x) becomes e^(0.1 * x) = e^(x / 10)

2. The limits become x = 1.5/0.1 = 15 to x = 2.1/0.1 = 21





Sum: 43.1994368



In Summary…


For the sum:

sum(f(x), x = a to x = b, step = Δx):


1. Adjust f(x) to f(Δx * x)

2. Adjust the limits: x = a/Δx to x = b/Δx

3. Summation function looks like this: Σ( f(Δx * x), x = a/Δx to x = b/Δx)


Hope you find this useful! Take care,


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, August 21, 2022

Rationalizing a Quadratic Polynomial

Rationalizing a Quadratic Polynomial


Problem


Rewrite the Quadratic Polynomial 1 + A*x + B*x^2 as a rational function of polynomials.  A and B are real numbers (however, this should work if A and B were complex numbers).  


1 + A*x + B*x^2 → p(x) / q(x)


Attempt 1:  1 + A*x + B*x^2 → (1 + C*x) / (1 + D*x)


1 + A*x + B*x^2 = (1 + C*x) / (1 + D*x)

(1 + A*x + B*x^2) * (1 + D*x) = (1 + C*x) / (1 + D*x) * (1 + D*x)

A*x + B*x^2 + D*x + A*D*x^2 + D*B*x^3 = C*x


Comparing the powers of x:


constant:  0 = 0

x:  A + D = C

x^2:  B + A*D = 0

x^3:  B*D = 0


This leads to either B=0 or D=0


Assume B=0. 

Then B + A*D = 0

A*D = 0


If A=0, then D = C, which leads to:

1 + A*x + B*x^2 = (1 + C*x) / (1 + D*x)

1 = (1 + C*x) / (1 + C*x)

1 = 1


If D=0, then A = C

1 + A*x + B*x^2 = (1 + C*x) / (1 + D*x)

1 + C*x = (1 + C*x) 


If D=0, then B=0, and we get the same results as above.   


Ultimately this transformation to (1 + C*x) / (1 + D*x) leads to nothing useful.


Attempt 2:  1 + A*x + B*x^2 → (1 + C*x^2) / (1 + D*x)

 

1 + A*x + B*x^2 = (1 + C*x^2) / (1 + D*x)

(1 + A*x + B*x^2) * (1 + D*x) = 1 + C*x^2 

(A + D)*x + (B + A*D)*x^2 + B*D*x^3 = C*x^2


Comparing the powers of x:


constant:  0 = 0

x:  A + D = 0

x^2:  B + A*D = C

x^3:  B*D = 0


A + D = 0 implies that A = -D or D = -A


Also either B = 0 or D = 0.


Assume B = 0. Then with A = -D:

A*D = C

-D*D = C

C = -D^2


1 + A*x + B*x^2 = (1 + C*x^2) / (1 + D*x)

1 -  D*x = (1 - D*x^2) / (1 + D*x)

1 -  D*x = ((1 - D*x) * (1 + D*x))/ (1 + D*x)

1 - D*x = 1 - D*x


If we assume that D = -A, then:

C = -A^2 and

1 + A*x = (1 - A*x^2) / (1 - A*x)

1 + A*x = ((1 - A*x)  * (1 + A*x)) / (1 - A*x)

1 + A*x = 1 + A*x


Assume D = 0.

Then A = 0 and B = C:

1 + B*x^2 = 1 + B*x^2

1 + C*x^2 = 1 + C*x^2


Again, we have transformations that are trivial.


Attempt 3:  1 + A*x + B*x^2 → (1 + C*x^3) / (1 + D*x)


1 + A*x + B*x^2 = (1 + C*x^3) / (1 + D*x)

(1 + A*x + B*x^2) * (1 + D*x) = 1 + C*x^3

(A + D)*x + (B + A*D)*x^2 + B*D*x^3 = 1 + C*x^3


Comparing the powers of x:


constant:  0 = 0

x:  A + D = 0

x^2:  B + A*D = 0

x^3:  B*D = C


This implies that:

A + D = 0

D = -A


B + A*D = 0

B+ A*-A = 0

B = A^2   (this restricts A and B)


B * D = C

(A^2)*(-A) = C

C = -A^3


We can conclude that B = A^2, C = -A^3, D = -A


The relationship between A, B, C, and D are all connected in this case.


Examples:


A = 2 ⇒ B = 4, C = -8, D = -2 and

1 + 2*x + 4*x^2 = (1 - 8*x^3) / (1 - 2*x)


A = -2 ⇒ B = 4, C = 8, D = 2 and

1 - 2*x + 4*x^2 = (1 + 8*x^3) / (1 + 2*x)



Note:  Casio fx-991EX Week - September 5, 2022 to September 9, 2022 


Eddie


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


Sunday, February 6, 2022

HP 17BII+ and TI-84 Plus CE Python: Zeta Approximation

HP 17BII+ and TI-84 Plus CE Python:  Zeta Approximation


Zeta Function


zeta(x) = Σ(1 ÷ (n^x), n =1 to ∞)


We are going to use the approximation:


zeta(x) = Σ(1 ÷ (n^x), n =1 to w) where w = intg(10^((a + 2) ÷ x)


where a is the number of decimal places desired.  The higher the accuracy, the longer the calculation takes.  Also the lower x is, the longer the calculation takes.


This is for all x > 0.


HP 17BII+ Formula ZETA


ZETA=0×L(W:10^IP((ACC+2)÷X))+Σ(N:1:G(W):1:INV(N^X))


Examples:


ACC =3, X = 2;  Result:  ZETA = 1.63


ACC =3, X = 3.5;  Result:  ZETA = 1.13


ACC =3, X = 8.7;  Result:  ZETA = 1.00


TI-84 Plus CE Python:  zeta.py


# 2021-12-07 ews

# zeta function approximation

from math import *

print("zeta function approximation")

x=eval(input("x? "))

a=eval(input("# places? "))

w=int(10**((a+2)/x)

z=0

n=1

while n<w:

  z+=(n**x)**-1

  n+=1

z=round(z,a)

print("zeta = "+str(z))


Eddie


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


Saturday, March 20, 2021

Testing The Accuracy of LN and EXP Approximations

Testing The Accuracy of LN and EXP Approximations


Introduction


Today we are testing an approximation polynomial for two common scientific functions.  I used a TI-84 Plus CE in testing.   The values take a range from x = 0.5 to x = 11.  


Approximating e^x


Approximation used:


e^x ≈ 1 + x * (1 + x/2 * (1 + x/3 * (1 + x/4 * (1 + x/5 * (1 + x/6)))))

(fractions are simplified, see source)


TI-84 Plus CE Program:  EXPTEST


"EWS 2021-01-19"

Disp "e^(X) TEST","JON M. SMITH"

Disp "RANGE, MIN. 0.5"

Input "START? ",A

Input "INCREMENT? ",I

Input "NO STEPS? ",N

seq(X,X,A,A+I*N,I)→L₁

e^(L₁)→L₂

1+L₁*(1+L₁/2*(1+L₁/3*(1+L₁/4*(1+L₁/5*(1+L₁/6)))))→L₃

abs(L₂-L₃)→L₄

iPart(log(L₄))→L₅

Disp "L₁:X, L₂:EXP, L₃:APPROX","L₄:ABS ERROR","L₅:PLACES"

SetUpEditor L₁,L₂,L₃,L₄,L₅

Disp "PRESS STAT, 1. EDIT"


Test: x range:  0.5 to 11, increments of 0.5




Approximating ln x


Approximation used:


ln x ≈ y * (1 + y/2 * (1 + 2y/3 * (1 + 3y/4 * (1 + 4y/5))))

where x ≥ 0.5

and y = (x - 1)/x

(see source)



TI-84 Plus CE Program:  LNTEST


"EWS 2021-01-19"

Disp "ln(X) TEST","JON M. SMITH"

Disp "RANGE, MIN. 0.5"

Input "START? ",A

Input "INCREMENT? ",I

Input "NO STEPS? ",N

seq(X,X,A,A+I*N,I)→L₁

ln(L₁)→L₂

(L₁-1)/L₁→L₆

L₆*(1+L₆/2*(1+2*L₆/3*(1+3*L₆/4*(1+4*L₆/5))))→L₃

abs(L₂-L₃)→L₄

Disp "L₁:X, L₂:LN, L₃:APPROX","L₄:ABS ERROR"

SetUpEditor L₁,L₂,L₃,L₄

Disp "PRESS STAT, 1. EDIT"


Test: x range:  0.5 to 11, increments of 0.5



Final Thoughts


The approximation for ln x hold much better than e^x as x increases.   I would not recommend the following approximations for values above 5.  


Source:


Smith, Jon M.  Scientific Analysis on the Pocket Calculator John Wiley & Sons: New York. 1975


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. 


Saturday, August 1, 2020

Casio fx-9750GIII and fx-CG50: System of Two Differential Equations, Runge Kutta 4th Order

Casio fx-9750GIII and fx-CG50: System of Two Differential Equations, Runge Kutta 4th Order

Introduction




The program TWORK4 uses the Runge Kutta 4th Order method to solve the following system of differential equations:

dx/dt = f(t, x, y)
dy/dt = g(t, x, y)

with initial conditions x0 = x(t0) and y0 = y(t0)

The next step is calculated with step h from:

x1 ≈ x0 + (k1 + 2 * k2 + 2 * k3 + k4) / 6
y1 ≈ y0 + (l1 + 2 * l2 + 2 * l3 + l4) / 6

k1 = h * f(t0, x0, y0)
l1 = h * g(t0, x0, y0)

k2 = h * f(t0 + h / 2, x0 + k1 / 2, y0 + l1 / 2)
l2 = h * g(t0 + h / 2, x0 + k1 / 2, y0 + l1 / 2)

k3 = h * f(t0 + h / 2, x0 + k2 / 2, y0 + l2 / 2)
l3 = h * g(t0 + h / 2, x0 + k2 / 2, y0 + l2 / 2)

k4 = h * f(t0 + h, x0 + k3, y0 + l3)
l4 = h * g(t0 + h, x0 + k3, y0 + l3)

For the next step set t0 = t0 + h, x0 = x1, and y0 = y1. 

Inputs:

DX/DT:  Enter dx/dt as a function of T, X, and Y.   T is the independent variable.

DY/DT:  Enter dy/dt as a function of T, X, and Y.   T is the independent variable.

T0, X0, Y0:  Enter the initial conditions

STEP:  Enter the step size

ITERATIONS: Enter the number of iterations desired.  This allows you to calculate a far point in one leap.  Example, if your initial condition is to = 0 and you want to find the point when t = 1 using the step size of 0.1, enter 0.1 for STEP and 10 for ITERATIONS.

Casio fx-9750GIII and fx-CG 50 Program: TWORK4

Notes: 

*  Although the code for the two calculators are the same, the programs will need to be programmed on each calculator separately.

*  The slash character (/) is accessed from the CHAR submenu.  The submenu shows up at the top-level menu which would read:
TOP/BOTTOM/SEARCH/MENU/A ←→ a/CHAR

* fn1 and fn2 are stored as function memories. 

"2020-06-18 EWS"
Rad
"DX/DT="? → fn1
"DY/DT="? → fn2
"T0"? → U
"X0"? → A
"Y0"? → B
"STEP?" → H
4 → Dim List 25
4 → Dim List 26
Lbl 0
"ITERATIONS"? → N
For 1 → I To N
A → X: B → Y: U → T
H * fn1 → List 25[1]
H * fn2 → List 26[1]
A + List 25[1] ÷ 2 → X
B + List 26[1] ÷ 2 → Y
U + H ÷ 2 → T
H * fn1 → List 25[2]
H * fn2 → List 26[2]
A + List 25[2] ÷ 2 → X
B + List 26[2] ÷ 2 → Y
H * fn1 → List 25[3]
H * fn2 → List 26[3]
A + List 25[3] → X
B + List 26[3] → Y
U + H → T
H * fn1 → List 25[4]
H * fn2 → List 26[4]
A + (List 25[2] + List 25[3] + Sum List 25) ÷ 6 → A
B + (List 26[2] + List 26[3] + Sum List 26) ÷ 6 → B
U + H → U
Next
ClrText
"(T, X, Y)"
{U, A, B} ◢
Menu "NEXT?", "YES", 0, "NO", 1
Lbl 1
"DONE"

Example

dx/dt = x sin y

dy/dt = y^2/500 + y/3 - y

Initial conditions: x(0) = 0.1, y(0) = 0.1, h = 0.1

T0 = 0
STEP = 0.1

ITERATIONS: 10
Results:  (T, X, Y): (1, 0.1075645239, 0.05134921355)

ITERATIONS: 10
Results:  (T, X, Y): (2, 0.1116714419, 0.02636554462)

Source:

John W. Harris and Horst Stocker.  Handbook of Mathematics and Computational Science.  Springer: New York.  2006.  ISBN 978-0-387-94746-4

Stack Exchange.  "Help with using the Runge-Kutta 4th order method on a system of 2 first order ODE'S"  Asked March 2014.   Last updated February 2019.  https://math.stackexchange.com/questions/721076/help-with-using-the-runge-kutta-4th-order-method-on-a-system-of-2-first-order-od  Retrieved June 17, 2020

Eddie

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

Sunday, April 26, 2020

Casio fx-CG 50: Shortcuts Study

Casio fx-CG 50: Shortcuts Study

Introduction

When programming in calculators, sometimes it is useful to use alternate ways of accomplishing the task.  The alternate way could save keystrokes and memory, which can become important with older programming calculators and calculators where the number of steps available is about 150 or lower. 

Complex Number Functions

Some of the shortcut methods involves complex numbers and complex number operations, particular involving polar-rectangular conversions.

Below are the four common conversion calculations needed and alternate ways to accomplish them: 

√(x^2 + y^2) = abs(x + y ⅈ) = R>Pr(x,y) 

atan( y / x ) = arg(x + y ⅈ) = R>Pθ(x,y)**

r cos θ = real( r ∠ θ) = P>Rx(r,θ)

r sin θ = imag(r ∠ θ) = P>Ry(r,θ)

** The domain in the atan function is (-90°, 90°) while the arg (sometimes named atan2 and angle) and R>Pθ functions takes the (x,y) coordinates to account and the domain is (-180°, 180°).

Casio fx-CG50 Program: SHORTCUT

The program SHORTCUT illustrates six shortcut techniques regarding:

1.  Law of Cosines - Calculating the Third Side of a triangle

c = √(a^2 + b^2 - 2ab cos θ)
Complex Number Alternate: c = abs( real(a∠θ) - b + imag(a∠θ)*ⅈ )

2.  Rounding to the Nearest Integer

Alternate to the round function:  int( frac x + x 0

3.  √(1 - x^2),  |x| < 1

Trigonometric Alternate:  sin(acos x )

4.  x / √(1 + x^2),  any x

Trigonometric Alternate:  sin(atan x)

5.  √(a^2 + b^2 + c^2)

Complex Number Alternate:  abs(c + abs(a + b*ⅈ) * ⅈ)

6.  √(a^2 + 2*b^2)

Two Step Alternate (this is just one of many ways):
abs(a + b*ⅈ)
abs(b + ans*ⅈ)

Program:

Anything that follows // is a comment.  Don't type the comment in. 

a+bⅈ       // turn complex mode on
"BETTER PROG HP67/97"    // credit to source, slash character from CHAR menu
"EWS 2020-03-09"
Menu "SHORTCUTS","LAW OF COSINES",1,"ROUND TO INTEGER",2,
"√(1-X^2)",3," X÷√(1+X^2)",4,"√(A^2+B^2+C^2)",5,"√(A^2+2*B^2)",6

Lbl 1
"θ"?→θ
"A"?→A
"B"?→B
"√(A^2+B^2-2AB cos θ)"→Str 1
Exp(Str 1)→R            
"Abs(Rep(A∠θ)-B+Imp(A∠θ)ⅈ"→Str 2
Exp(Str 2)→S
Goto R

// Exp numerically evaluates a string 

Lbl 2
"NUMBER"?→X
"RndFix(X,0)"→Str 1
RndFix(X,0)→R      
// Exp(RndFix(a,b)) leads to an error message
"Int (Frac X+X)"→Str 2
Exp(Str 2)→S
Goto R

Lbl 3
"-1
"√(1-X^2) "→Str 1
Exp(Str 1)→R
"sin cos^-1 X"→Str 2
Exp(Str 2)→S
Goto R

Lbl 4
"X"?→X
"X÷√(1+X^2)"→Str 1
Exp(Str 1)→R
"sin tan^-1 X"→Str 2
Exp(Str 2)→S
Goto R

Lbl 5
"A"?→A
"B"?→B
"C"?→C
"√(A^2+B^2+C^2)"→Str 1
Exp(Str 1)→R
"Abs (C+Abs (B+A×ⅈ)×ⅈ)"→Str 2
Exp(Str 2)→S
Goto R

Lbl 6
"A"?→A
"B"?→B
"√(A^2+2B^2)"→Str 1
Exp(Str 1)→R
"Abs (A+Bⅈ):Abs (Ans+Bⅈ)"→Str 2
Exp(Str 2)→S
Goto R

Lbl R
ClrText
Black Locate(1,1,Str 1)
Black Locate(1,2,R)
Blue Locate(1,4,Str 2)
Blue Locate(1,5,S)

//  If you are using a monochrome screen such as the Casio fx-9750gII or fx-9860gII, leave out the Black and Blue commands.


You can download the program file here (fx-CG 50, 696 bytes):
https://drive.google.com/open?id=1b4PzPWEdQ0bV_l3l7vIcThVGxjOR94pb 

Source:
William Kob, John Kennedy, Richard Nelson.  Better Programming On The HP-67/97 PPC 1978

Eddie

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

Saturday, April 18, 2020

HP 12C: Sums of x

HP 12C:  Sums of x

Introduction

The following are four programs to calculate:

*  ∑ x
*  ∑ x^2
*  ∑ x^3
*  ∑ ax + b

with limits x = 0 to n.

Each program uses a closed sum formula.  The second and fourth program uses Horner's Method. 

Note:  You can use the first three if your limits are x = 1 to n (because at x = 0, 0 is added to the sum).  However if you use the fourth program, to get the sum from 1 to n, subtract b. 

HP 12C Program:  ∑x (x=0 to n)

n
∑ x =  n * (n + 1) / 2
x=0

Enter n, execute program

STEP:  KEY CODE  KEY
01:  36  ENTER
02:  36  ENTER
03:  1  1
04:  40  +
05:  20  *
06:  2   2
07  10  ÷
08:  43,33,00  GTO 00

Keys Only:
ENTER
ENTER
1
+
2
*
÷
GTO 00

Example:  (n = 48)

48
∑ x  = 1176
x=0

HP 12C Program:  ∑x^2 (x=0 to n)

n
∑ x^2 =  n * ( ( n / 3 + 1 / 2 ) * n + 1 / 6 )
x=0

Enter n, execute program

STEP:  KEY CODE KEY
01:  36  ENTER
02:  36  ENTER
03:  36  ENTER
04:  3  3
05:  10  ÷
06:  2  2
07:  22  1/x
08:  40  +
09:  20  *
10:  6  6
11:  22  1/x
12:  40  +
13:  20  *
14:  43,33,00  GTO 00

Keys Only:
ENTER
ENTER
ENTER
3
÷
2
1/x
+
*
6
1/x
+
*
GTO 00

Example:  (n = 48)

48
∑ x^2  = 38,024
x=0

HP 12C Program:  ∑x^3 (x=0 to n)

n
∑ x^3 =  1 / 4 * (n^2 + n)^2
x=0

Enter n, execute the program

STEP:  KEY CODE  KEY
01:  36  ENTER
02:  36  ENTER
03:  2  2
04:  21  y^x
05:  40  +
06:  2:  2
07:  21  y^x
08:  4  4
09:  10  ÷
10:  43,33,00  GTO 00

Keys Only:
ENTER
ENTER
2
y^x
+
2
y^x
4
÷
GTO 00

Example:  (n = 32)

32
∑ x^3  = 278,784
x=0

HP 12C Program:  ∑(a*x + b)  (x=0 to n)

n
∑ (a*x + b) =  n * (a * n / 2 + (a / 2 + b) ) + b
x=0

Store a in R1, store b in R2, enter n on the x-stack, execute the program

STEP:  KEY CODE   KEY
01:  36   ENTER
02:  36   ENTER
03:  36   ENTER
04:  45, 1  RCL 1
05:  20   *
06:  2    2
07:  10   ÷
08:  45, 1  RCL 1
09:  2   2
10:  10   ÷
11:  45, 2   RCL 2
12:  40   +
13:  40   +
14:  20   *
15:  45, 2  RCL 2
16:  40  ÷
17:  43, 33, 00   GTO 00

Keys Only:
ENTER
ENTER
ENTER
RCL 1
*
2 
÷
RCL 1
2
÷
RCL 2
+
+
*
RCL 2
÷
GTO 00

Example:  (a = R1 = 3,  b = R2 = 4, n = 32)

3 STO 1,  4 STO 2,  32, R/S

32
∑ (3x + 4) = 1,716
x=0


I tried something new with my RPN keystroke programs, the second versions of each I just listed what keys to press without the step number or code.  I think this would be easier to read, but does leave out the key and key code.  Any comments on which style is preferred is appreciated. 


Eddie

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

HP 67 Collection: October 2026

HP 67 Collection: Oct ober 2026 All examples are done in FIX 4. (DSP 4) Earth's Gravity at a Specific Latitude The true ea...