0

I want to plot the results of a 'do' loop as a contour graph:

z = Reap[
  Do[
   Do[
    Sow[
     NIntegrate[Sin[a + b*x], {x, -10, 10}]
     ],
    {b, 0, 6, 0.5}
    ],
   {a, 0, 5, 0.5}
   ]
  ]

I get a list of values, but I'm not sure of the best way to rearrange everything to be able to plot a b vs a contour of z.

1 Answers1

2

Why numerically integrate when you can precisely integrate?

ArrayPlot@(z=Table[
  Integrate[Sin[a + b x], {x, -10, 10}], 
  {b, 0, 6, 0.5}, 
  {a, 0, 5, 0.5}])

or

ListPlot[z, 
Joined -> True,
PlotRange -> All]
David G. Stork
  • 41,180
  • 3
  • 34
  • 96
  • 1
    Yes, but I've just posted a MWE - I'm working on an integral that may not have an analytical solution. – Medulla Oblongata Mar 11 '16 at 11:01
  • What is the integral you seek? By the way, you should almost never use Do in Mathematica... there are almost always superior ways to iterate, most notably Table. – David G. Stork Mar 11 '16 at 11:03
  • Since you're interested, http://math.stackexchange.com/questions/1692773/cauchy-principal-value-of-integral-with-undefined-point and I want to vary the 1 and 4, like a and b in this example. – Medulla Oblongata Mar 11 '16 at 11:03