0
$\begingroup$

Is possible to extend this answer in order to perform definite integrals in two dimensions step-by-step?

OK, In response to the comment, I did a try and I have by now the following:

 showDefiniteIntegral2D[
  integrand_, {x_, xMin_, xMax_}, {y_, yMin_, yMax_}, 
  form_: StandardForm] := 
 Module[{a, replaceA = "", 
    antiDerivative = Integrate[integrand, x, y]}, 
   Row[{HoldForm[
      Integrate[integrand, {x, xMin, xMax}, {y, yMin, yMax}]], " = ", 
     Subsuperscript[
      DisplayForm[
       If[Head[antiDerivative] === Plus, 
        RowBox[{StyleBox["[", SpanMinSize -> 2], 
          ToBoxes[antiDerivative, form], 
          StyleBox["]", SpanMinSize -> 2]}], 
        RowBox[{ToBoxes[antiDerivative, form], 
          StyleBox["\[RightBracketingBar]", SpanMinSize -> 2]}]]], 
      {xMin,yMin},{xMax,yMax}], " = ", 
     Subtract @@ (antiDerivative /. {x -> {xMax, xMin}, 
         y -> {yMax, yMin}})}]] 

I think that the former approach could work,but any suggestion for improvement is welcome.

$\endgroup$
6
  • $\begingroup$ Perhaps you could try something on your own and report back when you run into trouble? $\endgroup$
    – MarcoB
    Commented Feb 3, 2017 at 22:02
  • $\begingroup$ The problem is that I don't know how to get started in the right direction. $\endgroup$ Commented Feb 3, 2017 at 22:04
  • $\begingroup$ How can I post Mathematica code dysplaying properly? $\endgroup$ Commented Feb 3, 2017 at 22:15
  • $\begingroup$ I guess if you did it by hand you would treat one integration variable at a time wouldn't you? $\endgroup$
    – george2079
    Commented Feb 3, 2017 at 22:45
  • 1
    $\begingroup$ But you'd probably have the gaussian integral as a special case. Another special case is where the integrals are separable. $\endgroup$
    – Jason B.
    Commented Feb 3, 2017 at 23:56

1 Answer 1

3
$\begingroup$

You can always just compute the integrals in a nested fashion.

Disclaimer: This will not always work! We need to ensure continuity of the inner integral to apply the fundamental theorem of calculus. See here for more details.


Here's a quick mock up of how to do this, calling Wolfram Alpha to get the steps each time:

IntegralSteps[expr_, {x_, a_, b_}, {y_, c_, d_}] :=
  Module[{inner, outer, innersteps, outersteps},
    inner = Integrate[expr, {x, a, b}];
    outer = Integrate[inner, {y, c, d}];

    innersteps = IntegralSteps[expr, {x, a, b}];
    outersteps = IntegralSteps[inner, {y, c, d}];

    TraditionalForm @ Grid[List /@ {
        Style["Compute the integral:", Gray],
        HoldForm[Integrate[expr, {x, a, b}, {y, c, d}]],
        Style["First, compute the inner integral:", Gray],
        Row[{HoldForm[Integrate[expr, {x, a, b}]] == inner, PopupWindow[Button["Show steps"], innersteps]}, Spacer[10]],
        Style["Substitute the result:", Gray],
        HoldForm[Integrate[expr, {x, a, b}, {y, c, d}] == Integrate[#, {y, c, d}]]&[inner],
        Style["Compute the next integral:", Gray],
        Row[{HoldForm[Integrate[#, {y, c, d}]]&[inner] == outer, PopupWindow[Button["Show steps"], outersteps]}, Spacer[10]],
        Style["Summarize:", Gray],
        HoldForm[Integrate[expr, {x, a, b}, {y, c, d}]] == outer
    }, 
    Alignment -> Left, 
    Dividers -> {{}, {False,{False,Gray},False}}, 
    Spacings -> {{}, {Automatic, {Automatic, 3}}}
    ] /. i_Integrate :> Style[i, ScriptLevel -> 0]
  ]

IntegralSteps[expr_, {x_, a_, b_}] :=
  IntegralSteps[ToString[Unevaluated[Integrate[expr, {x, a, b}]], InputForm]]

IntegralSteps[str_String] := 
  WolframAlpha[str,{{"Input",2},"Content"},PodStates->{"Input__Step-by-step solution"}]

One could extend this code to work for an $nD$ integral.

Here's a GIF of it in action:

IntegralSteps[x y, {x, 0, 1}, {y, 0, 1}]

enter image description here

$\endgroup$
2
  • $\begingroup$ Unfortunately, I am using Mathematica 9 and by some reason the pop-up menu that display the steps is not working. Thanks a lot for answer. $\endgroup$ Commented Feb 4, 2017 at 3:20
  • $\begingroup$ @user3116936 Hmm, I just tried it in Mathematica 9 and it worked fine for me. $\endgroup$
    – Greg Hurst
    Commented Feb 4, 2017 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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