1

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

Andrea
  • 521
  • 2
  • 10
  • What are the numerical values for x0, L, T and sigma? – zhk May 15 '17 at 16:32
  • 1
    What is p^{0, 1}[L, t] ? – rhermans May 15 '17 at 16:32
  • 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 – Andrea May 15 '17 at 16:34
  • 1
    I think you mean D[p[x, t], {x, 1}] ? – rhermans May 15 '17 at 16:36
  • 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) – Andrea May 15 '17 at 16:36
  • Then Derivative[0,1][p][L,t]-Derivative[0,1][p][0,t]. And wouldn't NDSolve expect numerical values for L and T in {x, 0, L}, {t, 0, T} – rhermans May 15 '17 at 16:43

1 Answers1

4

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

zhk
  • 11,939
  • 1
  • 22
  • 38
  • Hi, I am having a similar error. I posted the question at https://mathematica.stackexchange.com/questions/182702/simulating-a-pdes . PS:vI dont know if its correct to post it here. – kosa Sep 27 '18 at 13:58