Wednesday, December 13, 2017

HP Prime: Area by Quadratic Splines


HP Prime:  Area by Quadratic Splines

Introduction

The program QUADSUM calculates the area under the curve described by the set of points (x_n, y_n).  The points are connected, in groups of three, by quadratic splines.  Thus, points (x1, y1), (x2, y2), and (x3, y3) are connected by a quadratic spline, (x3, y3), (x4, y4), (x5, y5) are connected by another quadratic spline, and so on.

Screen shot by HP Prime, labels I added using MS Paint (the old one)

  
The number of points for QUADSUM must be odd. 

HP Prime Program QUADSUM

EXPORT QUADSUM(LX,LY)
BEGIN
// EWS 2017-12-10
// Area by connecting
// points using quadratic
// curves
// number of points must be odd
LOCAL A,S,T; // A=0
S:=SIZE(LX);
IF FP(S/2)==0 THEN
RETURN "Invalid: Number of
points must be odd";
KILL;
END;
LOCAL T,M,MA,MB,MC;
FOR T FROM 1 TO S-2 STEP 2 DO
M:=CAS.LSQ([[1,LX(T),LX(T)^2],
[1,LX(T+1),LX(T+1)^2],
[1,LX(T+2),LX(T+2)^2]],
[[LY(T)],[LY(T+1)],[LY(T+2)]]);
MA:=M(3,1);
MB:=M(2,1);
MC:=M(1,1);
A:=A+
(MA*LX(T+2)^3/3+MB*LX(T+2)^2/2+
MC*LX(T+2))-
(MA*LX(T)^3/3+MB*LX(T)^2/2+
MC*LX(T));
END;
RETURN A;
END;

Example

Find the area under the curve with these points connected by quadratic splines:
(0,2), (1,1), (2,2), (3,6), (4,4)



Note that the point (2,2) ends the first spline and starts the second.

QUADSUM({0,1,2,3,4}, {2,1,2,6,4}) returns 12.6666666667

FYI:  The polynomial described would be the piecewise equation:
y = { x^2 -2x + 2 for 0 < x ≤ 2,  -3x^2 + 19x – 24 for 2 < x ≤ 4

Eddie


This blog is property of Edward Shore, 2017

Monday, December 11, 2017

HP Prime: Perigee and Apogee of a Conic Section

HP Prime:  Perigee and Apogee of a Conic Section

Introduction

The program CONICAP determines three characteristics of a conic section:

Eccentricity:
E = 0, circle
0 < E < 1, ellipse
E = 1, parabola (this case is not covered)
E > 1, hyperbola

Periapsis (Perigee):
The point on the conic section where it is closest to a primary focus (which is designated at one of the two foci F or F’).

Apoapsis (Apogee):
The point on the conic section where it is furthest away from a primary focus.  Note for a hyperbola and a parabola, the apogee is ∞. 

 The inputs are the lengths of the semi-major axis (A) and the semi-minor axis (P).  For a hyperbola, input A as negative. 



HP Prime Program CONICAP

EXPORT CONICAP(A,P)
BEGIN
// EWS 2017-12-10
// Fundamentals Of Astrodynamics
// ABS(A)≥P
LOCAL E;
E:=√(1-P/A);
PRINT();
PRINT("Perigee: "+STRING(A*(1-E)));
IF A≥0 THEN
PRINT("Apogee: "+STRING(A*(1+E)));
END;
PRINT("Eccentricity: "+E);
IF E==0 THEN
PRINT("Circle");
END;
IF E>0 AND E<1 THEN
PRINT("Ellipse");
END;
IF E>1 THEN
PRINT("Hyperbola");
END;
END;

Examples


A = 8, P = 3
A = 5, P = 5
A = -8, P = 3
Perigee
1.67544467966
5
1.38083151968
Apogee
14.3245553203
5
N/A
Eccentricity
0.790569415042
0
1.17260393996

Source:
Roger R. Bate, Donald D. Mueller, Jerry E. White.  Fundamentals of Astrodynamics Dover Publications: New York.  1971. ISBN-13: 978-0-486-60061-1

Eddie


This blog is property of Edward Shore, 2017.

Wednesday, November 29, 2017

Casio fx-5800p Special Functions

Casio fx-5800p Special Functions

Programs

An Alternate Way of Extracting the Fraction and Integer Parts of a Number

The fraction part is stored in F, and the integer part is stored in I.  This algorithm can be used when a calculator or programming language does not have a fractional part or integer part function.

This program assumes the program is in Radians mode.

Casio fx-5800P Program FPIP

Rad
0.5    → F
? → X
cos(πX) = 0 Goto 1
Abs(X) → F
tan^-1 (tan (πF)) ÷ π → F
X < 0 -F → F
Lbl 1
F /right-triangle ([Shift] [x^2])
X – F → I

Bernoulli Numbers

The program BERNOULLI approximates the Bernoulli number of nth order.

Casio fx-5800P Program BERNOULLI

? → N
If N = 0
Then
1 → B
Goto 1
IfEnd
If Frac(N ÷ 2) ≠ 0
Then
Int( Abs(N – 2) ÷ (N – 2) – 1) ÷ 4 → B
Goto 1
IfEnd
Σ ( (2*J*π)^(-N), J, 1, 250) * (-1)^(N ÷ 2 + 1) * 2 * N! → B
Lbl 1
B

Euler Numbers

The program EULERNUM calculates the Euler number of order n.

Casio fx-5800P Program EULERNUM

? → N
0 → E
Frac(N ÷ 2) ≠ 0 Goto 1
(2 ÷ π)^(N + 1) * N! ÷ 5 → E
-1 – 10 * Int(E) → E
Frac(N ÷ 4) ≠ 0 Goto 1
4 – E → E
N ≠ 0 Goto 1
1   → E
Lbl 1
E

Custom Formulas

How to create custom formulas:  [MODE], 5.  PROG, 1.  NEW, give the name, 3. Formula

To calculate the custom formula, press [CALC], enter the value for T (ignore X because X is a dummy variable).

Sine Integral:   SI:  ∫( sin(X)/X dX,0,T)

Dawson Integral:  DAWSON:  ∫(e^(T^2-X^2) dX,0,T)

Bessel Function, with order N:  BESSEL:  1/π * ∫(cos(T * sin(X)-N*X) dX,0,T)

Error Function:  ERF:  2/√π * ∫(e^(-X^2) dX,0,T)

Fresnel Sine:  FRESSIN:  ∫( sin(π*X^2/2) dX,0,T)

Fresnel Cosine: FRESCOS: ∫( cos(π*X^2/2) dX,0,T)

Source:

Jerome Spainer and Keith B. Oldham  An Atlas of Functions Hemisphere Publication Corporation: Washington  1987  ISBN 0-89116-5738-8

Eddie

This blog is property of Edward Shore, 2017

Sunday, November 26, 2017

Rounding to the Nearest Reciprocal (HP Prime, TI-84 Plus CE, Casio fx-CG 50)

Rounding to the Nearest Reciprocal   (HP Prime, TI-84 Plus CE, Casio fx-CG 50)

Introduction

The program ROUNDRCP rounds a number to the nearest 1/n. This function can come in handy in several applications, for example, when working with construction or measuring, when have to round results to the nearest eighth (1/8), inch (1/12) or sixteenth (1/16).

Presented here are versions for the HP Prime, TI-84 Plus CE, and Casio fx-CG 50.

HP Prime:  ROUNDRCP

EXPORT ROUNDRCP(a,n)
BEGIN
// Round a to the nearest 1/n
// 2017-11-21 EWS
LOCAL w;
w:=FP(ABS(a))*n;
w:=ROUND(w,0);
RETURN IP(a)+SIGN(a)*(w/n);
END;


The TI-84 Plus CE and Casio fx-CG 50 versions store the answer in X.

TI-84 Plus CE ROUNDRCP

"EWS 2017-11-21"
Input "NUMBER:",A
Input "TO 1/NTH:",N
fPart(abs(A))*N→W
round(W,0)→W
If A<0
Then
iPart(A)-(W/N)→X
Else
iPart(A)+(W/N)→X
End
Disp "X:",X


Casio fx-CG 50 ROUNDRCP

“NUMBER”?→A
“TO 1÷NTH”?→N
Frac ((Abs A))*N→N
RndFix(W,0)→W
If A<0
Then
Int (A)-(W÷N)→X
Else
Int(A)+(W÷N)→X
IfEnd
“X:”
X

Examples

Round π to the nearest 1/4:
ROUNDRCP(π, 4):  3.25 = 13/4

Round e^2 to the nearest 1/100:
ROUNDRCP(e^2, 100): 7.39 = 739/100

Round 1/4 + 2/7 + 3 1/3 to the nearest 1/16:
ROUNDRCP(1/4 + 2/7 + 3 + 1/3, 16):  3.875 = 31/8
(thank you to Joe Horn for pointing out my error, it's correct now.)

Tips 

If you do not have the sign (signum) function, you can compensate by the following code:

If X<0
Then
Return -1  (subtract operation)
Else
Return 1 (addition operation)
End

If your calculator does not have the Round to any number of decimal points function, such as the Casio fx-5800p or fx-3650p, you can manipulate the modes and use the Rnd function and a switch of modes, like this code:

Fix 0
X  (put number to round in display)
Rnd
Float/Norm (1/2)

Eddie


This blog is property of Edward Shore, 2017

Wednesday, November 15, 2017

How to Rotate Graphs

How to Rotate Graphs

Introduction

The key is to use parametric equations in our rotation.  Using the rotation angle θ, the rotation matrix is:

R = [ [ cos θ, -sin θ ] [ sin θ, cos θ ] ]

With the equations x(t), y(t) set as the matrix:

M = [ [ x(t) ] [ y(t) ] ]

The rotated graph is:

[ [ x’(t) ] [ y’(t) ] ] = R * M

Where:

x’(t) = x(t) * cos θ – y(t) * sin θ
y’(t) = x(t) * sin θ + y(t) * cos θ

Rotation the Function y = f(x)

Let x = t and set the parametric functions:

x(t) = t
y(t) = f(t)

Rotating the Polar Equation r = f(t)  (where t = θ)

1.  Solve for t.
2.  Substitute r and t in the following equations:
  x(t) = r * cos t
  y(t) = r * sin t
3.  Simplify as needed.

Some trigonometric properties:
sin^2 ϕ + cos^2 ϕ = 1
sin(2*ϕ) = 2 * cos ϕ * sin ϕ
cos(2*ϕ) = 2 * cos^2 ϕ – 1
sin(acos ϕ) = cos(asin ϕ) = √(1 – ϕ^2)

Please refer to this link for additional details:  http://edspi31415.blogspot.com/2013/01/converting-polar-equations-to.html
   
Rotation Matrices for Certain Angles

Angle 30°, π/6:  R = [ [ √3/2, -1/2 ] [ 1/2, √3/2 ] ]

Angle 45°, π/4:  R = [ [ √2/2, -√2/2 ] [ √2/2, √2/2 ] ]

Angle 60°, π/3:  R = [ [ 1/2, -√3/2 ] [ √3/2, 1/2 ] ]

Angle 90°, π/2:  R = [ [ 0, -1 ] [ 1, 0 ] ]

Angle 120°, 2π/3:  R = [ [ -1/2, -√3/2 ] [ √3/2, -1/2 ] ]

Angle 135°, 3π/4:  R = [ [ -√2/2, -√2/2 ] [ √2/2, -√2/2 ] ]

Angle 150°, 5π/6:  R = [ [ -√3/2, -1/2 ] [ 1/2, -√3/2 ] ]

Angle 180°, π:  R = [ [ -1, 0 ] [ 0, -1 ] ]

Angle 210°, 7π/6:  R = [ [ -√3/2, 1/2 ] [ -1/2, -√3/2 ] ]

Angle 225°, 5π/4:  R = [ [ -√2/2, √2/2 ] [ -√2/2, -√2/2 ] ]

Angle 240°, 4π/3:  R = [ [ -1/2, √3/2 ] [ -√3/2, -1/2 ] ]

Angle 270°, 3π/2:  R = [  [ 0, 1 ] [ -1, 0 ] ]

Angle 300°, 5π/3:  R = [ [ 1/2, √3/2 ] [ -√3/2, 1/2 ] ]

Angle 315°, 7π/4:  R = [ [ √2/2, √2/2 ] [ -√2/2, √2/2  ] ]

Angle 330°, 11π/6:  R = [ [ √3/2, 1/2 ] [ -1/2, √3/2  ] ]

Examples

Each example is followed by a graph of the original equation (blue) and the rotated equations (red).  I used a Casio fx-CG 50 for the screen shots.

Example 1:  y = 3*x^2, rotate 90°

We have a function in the form of y = f(x).  Let’s transfer the function to parametric form, first by assigning x = t and y = 3*t^2.  Angle mode is in radians.

With 90°, the rotation matrix is:  R = [ [ 0, -1 ] [ 1, 0 ] ]

The transformed equations are:

[ [ 0, -1 ] [ 1, 0 ] ] * [ [ t ] [ 3*t^2 ] ] = [ [ -3*t^2 ] [ t ] ]

Rotated Equations:  x’(t) = -3*t^2, y’(t) = t



Example 2:  x = t^3, y = 2*t – 1, rotate 270°

We have the equations in parametric form.  We’ll need the rotation matrix, where:

R = [  [ 0, 1 ] [ -1, 0 ] ]

[  [ 0, 1 ] [ -1, 0 ] ] * [ [ t^3 ] [ 2*t – 1 ] ] = [ [ 2*t – 1 ] [ -t^3 ] ]

Rotated Equations:  x’(t) = 2*t – 1, y’(t) = -t^3



Example 3:  x = sin t, y = e^t, rotate 135°

The rotation matrix is R = [ [ -√2/2, -√2/2 ] [ √2/2, -√2/2 ] ]

Rotated Equations:  x’(t) = -√2/2 * (sin t + e^t), y’(t) = √2/2 * (sin t – e^t)



Example 4:  r = 2 θ, rotate 60°

The parametric form is x(t) = 2 * t * cos t, y(t) = 2 * t * sin t

The rotation matrix is R = [ [ 1/2, -√3/2 ] [ √3/2, 1/2 ] ]

Rotated Equations: x’(t) = t * cos t - √3 * t * sin t, y’(t) = t * sin t + √3 * t * cos t



Eddie


This blog is property of Edward Shore, 2017

Saturday, November 11, 2017

Casio fx-CG 10, fx-CG 20, fx-CG 50 Update to Software Version 3.1

Casio fx-CG 10, fx-CG 20, fx-CG 50 Update to Software Version 3.1

If you want to see my original review of the fx-CG 50, please click here: 

What’s New with Software Version 3.1
  
Major Graph3D App Update!

Wow!  Casio hit it out of park with their updated 3D Graph mode.

When I first reviewed the Casio fx-CG 50 last June, one of the new features highlighted was the 3D Graph mode.  At the time, the mode was limited to lines, planes, spheres, and cylinders.  A good start, but limited mode. 

Not anymore.  First, the update added cones to the template.


The 3D Graph mode has become an official graphing mode because the mode now has functional graphing in the form of Z(X,Y).


It doesn’t stop there.  The mode also offers parametric graphing in the form of (X(S,T), Y(S,T), Z(S,T)).  This might be my favorite part of the Graph 3D app.


Finally, you can rotate Y(X) functions either by X or Y axis, to give a really neat visualization of functions.


The update adds analysis for planes and lines.  Analysis includes intersection points and relational type analysis (intersection vs. orthogonal vs. rotational vs. parallel, etc.)


QR Codes Added to the Catalog

QR (Quick Response) codes, those small square bar codes that people scan with their smartphones to connect to certain webpages, have been added to most of the commands in the Catalog.  Any QR reader should do.  A successful reading of the bar code leads to Casio’s online manual. 





Count on Casio continuing the use of QR codes, in both graphing and non-graphing models.  Recall that the fx-991 EX Classwiz has QR codes to display stat plots and screen shots through Casio’s Casio EDU+ software and app. 

Yes, QR codes generated by the catalog can be read by the Casio EDU+ app. 

For more details, click here:

Wish List

I wish in the next update, Casio increases the number of colors to display text and graphs, currently there are still seven (black, blue, red, magenta, green, cyan, and yellow).  At least put an RGB function. 

I think a differential equation graph mode or type would fit well with this series, even if it is just in the form of y’ = f(x,y,constants) and the Runge Kutta 4th order method is used. 

I suspect the next hardware of this series will have memory increased to at least 256MB or more.   This series of calculators deserves to have such increase because of all the great things this series offers!

Download Links


Please keep in mind you will need to install the Graph3D for the fx-CG 10 and fx-CG 20 Add-In separately.  The Graph3D already comes with the fx-CG 50.


The era of third-dimensional graphing is here to stay!

Eddie

This blog is property of Edward Shore, 2017.

HP Prime: Area by Quadratic Splines

HP Prime:  Area by Quadratic Splines Introduction The program QUADSUM calculates the area under the curve described by the set o...