Post Reply 
Jacobi elliptic function
11-02-2017, 05:26 PM (This post was last modified: 11-02-2017 06:22 PM by salvomic.)
Post: #1
Jacobi elliptic function
hi,
here is a first version of a program to return Jacobi elliptic function and its parameters (see here for theory).
This function is related to the Elliptic Integrals: see my version here in the Library.

INPUT: Jacobi_fn(φ, m)
where φ is the amplitude (φ=ASIN(x), where x is upper bound of Elliptic integral 1st kind expressed in other canonical form; the complete form has 0<=x<=1 or 0<=φ<=π/2); m=k^2 is the square of the eccentricity (0<=k<=1).

RETURN a matrix where the first row present u (elliptic integral 1st kind in the sine integral –with φ– form), φ, m and the second row sn (amplitude sine), cn (amplitude cosine) and dn (delta amplitude)

The Code:
Code:

// Jacobi elliptic functions
EXPORT jacobi_fn(φ, m)
// Elliptic integral of 1st kind
// φ = amplitude, m = k^2 where k is eccentricity
BEGIN
local θ, u, sn, cn, dn;
u := int(1/(SQRT(1-m*SIN(θ)*SIN(θ))),θ,0,φ);
sn :=  SIN(φ);
cn := COS(φ);
dn := SQRT(1-m*SIN(φ)*SIN(φ));
// RETURN a matrix with
// u (Elliptic integral 1st kind), φ, m
// sn (Amplitude Sine), cn (Amplitude Cosine), dn (Delta Amplitude)
RETURN [[u,φ,m], [sn, cn, dn]];
END;

For now there is no control for over boundary values.

Enjoy!
Salvo Micciché

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
10-17-2020, 08:14 PM (This post was last modified: 10-17-2020 09:57 PM by salvomic.)
Post: #2
RE: Jacobi elliptic function
With G2 Software version 2.1.14433 (2020 01 21) both in CAS and Home, if ‹number format› in Home settings is set "Standard" and Angular mode is set to "RAD" I'm trying this input for my program:
Code:
jacobi_fn(asin(1),0.4^2)
the input become
Code:
jacobi_fn(ASIN(1),0.4^2)
and the return is a matrix where the second elements of the two rows present a wrong char instead of the numbers ("⌷"), maybe an ellipsis (...)?.
See the above attachment.

If I set other format, like "Float 9" or another angular mode ("DEG" or GRAD), also with "Standard" setting the matrix shows ok.

Is it a bug or a problem here? Am I missing something?

Thanks for help.

Salvo

EDIT 1: if I input acos(1) instead of asin(1) the output is ok (but also that function become ACOS(1) in the display) and also with "Standard" format, however not if I put a number or e.g. π/2.

EDIT 2: the view is ok if I traspose the generated matrix but not if I put manually in the input line the same matrix (not transposed)

EDIT 3: in iOS I get two different output: in Home the "⌷" become an ellipsis sign (...); in CAS I get an error "Error in input": why?


Attached File(s) Thumbnail(s)
       

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
10-18-2020, 07:51 AM
Post: #3
RE: Jacobi elliptic function
In Home view and standard number format the result has to be shown (select it and press the soft key “Show”).

Remember (or discover) that CAS and Home don’t share the same memory space, and that CAS solves calculations symbolically. Thus in CAS mode, it receives the variable names and doesn’t know how to interpret them.

To create such programs for CAS, you should create a CAS program.
But remember it will try to solve it symbolically, which is sometimes impossible with integrals.

I also suggest you use the integral sign instead of the int function which is part of the CAS.

To be synthetic: your program is designed to calculate numerical values, don’t use it with CAS.

Thibault - not collector but in love with the few HP models I own - Also musician : http://walruspark.co
Find all posts by this user
Quote this message in a reply
10-18-2020, 03:27 PM
Post: #4
RE: Jacobi elliptic function
(10-17-2020 08:14 PM)salvomic Wrote:  EDIT 1: if I input acos(1) instead of asin(1) the output is ok (but also that function become ACOS(1) in the display) and also with "Standard" format, however not if I put a number or e.g. π/2.

This suggest something is wrong with simplifying acos.

I would try acos(0) though, since acos(0) = asin(1) = π/2
Find all posts by this user
Quote this message in a reply
10-18-2020, 03:35 PM
Post: #5
RE: Jacobi elliptic function
hi @pinkman,
you are right for the hints about the making of a CAS program and the use of the integral sign ∫ and so on, but I think also that the problem with the matrix output is the "ellipsis" (...) due to too long numbers in the second column, the fact is also this abbreviation is showed with a wrong symbol (⌷ instead of ...) both in CAS and in Home.
I would like to know how to avoid it with "Standard" setting and if I try to change Standard" with other settings (like Float, SCI or ENG...) or simply put an instruction first to show the matrix to set some setting and then change it again, but how to do after a RETURN instruction?

Thanks,
Salvo

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
10-18-2020, 03:37 PM
Post: #6
RE: Jacobi elliptic function
(10-18-2020 03:27 PM)Albert Chan Wrote:  This suggest something is wrong with simplifying acos.

I would try acos(0) though, since acos(0) = asin(1) = π/2

also with ACOS(0) I get the same output.

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
10-18-2020, 04:18 PM
Post: #7
RE: Jacobi elliptic function
(10-18-2020 03:35 PM)salvomic Wrote:  hi @pinkman,
you are right for the hints about the making of a CAS program and the use of the integral sign ∫ and so on, but I think also that the problem with the matrix output is the "ellipsis" (...) due to too long numbers in the second column, the fact is also this abbreviation is showed with a wrong symbol (⌷ instead of ...) both in CAS and in Home.
I would like to know how to avoid it with "Standard" setting and if I try to change Standard" with other settings (like Float, SCI or ENG...) or simply put an instruction first to show the matrix to set some setting and then change it again, but how to do after a RETURN instruction?

Thanks,
Salvo

Maybe a good solution is to use EDITMAT:

Code:

[...]
LOCAL rm;
[...]
rm := [[uU,φ,mM], [sn, cn, dn]];
EDITMAT(rm);
END;

No return statement is needed, as any program will automatically return the last calculation result.
Also watch the Help entry for EDITMAT, you can set it to be read-only.

Thibault - not collector but in love with the few HP models I own - Also musician : http://walruspark.co
Find all posts by this user
Quote this message in a reply
10-18-2020, 04:32 PM (This post was last modified: 10-18-2020 07:02 PM by salvomic.)
Post: #8
RE: Jacobi elliptic function
(10-18-2020 04:18 PM)pinkman Wrote:  Maybe a good solution is to use EDITMAT:

Code:

[...]
LOCAL rm;
[...]
rm := [[uU,φ,mM], [sn, cn, dn]];
EDITMAT(rm);
END;

No return statement is needed, as any program will automatically return the last calculation result.
Also watch the Help entry for EDITMAT, you can set it to be read-only.

thanks, I'll try so.

Salvo

EDIT: however, maybe it is simpler to use ROUND(..., 6) to show the matrix with acceptable approximation...

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)