Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1994
*January
*February
*March
*April
*May
*June
*July
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1994

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

Search the Archive

Re: a problem with an array

  • To: mathgroup at christensen.cybernetics.net
  • Subject: Re: a problem with an array
  • From: Bill Graves <graves at bnlls1.nsls.bnl.gov>
  • 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
important.

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

Or an even more straightforward solution:

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

..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