# Best NDSolve Methods for this equation?

**URL:** <https://community.wolfram.com/t/best-ndsolve-methods-for-this-equation/9738>\
**Category:** Questions\
**Tags:** physics, calculus, equation-solving, numerical-computation\
**Created:** [December 10, 2016, 12:43pm UTC](https://community.wolfram.com/t/best-ndsolve-methods-for-this-equation/9738 "2016-12-10T12:43:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fernandogarciarubio](https://avatars.discourse-cdn.com/v4/letter/f/4af34b/32.png) [@fernandogarciarubio](https://community.wolfram.com/u/fernandogarciarubio)\
**Post date:** [December 10, 2016, 12:43pm UTC](https://community.wolfram.com/t/best-ndsolve-methods-for-this-equation/9738/1 "2016-12-10T12:43:55Z")

</div>

Hello everybody!

First, thank you for reading this post.

I am a Ph.D. student in plasma physics, and I am struggling with numerically solving a set of equations. After some thoughts, I basically detected that the problem in my solution arises from my inability to choose good NDSolve methods to solve an inherently unstable equation of the type:

dy/dt = - d^2y/dx^2,

With initial condition y(x,0) = sin(x), and boundary conditions y(0,t) = 0, y(Pi,t) = 0.

The analytical solution is y(x,t) = Exp(t)Sin(x), but I failed to compute it numerically. An example:

```
solpru = NDSolve[{D[y[x, t], t] == - D[D[y[x, t], x], x], 
    y[0, t] == Sin[0], y[Pi, t] == Sin[Pi], y[x, 0] == Sin[x]}, 
   y, {x, 0, Pi}, {t, 0, 1}, Method -> {
     "PDEDiscretization" -> {"MethodOfLines", 
       "SpatialDiscretization" -> {"TensorProductGrid"}}}];
ys[x_,t_] := Evaluate[y[x,t] /. solpru];
Plot[{ys[x, 0], ys[x, 1]}, {x, 0, Pi}, PlotRange -> All]

```

I have tried with different Mehtods (“TimeIntegration”, “PDEDiscretization”), but none of them gave me a proper result, all of them induced numerical instabilities.

Please can someone shed some light on this problem? Which would the best Method options be for this type of “exploding” equation?

Thank you very much

---

<div class="post-metadata">

**Author:** ![mariuszi28cg](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/mariuszi28cg/32/308_2.png) [@mariuszi28cg](https://community.wolfram.com/u/mariuszi28cg)\
**Post date:** [December 10, 2016, 1:17pm UTC](https://community.wolfram.com/t/best-ndsolve-methods-for-this-equation/9738/2 "2016-12-10T13:17:23Z")

</div>

Hey.  
First ,I don’t know the best Method options for this type,but this code below works:

```
ppR = 20;
solpru = NDSolve[{D[y[x, t], t] == -D[D[y[x, t], x], x], 
    y[0, t] == Sin[0], y[Pi, t] == Sin[Pi], y[x, 0] == Sin[x]}, 
   y, {x, 0, Pi}, {t, 0, 1}, MaxSteps -> Infinity, PrecisionGoal -> 1,
    AccuracyGoal -> 1, 
   Method -> {"MethodOfLines", 
     "SpatialDiscretization" -> {"TensorProductGrid", 
       "MinPoints" -> ppR, "MaxPoints" -> ppR, 
       "DifferenceOrder" -> 1}, 
     Method -> {"ExplicitEuler", "MaxDifferenceOrder" -> 4}}];
ys[x_, t_] := Evaluate[y[x, t] /. solpru];
Plot[{ys[x, 0], ys[x, 1/2], ys[x, 3/4], ys[x, 1]}, {x, 0, Pi}, 
 PlotRange -> All]

```

 ![10663Bez tytułu.png](https://global.discourse-cdn.com/wolfram/original/3X/2/0/202bbba5761e7be58254f14dd9c12087fd7f0599.png)

See another code:

```
ppR = 50;
solpru = NDSolve[{D[y[x, t], t] == -D[D[y[x, t], x], x], 
    y[0, t] == Sin[0], y[Pi, t] == Sin[Pi], y[x, 0] == Sin[x]}, 
   y, {x, 0, Pi}, {t, 0, 1}, MaxSteps -> Infinity, PrecisionGoal -> 1,
    AccuracyGoal -> 1, 
   Method -> {"MethodOfLines", 
     "SpatialDiscretization" -> {"TensorProductGrid", 
       "MinPoints" -> ppR, "MaxPoints" -> ppR, 
       "DifferenceOrder" -> 1}, 
     Method -> {"ImplicitRungeKutta", "DifferenceOrder" -> 2}}];
ys[x_, t_] := Evaluate[y[x, t] /. solpru];
Plot[{ys[x, 0], ys[x, 1/2], ys[x, 3/4], ys[x, 1]}, {x, 0, Pi}, 
 PlotRange -> All]

```

---

<div class="post-metadata">

**Author:** ![etm](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/etm/32/8360_2.png) [@etm](https://community.wolfram.com/u/etm)\
**Post date:** [December 11, 2016, 12:43am UTC](https://community.wolfram.com/t/best-ndsolve-methods-for-this-equation/9738/3 "2016-12-11T00:43:10Z")

</div>

This works pretty well. Numeric …

```
solpru = NDSolve[{D[y[x, t], t] == -D[D[y[x, t], x], x], 
    y[0, t] == Sin[0], y[Pi, t] == Sin[Pi], y[x, 0] == Sin[x]}, 
   y, {x, 0, Pi}, {t, 0, 1}, MaxSteps -> Infinity, PrecisionGoal -> 3,
    AccuracyGoal -> 8, 
   Method -> {"MethodOfLines", 
     "SpatialDiscretization" -> "FiniteElement"}];

    Plot3D[Evaluate[y[x, t] /. solpru], {x, 0, Pi}, {t, 0, 1}]

```

 ![analytical.png](https://global.discourse-cdn.com/wolfram/original/2X/7/721e3e6dab326e7a11c4fcd818b94a40b11ece25.png)

Analytical

```
sol2 = DSolve[{D[y[x, t], t] == -D[y[x, t], {x, 2}], 
y[0, t] == Sin[0], y[Pi, t] == Sin[Pi], y[x, 0] == Sin[x]}, 
y, {x, 0, Pi}, {t, 0, 1}]

```

{{y → Function[{x, t}, E^t Sin[x]]}}

 ![numeric.png](https://global.discourse-cdn.com/wolfram/original/3X/d/4/d41d0158202d7cadf20e0a099544fe62b74b0e90.png)

---

<div class="post-metadata">

**Author:** ![fernandogarciarubio](https://avatars.discourse-cdn.com/v4/letter/f/4af34b/32.png) [@fernandogarciarubio](https://community.wolfram.com/u/fernandogarciarubio)\
**Post date:** [December 12, 2016, 12:30pm UTC](https://community.wolfram.com/t/best-ndsolve-methods-for-this-equation/9738/4 "2016-12-12T12:30:30Z")

</div>

Thank you very much!

I see that the key point here is to lower the requirements on precision and accurary goals.

Comparing with the analytic solution, it turns out that the integration with the Implicit Runge Kutta is better than the Explicit Euler.

Best,

Fernando

---

<div class="post-metadata">

**Author:** ![fernandogarciarubio](https://avatars.discourse-cdn.com/v4/letter/f/4af34b/32.png) [@fernandogarciarubio](https://community.wolfram.com/u/fernandogarciarubio)\
**Post date:** [December 12, 2016, 12:33pm UTC](https://community.wolfram.com/t/best-ndsolve-methods-for-this-equation/9738/5 "2016-12-12T12:33:23Z")

</div>

Thank you very much.

The discretization using Finite Elements work for this case. However, I have noticed that the FiniteElement discretization apparently does not work when the coefficients of the equation are not polynomials of the unknowns. For example:

dy/dt = -1/(1+y) d^2 y/dx^2.

Would you know how to overcome this problem?

Thank you!
