Re: mathematica newbie ?

*To*: mathgroup at smc.vnet.net*Subject*: [mg92427] Re: mathematica newbie ?*From*: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>*Date*: Tue, 30 Sep 2008 21:50:54 -0400 (EDT)*Organization*: The Open University, Milton Keynes, UK*References*: <gbt2pe$lcc$1@smc.vnet.net>

Jared.webb at yahoo.com wrote: > I am extremely new to mathematica and am having trouble following the > documentation. > > I would like to set up the following loop and have it send the output > to a vector. > > If I have in mathematica: > > nsupports=3 > ndof=10 > nels=2 > int=range[0,nsupports-1] - this is my iterator > > I want to set up a loop: > > for x in int: > if x=0, return 0 > if x=nsupports-1, return ndof-2 > otherwise, return x*nels*2 > > I want the output to go to a column vector. Assuming I have correctly understood the pseudo-code, a possible solution is as follows: In[1]:= nsupports = 3; ndof = 10; nels = 2; int = Range[0, nsupports - 1]; Table[If[x == 0, 0, If[x == nsupports - 1, ndof - 2, x*nels*2]], {x, int}] Out[20]= {0, 4, 8} Regards, -- Jean-Marc