Showing posts with label custom app. Show all posts
Showing posts with label custom app. Show all posts

Saturday, February 15, 2020

HP Prime and TI 84 Plus CE: Jacobi Elliptic Functions

HP Prime and TI 84 Plus CE:  Jacobi Elliptic Functions

Introduction

Jacobian Elliptic Functions are a set of twelve functions denoted by XY(U, K) where X and Y stands of letters c, s, n, and d.  Today's blog post will focus on three of the common Jacobi Elliptic Functions:

Sine Amplitude:  sn(u,k)
Cosine Amplitude:  cn(u,k)
Delta Amplitude:  dn(u,k)

Where u is a real number and k is a parameter between -1 and 1 inclusive

To determine any of the Jacobian Elliptic Functions, the integral has to be solved for X:

U = ∫( 1/√(1 - K^2 * sin^2(T)) dT from T = 0 to T = X)

Solving for X will represent the function am(U,K).

Then:
sn(U,K) = sin(X)
cn(U,K) = cos(X)
dn(U,K) = √(1 - K^2 * sin^2(X))

Radian angles are used. 

HP Prime App:  Jacobi Elliptic Functions

Download here:  https://drive.google.com/open?id=1qQ253ri88IyZIwYvKd5kEAIe2Bkgfyl_



In a different approach, I have created a custom app, which is based on the Solver App named Jacobi Elliptic Functions, which you can download on the link above.

Symb View:  The four equations that are used for this app.  Leave all four checked.

Num View:  This is where you enter U and K.  Leave these boxes unchecked.  Press or touch (Solve) to get the other values am (X), sn (S), cn (C), and dn (D). 

If you want to program ths app yourself, please see the screen shots above. 

TI-84 Plus CE Program:  ELLIPFX

Download here:  https://drive.google.com/open?id=16DTb2m2o2kwo1sJ6s_NGGJ_M9bgxsOvZ

"EWS 2020-01-22"
Radian
.5→X:1→F:1→N
ClrHome
Disp "JACOBIAN ELLIPTIC","­1≤K and K≤1"
Prompt U,K
Repeat abs(N/F)≤1E­10
fnInt((1-K^2*sin(T)^2)^(­-1/2),T,0,X)-U→N
(1-K^2*sin(X)^2)^(­-1/2)→F
X-N/F→X
End
sin(X)→S
cos(X)→C
√(1-K^2*sin(X)^2)→D
ClrHome
Disp "U="+toString(U)
Disp "K="+toString(K)
Disp "AM="+toString(X)
Disp "SN="+toString(S)
Disp "CN="+toString(C)
Disp "DN="+toString(D)

Examples

Example 1:
U = 3
K = 0.5

Results:
AM(U,K) = 2.772166899
SN(U,K) = 0.3610799872
CN(U,K) = -0.932534848
DN(U,K) = 0.9835676442

Example 2:
U = 1.5
K = 0

Results:
AM(U,K) = 1.5
SN(U,K) = 0.9974949866
CN(U,K) = 0.0707372017
DN(U,K) = 1

Sources

"Jacobi elliptic functions"  Wikipeida.  https://en.wikipedia.org/wiki/Jacobi_elliptic_functions  Retrieved December 23, 2019

"Jacobi elliptic function sn,cn,dn (chart) Calculator"  Ke!san Online Calculator https://keisan.casio.com/exec/system/1180573437  Retrieved January 22, 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.

Tuesday, February 13, 2018

HP Prime: TrigPlot App (HP Prime Custom app Tutorial)

HP Prime: TrigPlot App  (HP Prime Custom app Tutorial)

Introduction

Here is another example custom app, the TrigPlot, which plots the following equation:

y = A * sin(Bx + C) + D * cos(Ex + F) + G * sin(Hx + I)^2 + J * cos(Kx + L)^2

where all angles are in radians.  The app uses the global variables A through L. 

Keys

[ Num ]:  The user enters values for A – L.  They must be real (not complex or have a (-1) component)

[ Plot ]:  Enter plot parameters and choose the color of the plot (purple, blue, green, gold, red).  The plot is against a black background.

[ View ], Erase A-L:  Sets the variables A through L to 0 (zero).

[ Info ]:  Displays information about the app

Notes



The Info section introduces the user to the app’s concept:

Info()
BEGIN
// This is when the user presses
// Shift+Apps (Info), use Print
// commands

PRINT();

PRINT("TrigPlot App");
PRINT("------------");
PRINT("By Edward Shore");
PRINT("------------");
PRINT("This app plots the equation");
PRINT("Y = A*SIN(B*X+C) + D*COS(E*X+F) +");
PRINT("G*SIN(H*X+I)^2 + J*COS(K*X+L)^2");
PRINT("------------");
PRINT("February 2018");

END;


To ensure the app always runs in Radians mode, I store the value 1 to AAngle during startup (START).  In addition, I added the Info(); to show the Info screen.

START()
BEGIN
// This happens when the app is started.

// Set the app to radians angle mode.
AAngle:=1;
// This is a specific app mode setting
// unlike HAngle

// Also run the Info screen
Info();

END;

The Plot portion of app is based on the Pixel Plot program (see http://edspi31415.blogspot.com/2018/02/hp-prime-pixel-plot-how-to-change.html ) where pixels are plotted.

HP Prime Program:  TrigPlot (in app TrigPlot)

#pragma mode( separator(.,;) integer(h32) )

//Symb()
//BEGIN
// MSGBOX("Symb");
//END;

Plot()
BEGIN
// runs the Plot routine
// set color scheme
LOCAL col1;
col1:={#BF00FFh,#7DF9FFh,
#00FF00h,#D4AF37h,#FF0000h};

// Radians
HAngle:=0;

// localize variables
LOCAL xm,xn,ym,yn;
LOCAL xs,ys,xp,yp;
LOCAL x,y,ch;

// input screen
INPUT({
xm,xn,ym,yn,
{ch,
{"Purple","Blue","Green",
"Gold","Red"}}},
"TrigPlot Setup: Plot",
{"x-min: ","x-max: ",
"y-min: ","y-max: ",
"Color: "});

// set black background
RECT_P(0);

// calulate the scale
xs:=(xn-xm)/320;
ys:=(yn-ym)/−220;

// drawing

// color choice
LOCAL c1:=col1[ch];

// axis information
LOCAL st1,st2;
st1:="x:["+xm+","+xn+"]";
st2:="y:["+ym+","+yn+"]";
TEXTOUT_P(st1,0,0,2,#C0C0C0h);
TEXTOUT_P(st2,0,20,2,#C0C0C0h);

// function
FOR x FROM xm TO xn STEP xs DO

// function
y:=A*SIN(B*x+C)+D*COS(E*x+F)+
G*SIN(H*x+I)^2+J*COS(K*x+L)^2;

// point→pixel, plot
xp:=(x-xm)/xs;
yp:=(y-yn)/ys;
PIXON_P(xp,yp,c1);

END;
// freeze screen
FREEZE;

END;

Num()
BEGIN
// This is where all the variables are
// entered, in one easy spot. A-L are
// global in this application.
INPUT({A,B,C,D,E,F,G,H,I,J,K,L},
"TrigPlot Variables");
END;

//SymbSetup()
//BEGIN
// MSGBOX("SymbSetup");
//END;

//PlotSetup()
//BEGIN
// MSGBOX("PlotSetup");
//END;

//NumSetup()
//BEGIN
// MSGBOX("NumSetup");
//END;

Info()
BEGIN
// This is when the user presses
// Shift+Apps (Info), use Print
// commands

PRINT();

PRINT("TrigPlot App");
PRINT("------------");
PRINT("By Edward Shore");
PRINT("------------");
PRINT("This app plots the equation");
PRINT("Y = A*SIN(B*X+C) + D*COS(E*X+F) +");
PRINT("G*SIN(H*X+I)^2 + J*COS(K*X+L)^2");
PRINT("------------");
PRINT("February 2018");

END;

START()
BEGIN
// This happens when the app is started.

// Set the app to radians angle mode.
AAngle:=1;
// This is a specific app mode setting
// unlike HAngle

// Also run the Info screen
Info();

END;

//RESET()
//BEGIN
//MSGBOX("RESET");
//END;

//VIEW "Views", Views()
//BEGIN
// MSGBOX("Views");
//END;

VIEW "Erase A-L", ERASEAL()
BEGIN
A:=0; B:=0; C:=0; D:=0; E:=0; F:=0;
G:=0; H:=0; I:=0; J:=0; K:=0; L:=0;
END;

Examples

Example 1:  y = 2 sin(x + 2) – 3 cos x
A = 2, B = 1, C = 2, D = -3, E = 1 (the rest are zero)



Example 2:  y = 2 cos(2x) + 1.5 * cos^2 x
D = 2, E = 2, J = 1.5, K = 1 (the rest are zero)



Eddie


This blog is property of Edward Shore, 2018.

Saturday, February 10, 2018

HP Prime Custom App: GeomCalc

HP Prime Custom App: GeomCalc

Introduction

The app GeomCalc is an example of a custom HP App for the HP Prime.  For general information, please visit this blog entry:  http://edspi31415.blogspot.com/2018/02/hp-prime-intro-to-blank-custom-apps.html

Let’s get start with this example app.

START - The Initial Conditions

Here I set the app’s angle to degrees mode.  Note that I use the variable AAngle instead of the global variable HAngle.  The values for AAngle are slightly different than HAngle:

0:  use the angle setting from Home Settings
1:  Radians
2:  Degrees
3:  Gradians

I want the app to operate with angles in degrees, so I set AAngle to 1.

The last command is a message box containing the word Ready, to let the user know that the app is all set to go. 

START()
BEGIN
// Set app angle to degrees
AAngle:=2;
MSGBOX("Ready.");
END;

Info – Title and Introduction

I want to leave some basic information about this app.  I recommend that you use the PRINT command rather than the TEXTOUT/WAIT/FREEZE.  Alternatively, you can store a string in ANote. 

I prefer using PRINT because I can print multiple lines with appropriate line breaks.

Info()
BEGIN
PRINT();
PRINT("GeomCalc");
PRINT("---------");
PRINT("EWS 2018-02-07");
PRINT("---------");
PRINT("Geometry areas and volumes");
END;



The Symb section – selecting the calculation

In this section, I set the variable I to a choice of one of ten options.  The variable I is a global variable, so I can use determine calculations.  The INPUT command uses a dropdown box.  The general format for a single dropdown box is:

INPUT( { { var, {“choice 1”, “choice 2”, … }}}, … (other parameters)  )

The message box at the end let’s the user know that the choice has been set, and can now proceed to the calculation by pressing [Num]. 

Symb()
BEGIN
// Choose the calculation
// Global vars are used
INPUT({{I,{"Area: Circle",
"Area: Ellipse",
"Area: Trapezoid",
"Area: Circular Sector",
"Area: Regular Polygon",
"Volume: Sphere",
"Volume: Cylinder",
"Volume: Cone",
"Volume: Box",
"Volume: Ellipsoid"}}},
"Select Your Calculation");
MSGBOX("It's set!");
END;



The Num section – doing the calculation

When the [Num] is pressed, the user as asked to enter the arguments.  The final result is displayed on the terminal.  Since global variables (including A-Z) is used, values are permanently stored until changed.  In this app, I store the area in the variable E and the volume in V.

There is no default selection, so I use ten IF-THEN structures than a CASE structure.

Num()
BEGIN

IF I==1 THEN
INPUT(R,"Area: Circle","Radius: ");
E:=π*R^2;
PRINT();
PRINT("Area: "+E);
END;

IF I==2 THEN
INPUT({A,B},"Area: Ellipse",
{"A: ","B: "});
E:=π*A*B;
PRINT();
PRINT("Area: "+E);
END;

IF I==3 THEN
INPUT({A,B,H},"Area: Trapezoid",
{"A: ","B: ","H: "});
E:=0.5*H*(A+B);
PRINT();
PRINT("Area: "+E);
END;

IF I==4 THEN
INPUT({θ,R},"Area: Circular
Sector",{"Angle (°): ",
"Radius: "});
E:=θ*π*R^2/360;
PRINT();
PRINT("Area: "+E);
END;

IF I==5 THEN
INPUT({N,S},"Area: Regular
Polygon",{"# sides: ",
"Length: "});
E:=N*S^2/(4*TAN(180/N));
PRINT();
PRINT("Area: "+E);
END;

IF I==6 THEN
INPUT(R,"Volume: Sphere","Radius: ");
V:=4/3*π*R^3;
PRINT();
PRINT("Volume: "+V);
END;

IF I==7 THEN
INPUT({R,H},"Volume: Cylinder",
{"Radius: ","Height: "});
V:=π*R^2*H;
PRINT();
PRINT("Volume: "+V);
END;

IF I==8 THEN
INPUT({R,H},"Volume: Cone",
{"Radius: ","Height: "});
V:=π*R^2*H/3;
PRINT();
PRINT("Volume: "+V);
END;

IF I==9 THEN
INPUT({A,B,C},"Volume: Box",
{"A: ","B: ","C: "});
V:=A*B*C;
PRINT();
PRINT("Volume: "+V);
END;

IF I==10 THEN
INPUT({A,B,C},"Volume: Ellipsoid",
{"A: ","B: ","C: "});
V:=4/3*π*A*B*C;
PRINT();
PRINT("Volume: "+V);
END;

END;




Putting It All Together 

#pragma mode( separator(.,;) integer(h32) )

Symb()
BEGIN
// Choose the calculation
// Global vars are used
INPUT({{I,{"Area: Circle",
"Area: Ellipse",
"Area: Trapezoid",
"Area: Circular Sector",
"Area: Regular Polygon",
"Volume: Sphere",
"Volume: Cylinder",
"Volume: Cone",
"Volume: Box",
"Volume: Ellipsoid"}}},
"Select Your Calculation");
MSGBOX("It's set!");
END;

//Plot()
//BEGIN
// MSGBOX("Plot");
//END;

Num()
BEGIN

IF I==1 THEN
INPUT(R,"Area: Circle","Radius: ");
E:=π*R^2;
PRINT();
PRINT("Area: "+E);
END;

IF I==2 THEN
INPUT({A,B},"Area: Ellipse",
{"A: ","B: "});
E:=π*A*B;
PRINT();
PRINT("Area: "+E);
END;

IF I==3 THEN
INPUT({A,B,H},"Area: Trapezoid",
{"A: ","B: ","H: "});
E:=0.5*H*(A+B);
PRINT();
PRINT("Area: "+E);
END;

IF I==4 THEN
INPUT({θ,R},"Area: Circular
Sector",{"Angle (°): ",
"Radius: "});
E:=θ*π*R^2/360;
PRINT();
PRINT("Area: "+E);
END;

IF I==5 THEN
INPUT({N,S},"Area: Regular
Polygon",{"# sides: ",
"Length: "});
E:=N*S^2/(4*TAN(180/N));
PRINT();
PRINT("Area: "+E);
END;

IF I==6 THEN
INPUT(R,"Volume: Sphere","Radius: ");
V:=4/3*π*R^3;
PRINT();
PRINT("Volume: "+V);
END;

IF I==7 THEN
INPUT({R,H},"Volume: Cylinder",
{"Radius: ","Height: "});
V:=π*R^2*H;
PRINT();
PRINT("Volume: "+V);
END;

IF I==8 THEN
INPUT({R,H},"Volume: Cone",
{"Radius: ","Height: "});
V:=π*R^2*H/3;
PRINT();
PRINT("Volume: "+V);
END;

IF I==9 THEN
INPUT({A,B,C},"Volume: Box",
{"A: ","B: ","C: "});
V:=A*B*C;
PRINT();
PRINT("Volume: "+V);
END;

IF I==10 THEN
INPUT({A,B,C},"Volume: Ellipsoid",
{"A: ","B: ","C: "});
V:=4/3*π*A*B*C;
PRINT();
PRINT("Volume: "+V);
END;

END;

//SymbSetup()
//BEGIN
// MSGBOX("SymbSetup");
//END;

//PlotSetup()
//BEGIN
// MSGBOX("PlotSetup");
//END;

//NumSetup()
//BEGIN
// MSGBOX("NumSetup");
//END;

Info()
BEGIN
PRINT();
PRINT("GeomCalc");
PRINT("---------");
PRINT("EWS 2018-02-07");
PRINT("---------");
PRINT("Geometry areas and volumes");
END;

START()
BEGIN
// Set app angle to degrees
AAngle:=2;
MSGBOX("Ready.");
END;

//RESET()
//BEGIN
// MSGBOX("RESET");
//END;

//VIEW "Views", Views()
//BEGIN
// MSGBOX("Views");
//END;

Examples

Example 1:  Area of a Polygon



Example 2:  Volume of a Cone



I plan to post another example by next week, that one will involve plotting.


Eddie


This blog is property of Edward Shore, 2018

Numworks (Python): Parallelograms Described by Vectors

Numworks (Python): Parallelograms Described by Vectors Introduction The script drawpgram.py draws a parallelogram constructed by ...