MathGroup Archive 2008

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

Search the Archive

Re: mathematica newbie ?

  • To: mathgroup at
  • Subject: [mg92481] Re: mathematica newbie ?
  • From: Bill Rowe <readnews at>
  • Date: Wed, 1 Oct 2008 18:32:13 -0400 (EDT)

On 9/30/08 at 7:33 AM, Jared.webb at 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:

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

While this can be done using a For loop, this is definitely not
what I would use. I will leave it to others to show how this can
be done using a For loop. Now having said that, your if
statements seem to work out as follows

x = 0 output 0
x = nsupports-1 which evaluates to 2 output ndof - 2 which
evaluates to 8
for any other x output x * nels * 2 which evaluates to 4 * x

Note that for x = 2, the output is the same as 4 * x and this is
also the case for x = 0.

So, the desired output can be created using

4 Range[0,nsupports-1]

This will return a list. Mathematica does not distinguish
between row and column vectors. It is possible to create a n x 1
array which could be considered a column vector. Changing the
syntax above to

4 List/@Range[0, nsupport-1]

will create a nsupport-1 x 1 array

  • Prev by Date: Re: Plotting f = Function[x,expr] and f[x_] := expr
  • Next by Date: Re: Comparison between Mathematica and other symbolic systems
  • Previous by thread: RE: Plotting f = Function[x,expr] and f[x_] := expr
  • Next by thread: Re: data source for demonstration