0
$\begingroup$

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.

$\endgroup$
2
  • 1
    $\begingroup$ Would Table and ListContourPlot be any help? $\endgroup$
    – Michael E2
    Commented Mar 11, 2016 at 11:55
  • $\begingroup$ Related: (97293), (104318) $\endgroup$
    – Michael E2
    Commented Mar 11, 2016 at 12:18

1 Answer 1

2
$\begingroup$

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]
$\endgroup$
3
  • 1
    $\begingroup$ Yes, but I've just posted a MWE - I'm working on an integral that may not have an analytical solution. $\endgroup$ Commented Mar 11, 2016 at 11:01
  • $\begingroup$ 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. $\endgroup$ Commented Mar 11, 2016 at 11:03
  • $\begingroup$ Since you're interested, math.stackexchange.com/questions/1692773/… and I want to vary the 1 and 4, like a and b in this example. $\endgroup$ Commented Mar 11, 2016 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.