I have the equation $x^2+xy+y^2=z^2$ to solve it in natural numbers.
The discriminant of it $D=4z^2-3y^2$ and must be perfect square.
I wrote Python program to get solutions for $1<x<100$ by enumeration.
def Solution():
A=[]
nMaximum=10**2
for x in range(1,nMaximum):
dTemp1a=3*x**2
for z in range(x+1, nMaximum):
dDiscriminant=4*z**2-dTemp1a
dTemp5=int(dDiscriminant**0.5)
if dTemp5**2!=dDiscriminant:
continue
dTemp6=(-1*x+dTemp5)/2
y=int(dTemp6)
if not CheckIfExists(A, z):
A.append([x,y,z])
return A
def CheckIfExists(arr, z):
bResult=False
for s in arr:
if s[2]==z:
bResult=True
break
return bResult
a = Solution()
print(len(a))
print(a)
# [3, 5, 7], [5, 16, 19], [6, 10, 14], [7, 8, 13] ...
Three variable, second degree diophantine equation doesn't explain how to get other solutions when we know the first solution $(3,5,7)$
Could you give me a hint ?
UPDATE asked by Shean: I need to get all solutions based on $(3,5,7)$. See my question as the example of what I am looking for:
or see these formulas for all solutions of Pell's equation
Can't fit this into a comment so I'll make it an answer.
Firstly, your question isn't clear.
If you are expecting to generate ALL triples from $(3,5,7)$ then I don't think this is possible (actually it may be possible, see Will's comment). If you simply want more solutions then take the triple $(3k,5k,7k)$ for any positive integer $k$.
Now if you're wondering why the solutions to formulas such as \begin{equation} x=m^2-n^2\\ y=2mn+n^2\\\tag{1} z=m^2+mn+n^2 \end{equation} where $n<m$ and $\gcd(m,n)=1$ produce less results to: simply plugging in values for $x$ and $y$ and checking if $x^2+xy+y^2$ is a square, is because $(1)$ generates primitive solutions, that is $\gcd(x,y,z)=1$.
(Note: $(1)$ sometimes produces non-primitive solutions, to remedy this, simply divide $x,y,z$ by $\gcd(x,y,z)$)
Some example code using the system $(1)$ producing only primitive triples:
Some example code plugging values for $x$ and $y$ and simply verifying the equation (This is what your code above was doing):
You can verify for yourself that any solution from the second code is a non-primitive. Or, you can run a variant of the first code which multiplies each primitive by $k=2,3,4,5$ and notice that the outputs are the same. Simply replace:
with