Pythagorean Triangle Search

07122020, 04:16 PM
Post: #1




Pythagorean Triangle Search
Three Integers Make a Right Triangle
A Pythagorean triple is a trio of positive integers a, b, and c, that describe the lengths of a right triangle, where a and b are the lengths of the sides while c is the length of the hypotenuse. The variables a, b, and c follow the Pythagorean Theorem: a^2 + b^2 = c^2 Where the following measurements perimeter and area are calculated as: p = perimeter = a + b + c r = area = a * b / 2 With two positive integers m and n where m > n, Euclid gives a formula where a, b, and c are generated: a = 2 * m * n b = m^2  n^2 c = m^2 + n^2 This can easily verified to satisfy the Pythagorean Theorem: a^2 + b^2 = c^2 (2*m*n)^2 + (m^2  n^2)^2 = (m^2 + n^2)^2 4*m^2*n^2 + m^4  2*m^2*m^2 + n^4 = m^4 + 2*m^2*m^2 + n^4 4*m^2*n^2 + m^4  4*m^2*m^2 + n^4 = m^4 + n^4 m^4 + n^4 = m^4 + n^4 The following program PYTHRI asks you for m and n and generates a Pythagorean triple. Make sure that m > n. Code: HP Prime Program PYTHRI Can We Go the Other Way? Let's say we have the area and the perimeter of a right triangle. Can we find a Pythagorean triple? In order to do so, we need to solve for m and n, and make sure that m and n are positive integers. Recall that: a = 2 * m * n b = m^2  n^2 c = m^2 + n^2 Perimeter: p = a + b + c p = 2 * m * n + m^2  n^2 + m^2 + n^2 p = 2 * m^2 + 2 * m * n Area: r = a * b / 2 r = m * n * (m^2  n^2) r = m^3 * n  m * n^3 Let's solve for n in the perimeter equation: p = 2 * m^2 + 2 * m * n p  2 * m^2 = 2 * m * n Since m is a positive integer, m ≠ 0 and by dividing by 2 * m: p / (2* m)  m = n Substitute in the area equation: r = m^3 * n  m * n^3 r = m^3 * (p / (2* m)  m)  m * (p / (2* m)  m)^3 The program IPYTHTRI attempts to find a Pythagorean triple by solving for m in the above equation. A first initial guess of 0 is used, but the initial guess uses powers of 10 for any further iterations that are needed. Should a triple not be found, the program will indicate the finding. Perfect search is not guaranteed. If a suitable solution is found, then the program calculates and displays a, b, and c. HP Prime Program IPYTHTRI (inverse PYTHTRI) Code: EXPORT IPYTHTRI() Examples (p = perimeter, r = area) m = 5, n = 3 a = 30, b = 16, c = 34 p = 80, r = 240 m = 11, n = 6 a = 132, b = 85, c = 157 p = 374, r = 5610 m = 18, n = 14 a = 504, b = 128, c = 520 p = 1152, r = 32256 m = 164, n = 133 a = 43624, b = 9207, c = 44585 p = 97416, r = 200,823,084 Source: Pythagorean triple. Wikipedia. Last Edited June 13, 2020. https://en.wikipedia.org/wiki/Pythagorean_triple Accessed June 13, 2020 Eddie http://edspi31415.blogspot.com/2020/07/h...earch.html 

« Next Oldest  Next Newest »

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