Message Boards Message Boards

3 Replies
0 Total Likes
View groups...
Share this post:

After compilation, NDSolve and graph of energy don't run.

Posted 11 years ago
Good evening everybody!
There's a problem I dealt with some time ago. I tried to find numerical solution of PDE (and managed) and then tried to draw a graph of an energy, that may be represented as a triple integral of a solution of this PDE (see the code below). Everything was OK, but after I'd compiled my programm, there existed a strange problem: the programm stopped to work and the graph of energy wasn't drawn. I'd be very grateful to you, if you show me where I had a mistake and whether it's possible to correct it and improve the code.
Thanks beforehand.

 Clear[A, sol, x, y, z, t, R, V, v1, v2, E1, x1, y1, z1];
 R = 1000;
 V = 0.1;
 sol = NDSolve[{D[A[t, x, y, z], t] +
      V*Sin[z]*Exp[-z/R]*D[A[t, x, y, z], x] == (1/R)*
      D[A[t, x, y, z], z, z], A[0, x, y, z] == Sin[x] + Sin[y],
    A[t, 0, y, z] == A[t, 2*Pi, y, z],
    A[t, x, 0, z] == A[t, x, 2*Pi, z]},
   A, {t, 0, 10}, {x, 0, 2*Pi}, {y, 0, 2*Pi}, {z, 0,
nsol = Evaluate[A[t, x, y, z] /. sol][[1, 0]];
v1[t_, x_, y_, z_] :=
  Exp[-t/R]*(V*Sin[z] - (D[nsol[x, y1, z, t], y1] /. y1 -> y));
v2[t_, x_, y_, z_] :=
  Exp[-t/R]*(D[nsol[x1, y, z, t], x1] /. x1 -> x);
E1[t_] := -(1/R)*
   NIntegrate[(D[v1[t, x, y, z1], z1] /.
        z1 -> z)^2 + (D[v2[t, x, y, z1], z1] /. z1 -> z)^2, {x, 0,
     2*Pi}, {y, 0, 2*Pi}, {z, 0, 2*Pi}];
Plot[E1[t], {t, 0, 10}]
POSTED BY: Mark Turtsinskyi
3 Replies
If the failure happened after compiling, maybe the Compile function call had a mistake.
How was it set up?

Your code as given had a warning about insufficient boundary conditions.
I do not know if that might be part of the problem.
POSTED BY: Bruce Miller
Yes, I know there was a warning about boundary conditions. But just before I compiled this code, I drew a graph of v1(x,y,z,t) in particular point (x,y) and everything was OK. Such a warning I received also in this case, but nevertheless the graph was drawn.
I suspect, there may be a mistake in numerical integration, because the graphs of v1 and v2 in particular points were well drawn.
Thanks a lot for your advice.

May be, there'll be some suggestions how the code may be corrected.
POSTED BY: Mark Turtsinskyi
When troubleshooting, it's easier if you evalute the statements one at a time.
POSTED BY: Frank Kampas
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract