Re: Euclidean Algorithm in Mathematica
- From: "Nena" <Nivea.Schwarzkopf@xxxxxx>
- Date: 8 Nov 2006 13:14:35 -0800
Well, thanks!
I need a slighty different example.
I would like to call the first two remainders within
a new function without defining the variables
alpha and beta outside first.
So I don't want to have this line first
{alpha, beta} = myRemainders[12, 7]
but something of the shape
g[a, b] = alpha + beta where
alpha is the first entry of the result of
myRemainders[a, b] and beta the second one.
Many thanks,
Nena
Jean-Marc Gulliet wrote:
Nena wrote:
Excellent! Thanks!
Just one little alternation.
Let alpha and beta be the first two remainders with
the condition that they are both less than the square root
of a. And also alpha > beta.
How can I list alpha and beta separately?
So that I can treat alpha and beta as variables for further
manipulations. For example to calculate
g[alpha_, beta_] := alpha^2 + beta^2
For example
In[1]:=
Remainder[a_, b_] := a - Quotient[a, b]*b
Remainder[a_, 0] := 0
myRemainders[a_, b_] := Module[{lst},
lst = FixedPointList[{Last[#1], Remainder @@ #1} &, {a, b}];
Select[lst, #1[[2]] < Sqrt[a] &, 2][[All, 2]]]
In[4]:=
{alpha, beta} = myRemainders[12, 7]
Out[4]=
{2,1}
In[5]:=
alpha
Out[5]=
2
In[6]:=
beta
Out[6]=
1
In[7]:=
alpha^2 + beta^2
Out[7]=
5
Regards,
Jean-Marc
.
- Follow-Ups:
- Re: Euclidean Algorithm in Mathematica
- From: Richard J. Fateman
- Re: Euclidean Algorithm in Mathematica
- References:
- Euclidean Algorithm in Mathematica
- From: Nena
- Re: Euclidean Algorithm in Mathematica
- From: Jean-Marc Gulliet
- Re: Euclidean Algorithm in Mathematica
- From: Nena
- Re: Euclidean Algorithm in Mathematica
- From: Jean-Marc Gulliet
- Re: Euclidean Algorithm in Mathematica
- From: Nena
- Re: Euclidean Algorithm in Mathematica
- From: Jean-Marc Gulliet
- Euclidean Algorithm in Mathematica
- Prev by Date: Re: Euclidean Algorithm in Mathematica
- Next by Date: Re: Euclidean Algorithm in Mathematica
- Previous by thread: Re: Euclidean Algorithm in Mathematica
- Next by thread: Re: Euclidean Algorithm in Mathematica
- Index(es):
Relevant Pages
|
|