MathGroup Archive 1994

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

Search the Archive

Re: a problem with an array

  • To: mathgroup at
  • Subject: Re: a problem with an array
  • From: Bill Graves <graves at>
  • Date: Mon, 24 Oct 94 11:48:01 EDT

Jesus Rojo writes:
> I have a Module (in a Package) that say
> 		nombre[M_,N_]:=
> 		Module[{},
> 		(* M is for input and N for output *)
> 		N=Table[0.,{5}];
> 		Do[
> 		  N[[i]]=M[[i,i]]
> 		,{i,1,5}];
> 		.....................................
> 		]
> The first time that I run this, all in correct. But the next
> time an error happen.

I think it's a good idea to make the output variable "N" local to the
module, and have the module return "N".  Note the initialization of
N to an empty list and use of the AppendTo[] function.  Also note the
way "N" is returned.  The lack of a ";" before the closing bracket is

nombre[M_List] := Module[{N={}},
  Do[ AppendTo[N, M[[i,i]]], {i,1,5}];

Or an even more straightforward solution:

nombre[M_List] := Module[{N},
  N = Table[M[[i,i]], {i,5}];

..Bill Graves

  • Prev by Date: Re: matrix of coefficents
  • Next by Date: Re: function definition
  • Previous by thread: Re: matrix of coefficents
  • Next by thread: Help with conditional rules