(12C) Pell's Equation - Printable Version +- HP Forums ( https://www.hpmuseum.org/forum)+-- Forum: HP Software Libraries ( /forum-10.html)+--- Forum: General Software Library ( /forum-13.html)+--- Thread: (12C) Pell's Equation ( /thread-11018.html) |

(12C) Pell's Equation - Gamo - 07-07-2018 05:16 AM
Pell's equation (also called the Pell–Fermat equation) is the equation of the form of X^2 - nY^2 = 1 Where n is a given positive none square integer and integer solutions are sought for X and Y. More information about this topic: https://en.wikipedia.org/wiki/Pell%27s_equation I personally make a note on this subject found on this MoHPC old forum and don't remember who posted this in the forum. I found this very interesting and would like to share his clever program to solve this special equation. Example: X^2 - (3)Y^2 = 1 3 R/S --> 2 X<>Y 1 Answer: X=2, Y=1 Remark: The list of the possible n is shown in the Wikipedia link. Program: Pell's Equation Code:
Gamo RE: (12C) Pell's Equation - Thomas Klemm - 07-07-2018 09:29 AM
(07-07-2018 05:16 AM)Gamo Wrote: I personally make a note on this subject found on this MoHPC old forum and don't remember who posted this in the forum. Cf. Re: x^2 - N*y^2 = 1 (12C) and 12-digit cut-off Other threads related to that topic are: RE: (12C) Pell's Equation - Dieter - 07-07-2018 11:24 AM
(07-07-2018 05:16 AM)Gamo Wrote: I personally make a note on this subject found on this MoHPC old forum and don't remember who posted this in the forum. The program you posted was written by Gerson W. Barbosa, it can be found in the old forum as linked in Thomas' post. The limitations of a 10-digit calculator have already been mentioned. This means that results with 6 digits or more may and will produce roundoff errors when x² or y² is calculated. And checking whether Pell's equation evaluates to 1 or not will fail. Which doesn't mean there is no way – consider the posts by Egan Ford in the mentioned old forum thread. Having said that, here's my attempt. A bit shorter and with less registers. ;-) Code: `01 STO 0` This returns the first solution of the equation (at least if the trivial solution x=1 and y=0 is ingored). Example: n=92 Code: `f PRGM` But there are infinitely many more solutions. These can be obtained with the recurrence formula as shown in the Wikipedia article. Replace the last three steps in the program above with this: Code: `...` Example: n=7 Code: `f PRGM` Please note that there is no solution if n is the square of an integer. In this case the program will throw an error: 25 [R/S] => Error 0. Dieter RE: (12C) Pell's Equation - Gamo - 07-08-2018 10:51 AM
Ah...that from Gerson W. Barbosa So my post is credit to Gerson who make this clever program....Thanks Gerson Gamo RE: (12C) Pell's Equation - SlideRule - 07-11-2018 02:49 PM
For those with an interest [attachment=6114] an excellent read (IMHO) BEST! SlideRule |