Re: Trouble modif. Matrix in function
- To: mathgroup at smc.vnet.net
- Subject: [mg29079] Re: [mg29068] Trouble modif. Matrix in function
- From: BobHanlon at aol.com
- Date: Sun, 27 May 2001 18:04:44 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Instead of explicitly nesting Table in the definition of TavGen, just use
multiple iterators.
TavGen[n_] := Table[1, {p, 1, n}, {i, 1, p}];
Elim[Rig_, Pos_, Offset_:0] := (TAB[[Rig, #]] = 0) & /@
Table[i, {i, Pos, Pos + Offset}];
When you called ElimG with a parameter value of TAB, the matrix TAB was used
not the
symbol TAB. To pass the symbol, you need to give ElimG the attribute
HoldFirst.
SetAttributes[ElimG, HoldFirst];
ElimG[P_, Rig_, Pos_, Offset_:0] := (P[[Rig, #]] = 0) & /@
Table[i, {i, Pos, Pos + Offset}];
TAB = TavGen[6];
Elim[5, 3, 2];
ans = TAB;
TAB = TavGen[6];
ElimG[TAB, 5, 3, 2];
TAB == ans
True
Bob Hanlon
In a message dated 2001/5/26 10:27:28 PM, nicola-mingotti at nospam-libero.it
writes:
>I'm new to the comp.soft-sys.math.mathematica
>so I hope this question has not been asked many time yet :)
>
>So :
>
>Defining
>
>TavGen[n_] := Table[
> Table[1, {i, 1, p}], {p, 1, n}]
>
>TAB = TavGen[6]
>
>Function 1) works , 2) does not work
>***********************************************
>1) Elim[Rig_, Pos_, Offset_:0] :=
> (TAB[[Rig, #]] = 0) & /@ Table[i, {i, Pos, Pos + Offset}]
>*************************************************
>
>*************************************************
>2) ElimG[P_, Rig_, Pos_, Offset_:0] :=
> (P[[Rig, #]] = 0) & /@ Table[i, {i, Pos, Pos + Offset}]
>*************************************************
>
>ElimG[TAB, 3, 2]
>this gives me :
>
>Set::"setps": "\!\({\(\({1}\)\), \(\({1, 1}\)\), \(\({1, 0, 1}\)\), \(\({1,
>\
>1, 1, 1}\)\), \(\({1, 1, 1, 1, 1}\)\), \(\({1, 1, 1, 1, 1, 1}\)\)}\) in
>\
>assignment of part is not a symbol."
>
>**************************************************
>
>I tried using a For instead of a Map but nothing changes :(
>