MathGroup Archive 2005

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

Search the Archive

Re: Do loop is faulty

  • To: mathgroup at
  • Subject: [mg55384] Re: [mg55368] Do loop is faulty
  • From: "David Park" <djmp at>
  • Date: Mon, 21 Mar 2005 03:01:51 -0500 (EST)
  • Sender: owner-wri-mathgroup at

Whoa! You're going too fast.

Let's check first that Mathematica will integrate an expression of the form
that you have.

NIntegrate[0.3 x Sin[2x], {x, 0, 2}]

That looks Ok, so now let's set values of a[i] and b[i]. I'll do three

Clear[a, b, c];
MapThread[(a[#1] = #2) &, {{1, 2, 3}, {0.2, 0.5, 1.3}}];
Do[b[i] = i, {i, 1, 3}]

There are various ways that could have been done, including individual Set
statements for each a[i] and b[i]. But the above works. Now let's check that
the values actually have been set. (The first time I did this I made an
error and the a values were not actually set so it is worth checking!)

Table[{i, a[i], b[i]}, {i, 3}]
{{1, 0.2, 1}, {2, 0.5, 2}, {3, 1.3, 3}}

That looks good so now let's generate a table of integral values.

Table[NIntegrate[a[i] x Sin[b[i]x], {x, 0, b[i]}], {i, 3}]
{0.0602337, 0.232221, 1.244}

That seems to work.

To make good use of Mathematica it really really pays to set aside some time
and work through most of Part I of The Mathematica Book to become familiar
with the syntax, common commands, and methods of doing things. Plunging
straight into calculations without doing this will be very frustrating.

David Park
djmp at

From: dumb_founded [mailto:andreajagger_8 at]
To: mathgroup at

I define array a[i] and array b[i] of dimension 10.  Then I go through
the following Do loop, or try to, that is.


I get numerous error messages saying that b[i] is not a valid limit of

This is sheer headache.  I will never try to use Mathematica for
numerical analysis again.

All your efforts on this matter are sincerely appreciated.


  • Prev by Date: Re: String to numbers
  • Next by Date: Re: Do loop is faulty
  • Previous by thread: Re: Do loop is faulty
  • Next by thread: Re: Do loop is faulty