Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Set::setraw error

  • To: mathgroup at smc.vnet.net
  • Subject: [mg90364] Re: Set::setraw error
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Mon, 7 Jul 2008 05:07:46 -0400 (EDT)
  • References: <g4q9kl$e6o$1@smc.vnet.net>

Hi,

yes xgcd[a_,b_]
define a and b as patterns and than you try to assign a new value
to pattern with
 >     If[a<0,a=-a; xsign=-1];
 >     If[b<0,b=-b; ysign=-1];

and that is
a) nonsense because a_ is any expression and you can't say that any 
expression has a value
b) you mean

xgcd[aa_, bb_] :=
  Module[{a = aa, b = bb, xsign = 1, ysign = 1, x = 1, y = 0, r = 0,
    s = 1, c, q}, If[a == 0 && b == 0, Return[{0, 0, 1}]];
   If[a == 0, Return[{Abs[b], 0, b/Abs[b]}]];
   If[b == 0, Return[{Abs[a], a/Abs[a], 0}]];
   If[a < 0, a = -a; xsign = -1];
   If[b < 0, b = -b; ysign = -1];
   While[b != 0, {c, q} = {Mod[a, b], Quotient[a, b]};
    {a, b, r, s, x, y} = {b, c, x - q*r, y - q*s, r, s}];
   Return[{a, x*xsign, y*ysign}]]

Regards
   Jens

Steven Siew schrieb:
> I have encountered this Set:setraw error for the code below.
> 
> I'm stumped. Does anyone have any idea what went wrong?
> 
> xgcd[a_,b_]:=Module[{xsign=1,ysign=1,x=1,y=0,r=0,s=1,c,q},
>     If[a == 0 && b == 0,Return[{0,0,1}]];
>     If[a == 0,Return[{Abs[b],0,b/Abs[b]}] ];
>     If[b == 0,Return[{Abs[a],a/Abs[a],0}]];
>     If[a<0,a=-a; xsign=-1];
>     If[b<0,b=-b; ysign=-1];
>     While[b\[NotEqual]0,
>       {c,q}={Mod[a,b],Quotient[a,b]};
>       {a,b,r,s,x,y}={b,c,x-q*r,y-q*s,r,s}
>       ];
>     Return[{a,x*xsign,y*ysign}]
>     ]
> 
> xgcd[2, 3]
> 
> \!\(\*
>   RowBox[{\(Set::"setraw"\), \(\(:\)\(\ \)\), "\<\"Cannot assign to
> raw \
> object \\!\\(2\\). \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", \
> ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, \
> ButtonData:>\\\"Set::setraw\\\"]\\)\"\>"}]\)
> 


  • Prev by Date: Re: Set::setraw error
  • Next by Date: Re: exporting from mathematica to a poster
  • Previous by thread: Re: Set::setraw error
  • Next by thread: Re: Set::setraw error