I am try to solve the following differential equation numerically: $$\frac{\partial p}{\partial t}=\frac{\partial^2 p}{\partial x^2}-e^{-t}\frac{\partial p}{\partial x}$$ with boundary conditions $p(x=0,t)=p(x=L,t)=0$ and initial condition $p(x,0)=\delta(x-x_0)$. I am also interested in computing the quantity: $$q(t)=\int_0^L p(x,t)dx$$ which satisfies the equation: $$q(t)=\frac{\partial p}{\partial x}(L,t)-\frac{\partial p}{\partial x}(0,t)$$ with initial condition $q(0)=1$.

I have tried the following in Mathematica:

NDSolve[{D[p[x, t], {t, 1}] == D[p[x, t], {x, 2}] - Exp[-t] D[p[x, t],x],
p[0, t] == 0, p[L, t] == 0,
p[x, 0] == 1/Sqrt[2 Pi sigma^2] Exp[-(x-x0)^2/(2 sigma^2)],
q'[t]==D[p[L, t], x] - D[p[0, t], x],q[0]==1}, 
{p[x, t],q[t]}, {x, 0, L}, {t, 0, T}]

Note that I have approximated the initial delta-function condition with a Gaussian. When I run this code I get the error:

Function::fpct: Too many parameters in {x,t} to be filled from Function[{x,t},1][t].

Could you help me to understand why? Thank you

  • $\begingroup$ What are the numerical values for x0, L, T and sigma? $\endgroup$ – zhk May 15 '17 at 16:32
  • 1
    $\begingroup$ What is p^{0, 1}[L, t] ? $\endgroup$ – rhermans May 15 '17 at 16:32
  • $\begingroup$ I use sigma=1/32, L=10, T=1. The derivative p^{1,0} is the first derivative with respect to x (there was a mistake in the previous formula), I don't know how to write it properly here sorry $\endgroup$ – Andrea May 15 '17 at 16:34
  • 1
    $\begingroup$ I think you mean D[p[x, t], {x, 1}] ? $\endgroup$ – rhermans May 15 '17 at 16:36
  • $\begingroup$ it's D[p[x,t],{x,1}], but evaluated at x=0 and x=L, I have now updated the code above thank you (the error is still the same) $\endgroup$ – Andrea May 15 '17 at 16:36

Something like this?

sigma = 1/32; x0 = 1; L = 10; T = 1;
{p[x_, t_]} = {p[x, t]} /.First@NDSolve[{D[p[x, t], {t, 1}] == 
     D[p[x, t], {x, 2}] - Exp[-t] D[p[x, t], x], p[0, t] == 0, 
    p[L, t] == 0, p[x, 0] == 1/Sqrt[2 Pi sigma^2] Exp[-(x - x0)^2/(2 sigma^2)]}, {p[x, t], 
     q[t]}, {x, 0, L}, {t, 0, T}]
q[t_] := NIntegrate[p[x, t], {x, 0, L}];
Plot[q[t], {t, 0, T}, PlotRange -> All]

enter image description here


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