0

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.

user3116936
  • 103
  • 2

1 Answers1

3

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

Greg Hurst
  • 35,921
  • 1
  • 90
  • 136