       Re: how to display the value of w after using do?

• To: mathgroup at smc.vnet.net
• Subject: [mg111030] Re: how to display the value of w after using do?
• From: Bill Rowe <readnews at sbcglobal.net>
• Date: Sat, 17 Jul 2010 08:17:40 -0400 (EDT)

```On 7/16/10 at 5:15 AM, ynzhang at mech.uwa.edu.au wrote:

>I am a beginner of Mathematica. I just wrote a Notebook(nb) in
>Mathematica to in order to obtain the Gauss-Hermite weights as
>follows:

>n = 5; Do[w[n][k] = Exp[z0[n][k]^2] Sqrt[Pi] 2^(n - 1)  n! / (n
>HermiteH[n - 1, z0[n][k]])^2, {k, n}]; I press shift & Enter to
>Evalutate. The results come out with only

>In:= Do[w[n][k] = Exp[z0[n][k]^2] Sqrt[Pi] 2^(n - 1)  n! / (n
>HermiteH[n - 1, z0[n][k]])^2, {k, n}];

>without Out.So I dont know if w comes out or not at last . If so,
>there should be a row or column vector shown in Out.

There are several issues here. First, the semicolon you've used
causes what you've written to be a compound expression
equivalent to expr;Null. When evaluating a compound expression,
Mathematica returns only the output from the last portion which
would be Null in this case. That is when you end your statement
with a semicolon, no matter what the earlier portion of the code
would return nothing will be returned to the output.

Next, Do has no return value. So, in this case omitting the
semicolon will not cause an output to appear.

Using Table instead of Do will create an output. That is:

n = 5;
Table[Exp[z0[n][k]^2] Sqrt[
Pi] 2^(n - 1) n!/(n HermiteH[n - 1, z0[n][k]])^2, {k, n}]

But while this will produce an output, it may not be what you
want. I suspect you may have intended the notation z0[n] to be
the nth element of z0. If so, that is not how Mathematica
evaluates this notation. Notation in the form of name[expr] is
evaluated by Mathematica as a function with name name evaluated
at whatever is returned by expr. At times it can be convenient
to think of name[n] as being the nth element of name. But it is
important to realize Mathematica treats this differently than an array.

=46or example, consider

In:= Do[w[k] = 2 k, {k, 5}]

In:= w

Out= 4

Demonstrating w has the expected value. But note

In:= w^2

Out= w^2

Here, w^2 is returned unevaluated since I've not provided an
argument to the function w. Now, consider

In:= z = Table[2 k, {k, 5}];
z[]

Out= 4

Demonstrating the second element of z has the expected value. And

In:= z^2

Out= {4,16,36,64,100}

Here, each element of z is squared since most built-in functions
thread over lists. And this last output is usually what one wants

=46inally, Mathematica has no concept of row or column vectors.
You can produce either a 1 x n or n x 1 matrix if you like. For
example, {Range} will create a 1 x 5 matrix and
List/@Range will create a 5 x 1 matrix.

```

• Prev by Date: How to parametrize a block of commands?
• Next by Date: Re: Hatched shading?
• Previous by thread: Re: how to display the value of w after using do?
• Next by thread: Changing the default width of Exported cells