Message Boards Message Boards

Trapezoidal method for NDSolve?

Posted 6 months ago

May I ask if Mathematica provides a trapezoidal method instruction for solving differential equations? I checked the reference materials and for NDSolve, it seems that only explicit Euler, implicit Euler, midpoint method, etc. are provided, but it seems that the trapezoidal method is not provided...

POSTED BY: James James
Posted 6 months ago

For Heun's order-2 method (a.k.a. "explicit trapeziodal"), that is the order-2 "ExplicitRungeKutta" method (which has an embedded error estimator):

Method -> {"ExplicitRungeKutta", "DifferenceOrder" -> 2}

NDSolve`EmbeddedExplicitRungeKuttaCoefficients[2, MachinePrecision] will show the $a$, $b$, $c$, $b_{err}$ matrix/vectors of the Butcher table if you want to check. The last vector $b_{err}$ is for estimating the error.

Alternatively, you can code your own Butcher tableau and plug it in:

explicitTrapezoidalCoefficients // ClearAll;
explicitTrapezoidalCoefficients[2, wp_, caller___] := 
  N[{{{1}}, {1/2, 1/2}, {1}}, wp];
explicitTrapezoidal = {"ExplicitRungeKutta", 
   "Coefficients" -> explicitTrapezoidalCoefficients, 
   "DifferenceOrder" -> 2};

Method -> explicitTrapezoidal

For the implicit trapezoidal method, you can use

Method -> {"ImplicitRungeKutta", 
      "Coefficients" -> "ImplicitRungeKuttaLobattoIIIACoefficients", 
      "DifferenceOrder" -> 2}

NDSolve`ImplicitRungeKuttaLobattoIIIACoefficients[2, MachinePrecision] will give the a, b, c matrx/vectors of the Butcher table, if you want to check.

Alternatively, the Crank-Nicholson method (a.k.a. "implicit trapezoidal") is coded up in the tutorial https://reference.wolfram.com/language/tutorial/NDSolvePlugIns.html#1708771088

POSTED BY: Updating Name
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract