Group Abstract Group Abstract

Message Boards Message Boards

0
|
5.2K Views
|
5 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How to store values, when using Do?

Posted 10 years ago

I am trying to plot a DensityPlot of a following integral, but I don't know how to store values generated using Do in a usable format. Following is the code that I have. Please suggest me a solution. Thanks a lot in advance!

    EQ1 = y1/((x1 - x)^2 + y1^2);

    Do[NIntegrate[EQ1, {x, 10^-10, 10}], {x1, 10^-10, 0.5, 5}, {y1, 10^-10, 0.5, 5}];
POSTED BY: Sid D
5 Replies
Posted 10 years ago

Hi Sid, A couple of spot checks look reasonable. Maybe the function isn't doing what you expect. enter image description here

POSTED BY: David Keith
Posted 10 years ago

Thanks a lot!

POSTED BY: Sid D
Posted 10 years ago

Thanks a lot, this was really helpful! Looking at the plot, I am not sure though if the the solution is correct.

POSTED BY: Sid D

Another, slightly different way:

f[x1_?NumericQ, y1_] := 
  NIntegrate[y1/((x1 - x)^2 + y1^2), {x, 10^-10, 10}];
DensityPlot[f[x1, y1], {x1, 0, 1}, {y1, 0, 1}]
POSTED BY: Gianluca Gorni
Posted 10 years ago

Hi Sid,

In Mathematica, there is almost always a better construct than Do or For. The attached notebook first uses Table to generate a table of values and ListDensityPlot to plot them. Then it defines a function of x1 and x2 to do the integration, and uses DensityPlot to plot that over a field of x1 and y1.

Best, David

Attachments:
POSTED BY: David Keith
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard