Re: Do loop is faulty

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

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}] 0.139333 That looks Ok, so now let's set values of a[i] and b[i]. I'll do three cases. 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 earthlink.net http://home.earthlink.net/~djmp/ From: dumb_founded [mailto:andreajagger_8 at hotmail.com] To: mathgroup at smc.vnet.net 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. Array[c,10]; Do[c[i]=NIntegrate[a[i]*x*Sin[b[i]*x],{x,0,b[i]}] I get numerous error messages saying that b[i] is not a valid limit of integration. This is sheer headache. I will never try to use Mathematica for numerical analysis again. All your efforts on this matter are sincerely appreciated. Thanks