Re: Diophant equation
- To: mathgroup at smc.vnet.net
- Subject: [mg42137] Re: Diophant equation
- From: "Dr. Wolfgang Hintze" <weh at snafu.de>
- Date: Fri, 20 Jun 2003 04:57:34 -0400 (EDT)
- References: <bcrru8$hq6$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Ken,
thanks. Very elegant.
To get the natural solutions (x,y > 0) I have added
In[103]:=
t = Table[s, {k, -100, 100}];
In[102]:=
u = Select[t, First[#1] > 0 && Last[#1] > 0 & ]
The first part (Table) can surely be improved.
Question: what is the meaning of the construct k_:k in your function?
I have never seen this before, and the formula works also without it
(i.e. writing just k_).
Wolfgang
Ken Levasseur wrote:
> Wolfgang:
>
> ExtendedGCD contains all of the information you need to construct the general solution. Here is one way to put it into the form {x,y}
>
> LinearDiophantine[a_,b_,c_,k_:k]:=
> ExtendedGCD[a,b]//If[Mod[c,First[#]]=!=0,{},c Last[#]+k{b/First[#],-a/First[#]}]&
>
> In[16]:=LinearDiophantine[120, 45, 15, k]
> Out[16]={3*k - 15, 45 - 8*k}
>
> In[17]:=LinearDiophantine[120, 43, 1, l]
> Out[17]= {43*l + 19, -120*l - 53}
>
> In[18]:= LinearDiophantine[120, 48, 1, l]
> Out[18]= {}
>
> Ken Levasseur
> Math. Sci.
> UMass Lowell
> On Monday, June 16, 2003, at 03:58AM, Dr. Wolfgang Hintze <weh at snafu.de> wrote:
>
>
>>How can I solve a linear Diophant equation like
>>
>>a x + b y = c
>>
>>where a, b, and c are given integers >0 for integer x and y in Mathematica?
>>
>>The solution is a one parameter family of the type
>>
>>x = A t + B, y = C t + D
>>
>>Any hint welcome.
>>
>>Wolfgang
>>
>>
>>
>>
>