# Use Inactive for Debugging a Program

By activating parts of a program in stages, Inactive can assist the debugging process.

The following program contains an error.

 In[1]:= Xa = 5.321122356674; b = -4.61014535141467; c = 0.214828315564808; d = 10.34234234234; min = -100; max = 100; kernel[x_, 1] := Exp[-(b - x)^2/c^2] kernel[x_, 2] := Max[Abs[b/c] - Abs[(b - x)/c], 0] firstInt[f_, x_, i_] := NIntegrate[d*kernel[x/a]*f, {x, min, max}] myInt[f_, x_, i_] := NIntegrate[f *firstInt[f, x, i], {x, min, max}]

Multiple messages are produced, and the integral returns unevaluated.

 In[2]:= XmyInt[x^2 + 3 x + 7, x, 1]
 Out[2]=

Create an inactive version of the program.

 In[3]:= XdebugInt[f_, x_, i_] := Inactivate[NIntegrate[f *firstInt[f, x, i], {x, min, max}]]
 In[4]:= XdebugInt[7 + 3 x + x^2, x, 1]
 Out[4]=

Everything looks fine, so try activating the function .

 In[5]:= XActivate[debugInt[7 + 3 x + x^2, x, 1], firstInt]
 Out[5]=

A message is produced, and the inner NIntegrate shows failed to evaluateit is missing its second argument. Correct the definition.

 In[6]:= XfirstInt[f_, x_, i_] := NIntegrate[kernel[x/a, i]*f, {x, min, max}]

Now evaluation proceeds correctly.

 In[7]:= XmyInt[x^2 + 3 x + 7, x, 1]
 Out[7]=
 In[8]:= XmyInt[x^2 + 3 x + 7, x, 2]
 Out[8]=

## Mathematica

Questions? Comments? Contact a Wolfram expert »