Message Boards Message Boards

10 Replies
6 Total Likes
View groups...
Share this post:

What is the default rule of Integration for Mathematica?

Posted 9 years ago

Hello all,

I was using RungeKutta 4th Order Method for my equation. So, if I just integrate without specifying the rule or method, what is the default rule that Mathematica use?

POSTED BY: Thai Kee Gan
10 Replies
Posted 9 years ago

Thank you Michael Rogers, this have given me an idea of how the integration works.

It's just that, for integrations without using Mathematica, we would use Simpson's Rules or Trapeziodal rule for integration for numerical integration, to obtain the value for the initial value before it. But in Mathematica without numerical integration, the InterpolatingFunction only show a graph or a plot (without any polynomials shown). Well I did obtain an accurate value for the integration of the InterpolatingFunction.

There's the set of rules in Mathematica for integration. So, now I need to know which is the correct integration rule that is default for Mathematica.


I believe Mathematica automatic chooses the rule for the Integration, so what command do I need to type to find out which method it used?

POSTED BY: Thai Kee Gan

No problem.

Here are the steps I have in mind:

  1. NDSolve produces y -> InterpolatingFunction[..]. The InterpolatingFunction will be order 3. Order 3 means the interpolation consists of piecewise degree-3 polynomials that interpolate between the steps of the solution computed by NDSolve.

  2. If you integrate the solution with intsol = Integrate[y[x] /. First[sol], x], where sol = NDSolve[..] is the solution, then intsol, the value of the result of Integrate, will be of the form InterpolatingFunction[..][x], where the interpolating function is an order-4 interpolation, which consists of piecewise degree-4 polynomials that are the integrals of the degree-3 polynomials in the solution.

There is no second application of Integrate that I have in mind. If you want to use Integrate twice, then the order increases by one at each step.

By "the appropriate initial conditions", I mean on each subinterval ${(x_{j-1}, x_j)}$, Integrate performs the integral

$$I_{j-1} + \int_{x_{j-i}}^x p_j(t) \; dt$$

where the initial value $I_{j-1}$ is the accumulation the integrals over the preceding intervals..

POSTED BY: Michael Rogers
Posted 9 years ago

I apologize if I misunderstand some points.

The first integration will be the of the piecewise polynomial equation. Then produces InterpolatingFunction, which is also a symbolic function. I am able to obtain the numerical value with the options given, from the option "Evaluate at point 3"

Then the InterpolatingFunction is an order-4 InterpolatingFunction?, the integration will be an order-5?

The Integration of the InterpolatingFunction is use to find the area under the graph for the InterpolatingFunction, which was similar to Simpson's Rule or Riemann Integral or others.

Or do you mean "Integrate integrates the polynomials symbolically and evaluates them at the endpoints of their subintervals; ", it follows the 4th Order RungeKutta Method and the subintervals is also 1/100?

Sorry if I seems to behave not professional with all these questions.

POSTED BY: Thai Kee Gan

Integrate integrates the polynomials symbolically and evaluates them at the endpoints of their subintervals; the result of integrating a standard order-3 InterpolatingFunction will be an order-4 InterpolatingFunction, with the degree-4 polynomials being the integrals of the degree-3 polynomials satisfying the appropriate initial conditions. It does not use a numerical method at all.

POSTED BY: Michael Rogers
Posted 9 years ago

Yes, Michael Rogers, that is what I did. I cannot find the function for integrate the InterpolatingFunction, so I just copy the command give by the "Automatic Options". I'm able to find the area under the graph of the InterpolatingFunction, but unable to choose specific method or rule. My predecessor used the Simpson's Rule for the rules of definite integrals. So, now I need to know which rule that Mathematica choose from the rules of definite integrals (there's quiet a few, searched in Wikipedia).

POSTED BY: Thai Kee Gan

If I understand what you did, Integrate, the symbolic integrator, was applied to the InterpolatingFunction. The interpolating function is basically a piecewise polynomial function (defined by data computed by NDSolve). Integrate effectively integrates each polynomial using the power rule and the rules of definite integrals, returning a function f such that f[x] equals the integral of the solution from the beginning of the domain up to x. It does not use numerical techniques.

POSTED BY: Michael Rogers
Posted 9 years ago

Sorry for the confusion, here's what I did. I NDSolve the equation with 4th Order RungeKutta Method

 In[37]:= z = 1
    ClassicalRungeKuttaCoefficients[4, prec_] := 
     With[{amat = {{1/2}, {0, 1/2}, {0, 0, 1}}, 
       bvec = {1/6, 1/3, 1/3, 1/6}, cvec = {1/2, 1/2, 1}}, 
      N[{amat, bvec, cvec}, prec]]
    NDSolve[{Derivative[1][y][x] == Piecewise[{{(y[x] + x^2 + z),
          0 <= x <= 1},

     {(y[x] + x^2 + 2 z),
      1 <= x <= 2},

     {(y[x] + x^2 + 3 z),
      2 <= x <= 3}}]
  , y[0] == 0.0}, y, {x, 0.`, 3`}, 
 Method -> {"ExplicitRungeKutta", "DifferenceOrder" -> 4, 
   "Coefficients" -> ClassicalRungeKuttaCoefficients}, 
 "StartingStepSize" -> 1/100]

Out[37]= 1

Out[39]= {{y -> InterpolatingFunction[{{0., 3.}}, <>]}}

Then I chose the option "Get Solution"

In[40]:= %39[[1, 1, 2]]

Out[40]= InterpolatingFunction[{{0., 3.}}, <>]

After that, there's another option, "Integrate", that's where the new integration result show up. The thing is, the code in the notebook and posted here is different. I would like to know does this new integration chose the previous integration method done, the 4th Order RungeKutta Method? or Mathematica chose another method?

RowBox[{"-", "1"}], ")"}],

Out[41]= InterpolatingFunction[{{0., 3.}}, <>][#1] &

enter image description here

POSTED BY: Thai Kee Gan

I'm not sure I understand your code or what (1) and (2) above means.

So, what is the automatic default rule for this integration? From the manual, there's "Trapezoidal Rule", "Multipanel Rule" and so on. How do I know which rule that Mathematica chose?

Sometimes there's a way to tell which numerical method Mathematica used by using a trace of some kind. Usually there isn't. The method chosen might be a mixture of multiple methods or could even be a method not documented. It could be anything. If you don't specify a value for the "Method" option, the function is free to do whatever it wants to try and solve your problem. It doesn't try to communicate what it did to solve it - often what it did isn't straightforward enough anyway.

If you want to try to examine the output of the function, you can sometimes determine what numerical method was used, although I don't recommend it.

POSTED BY: Sean Clarke
Posted 9 years ago

Here's what I have done,

1) I try used f = NDSolve specified using RungeKutta 4th Order Method. 2) There's an option that have option to integrate "f" for me and I just chose the option to integrate again.

\!\(\*SuperscriptBox[\(f[\([\)\(1, 1, 2\)\(]\)]\), 
RowBox[{"-", "1"}], ")"}],

Then I obtain the answer for "f" integrated another time.

So, what is the automatic default rule for this integration? From the manual, there's "Trapezoidal Rule", "Multipanel Rule" and so on. How do I know which rule that Mathematica chose?

POSTED BY: Thai Kee Gan

The default is a complicated set of rules and heuristics that picks a numerical method. This is basically true for any function which has a "Method" option.

NDSolve tries hard to pick the best numerical method for the problem you give it. It's always good to try running NDSolve with different numerical methods.

POSTED BY: Sean Clarke
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract