Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

First I can solve a transport equation with a source (Is it still called transport equation?) using DSolve. The form of the source serves only as an example. It can be anything.

sol1 = DSolve[
          { D[y[x, t], t] - 2 D[y[x, t], x] == Exp[-(t - 1)^2 - (x - 5)^2],
            y[x, 0] == 0
          },
          y[x, t],
          {x, t}
          ];

Plot3D[Evaluate[y[x, t] /. sol1], {x, -10, 10}, {t, 0, 15}, PlotRange -> All]

It will give me the following results. This is what I expected.

Results using DSolve

My question is, if I want to use NDSolve instead, what should I use as boundary conditions? The BC should allow the bulk to follow out of the domain and never return. I have no idea how to write down the BC.

For example,

sol3 = NDSolve[
          { D[y[x, t], t] - 2 D[y[x, t], x] == Exp[-(t - 1)^2 - (x - 5)^2],
            y[x, 0] == 0,
            y[-10, t] == 0,
            y[10, t] == 0},
          y[x, t],
          {x, -10, 10},
          {t, 0, 15}];

Plot3D[Evaluate[y[x, t] /. sol3], {x, -10, 10}, {t, 0, 15}, PlotRange -> All]

will give me an error and the following results which is obviously wrong:

NDSolve::eerr: Warning: scaled local spatial error estimate of 89.96891825336817` at t = 15.` in the direction of independent variable x is much greater than the prescribed error tolerance. Grid spacing with 25 points may be too large to achieve the desired accuracy or precision. A singularity may have formed or a smaller grid spacing can be specified using the MaxStepSize or MinPoints method options. >>

enter image description here

I think the error might involve something besides BC.

share|improve this question
    
The BC chosen does not match with the values (functions of t in this case) of the analytical function. This explains why DSolve and NDSolve give different results. Also if you want two boundary conditions these must be compatible with the problem. Actually, you need a boundary condition only for NDSolve if you have the analytic solution one condition suffices. –  Spawn1701D Apr 7 '13 at 7:03
    
@Spawn1701D, I do understand that the BC does not match the analytical solution. This is may not be relevant to the current question, but my original problem is to solve a similar PDE where the source is very complex and does not allow an analytical solution. Therefore, I hope I can have a BC that does not require me to guess the form of the solution. –  wdg Apr 7 '13 at 7:51
add comment

2 Answers

up vote 4 down vote accepted

Another way that works on this kind of problems is to impose the BC/ΙC on the characteristics. For this problem the characteristics are $$t+x/2=c$$ so by making the change of variables: $$ \xi=t+x/2,\, \eta=t $$

the PDE becomes (if I am correctly) $$ u_\eta=e^{-(-1+\eta )^2-(5+2 \eta -2 \xi )^2} $$ for this kind of equation I need just one condition, an initial one:

solalt=NDSolve[{D[y[\[Xi], \[Eta]], \[Eta]] == E^(-(-1 + \[Eta])^2 - (5 + 2 \[Eta] - 2 \[Xi])^2), y[\[Xi], 0] == 1}, y, {\[Xi], -5, 20}, {\[Eta], 0, 15}][[1,1]];
Plot3D[Evaluate[y[t + x/2, t] /. solalt], {x, -10, 10}, {t, 0, 15}, PlotRange -> All]

enter image description here

A little care must be given for the domains $(\xi,\eta)$ but its trivial to find it.

share|improve this answer
    
Your solution is neat. –  wdg Apr 7 '13 at 13:07
add comment

A smaller MaxStepSize(say 0.2) and one boundary condition will help:

sol2 = NDSolve[{D[y[x, t], t] - 2 D[y[x, t], x] == Exp[-(t - 1)^2 - (x - 5)^2], 
                y[x, 0] == 0, y[10, t] == 0}, 
                y, {x, -10, 10}, {t, 0, 15}, MaxStepSize -> 0.2]
Plot3D[y[x, t] /. sol2, {x, -10, 10}, {t, 0, 15}, PlotRange -> All]

enter image description here

Here I only retain the BC f[10, t] == 0 because it's relatively acceptable though approximate, while f[-10, t] == 0 is redundant and unreasonable: the source (Exp[-(t - 1)^2 - (x - 5)^2]) is still strong when x is around -10, I think it's not so hard to imagine the physical situation.

Well, personally I feel this example interesting, because it's the first time I see that DSolve works better than NDSolve 囧. In fact, a small MaxStepSize is still necessary even when we use a "exact" boundary:

eqn = D[y[x, t], t] - 2 D[y[x, t], x] == Exp[-(t - 1)^2 - (x - 5)^2];
ic = y[x, 0] == 0;
sol1 = DSolve[{eqn, ic}, y, {x, t}];

bc = (y[10, t] /. First@sol1) == y[10, t];

sol3 = NDSolve[{eqn, ic, bc}, y, {x, -10, 10}, {t, 0, 15}];
Plot3D[y[x, t] /. sol3, {x, -10, 10}, {t, 0, 15}, PlotRange -> All]

sol4 = NDSolve[{eqn, ic, bc}, y, {x, -10, 10}, {t, 0, 15}, MaxStepSize -> 0.2];
Plot3D[y[x, t] /. sol4, {x, -10, 10}, {t, 0, 15}, PlotRange -> All]

sol3

NDSolve::eerr: Warning: Scaled local spatial error estimate of 86.42948528609735` at x = -10. in the direction of independent variable t is much greater than prescribed error tolerance. Grid spacing with 25 points may be too large to achieve the desired accuracy or precision. A singularity may have formed or you may want to specify a smaller grid spacing using the MaxStepSize or MinPoints method options. >>

enter image description here

sol4

enter image description here

share|improve this answer
    
actually this works because we are dealing with numerics, if one evaluates the exact solution around f[10,-2.8]~-0.1! –  Spawn1701D Apr 7 '13 at 7:14
    
@Spawn1701D Yeah, f[10, t]==0 is still approximate, but I think for numeric solution it's acceptable, since it's hard to find a better BC… For this part I've edited my answer a little. –  xzczd Apr 7 '13 at 7:38
    
For these kind of problems is better to take the condition along the characteristic of the PDE something that doesn't seem to work well with NDSolve. –  Spawn1701D Apr 7 '13 at 7:54
    
Deriving the BCs from the analytic solution is not that useful. Imposing f[10, t] == 0 only is more useful, and is good enough for transport equation. If there is a diffusion term (irrelevant to this question though), we would then need BCs that are more sophisticated. –  wdg Apr 7 '13 at 13:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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