Johan Skak
Johan Skak

Reputation: 1

How to use InterpolationFunction as input to NDSolve PDE

I am trying to use the output of one NDSolve command as part of my PDE for the next one. I happen to know the exact formula (in this specific example) for the output of the first NDSolve command so I can directly compare the result.

Here is the code for the first NDSolve:

inc = W0[0, x, p] == E^(-(x^2 + p^2)/2) Boole[Abs[x] < 6 && Abs[p] < 6];
bcs = {W[t, -6, p] == 0, W[t, 6, p] == 0, W[t, x, -6] == 0, W[t, x, 6] == 0};
df[t_, x_, p_] = -p D[W0[t, x, p], x] + x D[W0[t, x, p], p];
s = NDSolve[{D[W0[t, x, p], t] == df[t, x, p], inc, bcs /. W -> W0}, W0, {t, 0, 1}, {x, -6, 6}, {p, -6, 6}]

Which returns a nice gauss when plotted (the solution is stationary). Know the code continues as follows:

inc1 = W1[0, x, p] == 0;
df1[t_, x_, p_] = -p D[W1[t, x, p], x] + x D[W1[t, x, p], p] + (x^3 D[W_1[t, x, p], p] - x D[W_1[t, x, p], {p,3}] /. s);
s1 = NDSolve[{D[W1[t, x, p], t] == df1[t, x, p], inc1, bcs /. W -> W1}, W1, {t, 0, 1}, {x, -6, 6}, {p, -6, 6}]

Which gives the error message: NDSolve: Encountered non-numerical value for a derivative at t == 0.`.

I have tried exchanging df1 with df1[t_, x_, p_] = -p D[W1[t, x, p], x] + x D[W1[t, x, p], x] N[(x^3 p + 3 p x - p^3 x) E^(-(1/2) (x^2 + p^2))] which gives the expected result without any errors. How can I get it to work with the InterpolationFunction?

Upvotes: 0

Views: 20

Answers (0)

Related Questions