Message Boards Message Boards

Plot and animate numerically calculated integral?

Posted 3 years ago

I want to plot the expression formed from numerically calculated Poisson integrals (aka fundamental solutions of heat equation). I can only get numerical values.

ODE system. We extract the solutions. They will serve as initial conditions in Poisson integrals. Then we choose parameter, some x and t and integration limits. After that we consctruct the expression. I need to plot and animate q for any x and t intervals. By this code I can only get numerical values.

s = NDSolve[{u'[x] == -3 W[x] + x, W'[x] == u[x] - W[x]^3, u[0] == -1,
W[0] == 1}, {u, W}, {x, 0, 200}]
G = First[u /. s]
g = First[W /. s]

\[Epsilon] = 1/10
T = -1/2
X = 10
p1 = -200
p2 = 200

Q1 = 1/( 2 Sqrt[Pi *((T) + 1)*(\[Epsilon])^(2)]) NIntegrate[
Exp[-(Abs[X - \[Xi]])^2/(4*((T) + 
1)*(\[Epsilon])^(2))] g[\[Xi]] G[\[Xi]] \
(-1/(2*(\[Epsilon])^2)), {\[Xi], p1, p2}]
Q2 = 1/( 2 Sqrt[Pi *((T) + 1)*(\[Epsilon])^(2)]) NIntegrate[
Exp[-(Abs[X - \[Xi]])^2/(4*((T) + 
1)*(\[Epsilon])^(2))] g[\[Xi]], {\[Xi], p1, p2}]
q = (-2 (\[Epsilon])^2 )*(Q1/Q2)

I think it should be very simple, but I am a newbie in Wolfram Mathematica, so I'm sorry if the question is too trivial. Hope to get help.

Attachments:
POSTED BY: Kevin Bates
5 Replies

Try and adjust the PlotRange.

POSTED BY: Gianluca Gorni

The semicolon";" at the end of the input suppresses the display of the output. Then you must be patient, because those plots take a lot of numerical integrations. Here is a simplified version that runs faster:

Table[ListPlot[
  Table[(1/(2 Sqrt[Pi*((t) + 1)*(\[Epsilon])^(2)])*
      NIntegrate[
       Exp[-(Abs[x - \[Xi]])^2/(4*((t) + 1)*(\[Epsilon])^(2))]*
        g[\[Xi]] G[\[Xi]]*
        (-1/(2*(\[Epsilon])^2)), {\[Xi], p1, p2}])/
    (1/(2 Sqrt[Pi*((t) + 1)*(\[Epsilon])^(2)])*
      NIntegrate[Exp[-(Abs[x - \[Xi]])^2/
          (4*((t) + 1)*(\[Epsilon])^(2))] g[\[Xi]],
       {\[Xi], p1, p2}]),
   {x, 0, 2, 1/10}],
  PlotRange -> All],
 {t, {-2}}]

I took the liberty of changing the PlotRange.

POSTED BY: Gianluca Gorni
Posted 3 years ago

Thank you for the code. After couple of minutes Mathematica had returned the plot. It's a little bit strange that x-axis is shifted. Any way to correct it?

For example I used x from 9.5 to 10.5 with a step 1/2, but it returned "numbers" of numbers: 9.5 is 1, 10 is 2. Not the actual x-axis.

POSTED BY: Kevin Bates

Your solution s is defined in the interval between 0 and 200. Then you integrate between -200 and 200. Are you sure this is what you mean?

POSTED BY: Gianluca Gorni
Posted 3 years ago

Thank you for noticing, I have changed 0 to -200. But it doesn't change nor the result of Nintegrate nor the result of plotting by Table. It's just "running", that's all.

plots = Table[
   Plot[(1/( 2 Sqrt[Pi *((t) + 1)*(\[Epsilon])^(2)]) NIntegrate[
        Exp[-(Abs[x - \[Xi]])^2/(4*((t) + 
               1)*(\[Epsilon])^(2))] g[\[Xi]] G[\[Xi]] (-1/(2*(\
\[Epsilon])^2)), {\[Xi], p1, p2}])/(1/( 
         2 Sqrt[Pi *((t) + 1)*(\[Epsilon])^(2)]) NIntegrate[
        Exp[-(Abs[x - \[Xi]])^2/(4*((t) + 
               1)*(\[Epsilon])^(2))] g[\[Xi]], {\[Xi], p1, p2}]), {x, 
     0, 2}, PlotRange -> {-10, 10}], {t, -2, 0, .25}];

And

Plot3D[Evaluate[(1/( 
       2 Sqrt[Pi *((t) + 1)*(\[Epsilon])^(2)]) NIntegrate[
      Exp[-(Abs[x - \[Xi]])^2/(4*((t) + 
             1)*(\[Epsilon])^(2))] g[\[Xi]] G[\[Xi]] (-1/(2*(\
\[Epsilon])^2)), {\[Xi], p1, p2}])/(1/( 
       2 Sqrt[Pi *((t) + 1)*(\[Epsilon])^(2)]) NIntegrate[
      Exp[-(Abs[x - \[Xi]])^2/(4*((t) + 
             1)*(\[Epsilon])^(2))] g[\[Xi]], {\[Xi], p1, p2}])], {t, 
  0, 10}, {x, -10, 10}]

or even

Plot3D[(1/( 2 Sqrt[Pi *((t) + 1)*(\[Epsilon])^(2)]) NIntegrate[
     Exp[-(Abs[x - \[Xi]])^2/(4*((t) + 
            1)*(\[Epsilon])^(2))] g[\[Xi]] G[\[Xi]] \
(-1/(2*(\[Epsilon])^2)), {\[Xi], p1, p2}])/(1/( 
      2 Sqrt[Pi *((t) + 1)*(\[Epsilon])^(2)]) NIntegrate[
     Exp[-(Abs[x - \[Xi]])^2/(4*((t) + 
            1)*(\[Epsilon])^(2))] g[\[Xi]], {\[Xi], p1, p2}]), {t, 0, 
  10}, {x, -10, 10}]

is also useless.

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

Group Abstract Group Abstract