Why is the Numerical Integration Resulting in Zero for a Non-Zero Function?

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
16 replies · 2K views
member 428835
Hi PF!

The following function is long but only 3 command lines: first defines the function ff, second numerically integrates the function, and third plots the function. As you'll see the integral is zero yet clearly that is not the case (seen from the plot). Any idea what's happening?

Code:
ff = 0.5606761981314476` ((-0.1367788536270296` +
        0.22165442361786794` Cos[\[Theta]] -
        0.0433321923224954` Cos[2 \[Theta]] -
        0.041543377668342985` Cos[3 \[Theta]] +
        0.9284408543946542` Sin[\[Theta]] -
        0.14311113535576353` Sin[2 \[Theta]] -
        0.21464881411190453` Sin[
          3 \[Theta]]) UnitStep[-0.01` + \[Theta]] -
     0.054429237999962535` (-0.495726932278196` -
        0.17369695482741626` Cos[\[Theta]] +
        0.8347194334290977` Cos[2 \[Theta]] -
        0.16529554632348553` Cos[3 \[Theta]] +
        0.0005992450328750604` Sin[\[Theta]] +
        0.0011984301417462028` Sin[2 \[Theta]] +
        0.0017974954086018597` Sin[
          3 \[Theta]]) UnitStep[-0.01` + \[Theta]] -
     0.04525014706857046` (-0.19590701566884333` (-0.495726932278196` \
- 0.17369695482741626` Cos[\[Theta]] +
           0.8347194334290977` Cos[2 \[Theta]] -
           0.16529554632348553` Cos[3 \[Theta]] +
           0.0005992450328750604` Sin[\[Theta]] +
           0.0011984301417462028` Sin[2 \[Theta]] +
           0.0017974954086018597` Sin[
             3 \[Theta]]) UnitStep[-0.01` + \[Theta]] + \
(-0.4923077743819351` - 0.1792378074713546` Cos[\[Theta]] -
           0.16419736106352353` Cos[2 \[Theta]] +
           0.8357429429168132` Cos[3 \[Theta]] +
           0.002388059687027475` Sin[\[Theta]] +
           0.004775880570076289` Sin[2 \[Theta]] +
           0.007163223869047984` Sin[
             3 \[Theta]]) UnitStep[-0.01` + \[Theta]])) \
(0.5606761981314476` (( \!\(\*
TagBox[GridBox[{
{"\[Piecewise]", GridBox[{
{"Indeterminate",
RowBox[{"\[Theta]", "==", "0.01`"}]},
{"0",
TagBox["True",
"PiecewiseDefault",
AutoDelete->True]}
},
AllowedDimensions->{2, Automatic},
Editable->True,
GridBoxAlignment->{
                  "Columns" -> {{Left}}, "ColumnsIndexed" -> {},
                   "Rows" -> {{Baseline}}, "RowsIndexed" -> {},
                   "Items" -> {}, "ItemsIndexed" -> {}},
GridBoxItemSize->{
                  "Columns" -> {{Automatic}}, "ColumnsIndexed" -> {},
                   "Rows" -> {{1.}}, "RowsIndexed" -> {},
                   "Items" -> {}, "ItemsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.84]},
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]},
Offset[0.2]}, "RowsIndexed" -> {}, "Items" -> {},
                   "ItemsIndexed" -> {}},
Selectable->True]}
},
GridBoxAlignment->{
               "Columns" -> {{Left}}, "ColumnsIndexed" -> {},
                "Rows" -> {{Baseline}}, "RowsIndexed" -> {},
                "Items" -> {}, "ItemsIndexed" -> {}},
GridBoxItemSize->{
               "Columns" -> {{Automatic}}, "ColumnsIndexed" -> {},
                "Rows" -> {{1.}}, "RowsIndexed" -> {}, "Items" -> {},
                "ItemsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.35]},
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]},
Offset[0.2]}, "RowsIndexed" -> {}, "Items" -> {},
                "ItemsIndexed" -> {}}],
"Piecewise",
DeleteWithContents->True,
Editable->False,
SelectWithContents->True,
Selectable->False]\) ) (-0.1367788536270296` +
           0.22165442361786794` Cos[\[Theta]] -
           0.0433321923224954` Cos[2 \[Theta]] -
           0.041543377668342985` Cos[3 \[Theta]] +
           0.9284408543946542` Sin[\[Theta]] -
           0.14311113535576353` Sin[2 \[Theta]] -
           0.21464881411190453` Sin[3 \[Theta]]) -
        0.054429237999962535` ( \!\(\*
TagBox[GridBox[{
{"\[Piecewise]", GridBox[{
{"Indeterminate",
RowBox[{"\[Theta]", "==", "0.01`"}]},
{"0",
TagBox["True",
"PiecewiseDefault",
AutoDelete->True]}
},
AllowedDimensions->{2, Automatic},
Editable->True,
GridBoxAlignment->{
                  "Columns" -> {{Left}}, "ColumnsIndexed" -> {},
                   "Rows" -> {{Baseline}}, "RowsIndexed" -> {},
                   "Items" -> {}, "ItemsIndexed" -> {}},
GridBoxItemSize->{
                  "Columns" -> {{Automatic}}, "ColumnsIndexed" -> {},
                   "Rows" -> {{1.}}, "RowsIndexed" -> {},
                   "Items" -> {}, "ItemsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.84]},
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]},
Offset[0.2]}, "RowsIndexed" -> {}, "Items" -> {},
                   "ItemsIndexed" -> {}},
Selectable->True]}
},
GridBoxAlignment->{
               "Columns" -> {{Left}}, "ColumnsIndexed" -> {},
                "Rows" -> {{Baseline}}, "RowsIndexed" -> {},
                "Items" -> {}, "ItemsIndexed" -> {}},
GridBoxItemSize->{
               "Columns" -> {{Automatic}}, "ColumnsIndexed" -> {},
                "Rows" -> {{1.}}, "RowsIndexed" -> {}, "Items" -> {},
                "ItemsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.35]},
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]},
Offset[0.2]}, "RowsIndexed" -> {}, "Items" -> {},
                "ItemsIndexed" -> {}}],
"Piecewise",
DeleteWithContents->True,
Editable->False,
SelectWithContents->True,
Selectable->False]\) ) (-0.495726932278196` -
           0.17369695482741626` Cos[\[Theta]] +
           0.8347194334290977` Cos[2 \[Theta]] -
           0.16529554632348553` Cos[3 \[Theta]] +
           0.0005992450328750604` Sin[\[Theta]] +
           0.0011984301417462028` Sin[2 \[Theta]] +
           0.0017974954086018597` Sin[3 \[Theta]]) + 2 ( \!\(\*
TagBox[GridBox[{
{"\[Piecewise]", GridBox[{
{"Indeterminate",
RowBox[{
RowBox[{
RowBox[{"-", "0.01`"}], "+", "\[Theta]"}], "==", "0"}]},
{"0",
TagBox["True",
"PiecewiseDefault",
AutoDelete->True]}
},
AllowedDimensions->{2, Automatic},
Editable->True,
GridBoxAlignment->{
                  "Columns" -> {{Left}}, "ColumnsIndexed" -> {},
                   "Rows" -> {{Baseline}}, "RowsIndexed" -> {},
                   "Items" -> {}, "ItemsIndexed" -> {}},
GridBoxItemSize->{
                  "Columns" -> {{Automatic}}, "ColumnsIndexed" -> {},
                   "Rows" -> {{1.}}, "RowsIndexed" -> {},
                   "Items" -> {}, "ItemsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.84]},
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]},
Offset[0.2]}, "RowsIndexed" -> {}, "Items" -> {},
                   "ItemsIndexed" -> {}},
Selectable->True]}
},
GridBoxAlignment->{
               "Columns" -> {{Left}}, "ColumnsIndexed" -> {},
                "Rows" -> {{Baseline}}, "RowsIndexed" -> {},
                "Items" -> {}, "ItemsIndexed" -> {}},
GridBoxItemSize->{
               "Columns" -> {{Automatic}}, "ColumnsIndexed" -> {},
                "Rows" -> {{1.}}, "RowsIndexed" -> {}, "Items" -> {},
                "ItemsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.35]},
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]},
Offset[0.2]}, "RowsIndexed" -> {}, "Items" -> {},
                "ItemsIndexed" -> {}}],
"Piecewise",
DeleteWithContents->True,
Editable->False,
SelectWithContents->True,
Selectable->False]\) ) (0.9284408543946542` Cos[\[Theta]] -
           0.28622227071152706` Cos[2 \[Theta]] -
           0.6439464423357136` Cos[3 \[Theta]] -
           0.22165442361786794` Sin[\[Theta]] +
           0.0866643846449908` Sin[2 \[Theta]] +
           0.12463013300502895` Sin[3 \[Theta]]) -
        0.10885847599992507` ( \!\(\*
TagBox[GridBox[{
{"\[Piecewise]", GridBox[{
{"Indeterminate",
RowBox[{
RowBox[{
RowBox[{"-", "0.01`"}], "+", "\[Theta]"}], "==", "0"}]},
{"0",
TagBox["True",
"PiecewiseDefault",
AutoDelete->True]}
},
AllowedDimensions->{2, Automatic},
Editable->True,
GridBoxAlignment->{
                  "Columns" -> {{Left}}, "ColumnsIndexed" -> {},
                   "Rows" -> {{Baseline}}, "RowsIndexed" -> {},
                   "Items" -> {}, "ItemsIndexed" -> {}},
GridBoxItemSize->{
                  "Columns" -> {{Automatic}}, "ColumnsIndexed" -> {},
                   "Rows" -> {{1.}}, "RowsIndexed" -> {},
                   "Items" -> {}, "ItemsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.84]},
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]},
Offset[0.2]}, "RowsIndexed" -> {}, "Items" -> {},
                   "ItemsIndexed" -> {}},
Selectable->True]}
},
GridBoxAlignment->{
               "Columns" -> {{Left}}, "ColumnsIndexed" -> {},
                "Rows" -> {{Baseline}}, "RowsIndexed" -> {},
                "Items" -> {}, "ItemsIndexed" -> {}},
GridBoxItemSize->{
               "Columns" -> {{Automatic}}, "ColumnsIndexed" -> {},
                "Rows" -> {{1.}}, "RowsIndexed" -> {}, "Items" -> {},
                "ItemsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.35]},
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]},
Offset[0.2]}, "RowsIndexed" -> {}, "Items" -> {},
                "ItemsIndexed" -> {}}],
"Piecewise",
DeleteWithContents->True,
Editable->False,
SelectWithContents->True,
Selectable->False]\) ) (0.0005992450328750604` Cos[\[Theta]] +
           0.0023968602834924056` Cos[2 \[Theta]] +
           0.005392486225805579` Cos[3 \[Theta]] +
           0.17369695482741626` Sin[\[Theta]] -
           1.6694388668581954` Sin[2 \[Theta]] +
           0.4958866389704566` Sin[3 \[Theta]]) -
        0.054429237999962535` (0.17369695482741626` Cos[\[Theta]] -
           3.338877733716391` Cos[2 \[Theta]] +
           1.4876599169113698` Cos[3 \[Theta]] -
           0.0005992450328750604` Sin[\[Theta]] -
           0.004793720566984811` Sin[2 \[Theta]] -
           0.016177458677416736` Sin[
             3 \[Theta]]) UnitStep[-0.01` + \[Theta]] + \
(-0.22165442361786794` Cos[\[Theta]] +
           0.1733287692899816` Cos[2 \[Theta]] +
           0.37389039901508686` Cos[3 \[Theta]] -
           0.9284408543946542` Sin[\[Theta]] +
           0.5724445414230541` Sin[2 \[Theta]] +
           1.9318393270071408` Sin[
             3 \[Theta]]) UnitStep[-0.01` + \[Theta]] -
        0.04525014706857046` (2 ( \!\(\*
TagBox[GridBox[{
{"\[Piecewise]", GridBox[{
{"Indeterminate",
RowBox[{
RowBox[{
RowBox[{"-", "0.01`"}], "+", "\[Theta]"}], "==", "0"}]},
{"0",
TagBox["True",
"PiecewiseDefault",
AutoDelete->True]}
},
AllowedDimensions->{2, Automatic},
Editable->True,
GridBoxAlignment->{
                    "Columns" -> {{Left}}, "ColumnsIndexed" -> {},
                    "Rows" -> {{Baseline}}, "RowsIndexed" -> {},
                    "Items" -> {}, "ItemsIndexed" -> {}},
GridBoxItemSize->{
                    "Columns" -> {{Automatic}},
                    "ColumnsIndexed" -> {}, "Rows" -> {{1.}},
                    "RowsIndexed" -> {}, "Items" -> {},
                    "ItemsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.84]},
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]},
Offset[0.2]}, "RowsIndexed" -> {}, "Items" -> {},
                    "ItemsIndexed" -> {}},
Selectable->True]}
},
GridBoxAlignment->{
                  "Columns" -> {{Left}}, "ColumnsIndexed" -> {},
                   "Rows" -> {{Baseline}}, "RowsIndexed" -> {},
                   "Items" -> {}, "ItemsIndexed" -> {}},
GridBoxItemSize->{
                  "Columns" -> {{Automatic}}, "ColumnsIndexed" -> {},
                   "Rows" -> {{1.}}, "RowsIndexed" -> {},
                   "Items" -> {}, "ItemsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.35]},
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]},
Offset[0.2]}, "RowsIndexed" -> {}, "Items" -> {},
                   "ItemsIndexed" -> {}}],
"Piecewise",
DeleteWithContents->True,
Editable->False,
SelectWithContents->True,
Selectable->False]\) ) (0.002388059687027475` Cos[\[Theta]] +
              0.009551761140152578` Cos[2 \[Theta]] +
              0.021489671607143955` Cos[3 \[Theta]] +
              0.1792378074713546` Sin[\[Theta]] +
              0.32839472212704707` Sin[2 \[Theta]] -
              2.5072288287504394` Sin[3 \[Theta]]) -
           0.19590701566884333` ( \!\(\*
TagBox[GridBox[{
{"\[Piecewise]", GridBox[{
{"Indeterminate",
RowBox[{"\[Theta]", "==", "0.01`"}]},
{"0",
TagBox["True",
"PiecewiseDefault",
AutoDelete->True]}
},
AllowedDimensions->{2, Automatic},
Editable->True,
GridBoxAlignment->{
                    "Columns" -> {{Left}}, "ColumnsIndexed" -> {},
                    "Rows" -> {{Baseline}}, "RowsIndexed" -> {},
                    "Items" -> {}, "ItemsIndexed" -> {}},
GridBoxItemSize->{
                    "Columns" -> {{Automatic}},
                    "ColumnsIndexed" -> {}, "Rows" -> {{1.}},
                    "RowsIndexed" -> {}, "Items" -> {},
                    "ItemsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.84]},
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]},
Offset[0.2]}, "RowsIndexed" -> {}, "Items" -> {},
                    "ItemsIndexed" -> {}},
Selectable->True]}
},
GridBoxAlignment->{
                  "Columns" -> {{Left}}, "ColumnsIndexed" -> {},
                   "Rows" -> {{Baseline}}, "RowsIndexed" -> {},
                   "Items" -> {}, "ItemsIndexed" -> {}},
GridBoxItemSize->{
                  "Columns" -> {{Automatic}}, "ColumnsIndexed" -> {},
                   "Rows" -> {{1.}}, "RowsIndexed" -> {},
                   "Items" -> {}, "ItemsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.35]},
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]},
Offset[0.2]}, "RowsIndexed" -> {}, "Items" -> {},
                   "ItemsIndexed" -> {}}],
"Piecewise",
DeleteWithContents->True,
Editable->False,
SelectWithContents->True,
Selectable->False]\) ) (-0.495726932278196` -
              0.17369695482741626` Cos[\[Theta]] +
              0.8347194334290977` Cos[2 \[Theta]] -
              0.16529554632348553` Cos[3 \[Theta]] +
              0.0005992450328750604` Sin[\[Theta]] +
              0.0011984301417462028` Sin[2 \[Theta]] +
              0.0017974954086018597` Sin[3 \[Theta]]) + ( \!\(\*
TagBox[GridBox[{
{"\[Piecewise]", GridBox[{
{"Indeterminate",
RowBox[{"\[Theta]", "==", "0.01`"}]},
{"0",
TagBox["True",
"PiecewiseDefault",
AutoDelete->True]}
},
AllowedDimensions->{2, Automatic},
Editable->True,
GridBoxAlignment->{
                    "Columns" -> {{Left}}, "ColumnsIndexed" -> {},
                    "Rows" -> {{Baseline}}, "RowsIndexed" -> {},
                    "Items" -> {}, "ItemsIndexed" -> {}},
GridBoxItemSize->{
                    "Columns" -> {{Automatic}},
                    "ColumnsIndexed" -> {}, "Rows" -> {{1.}},
                    "RowsIndexed" -> {}, "Items" -> {},
                    "ItemsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.84]},
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]},
Offset[0.2]}, "RowsIndexed" -> {}, "Items" -> {},
                    "ItemsIndexed" -> {}},
Selectable->True]}
},
GridBoxAlignment->{
                  "Columns" -> {{Left}}, "ColumnsIndexed" -> {},
                   "Rows" -> {{Baseline}}, "RowsIndexed" -> {},
                   "Items" -> {}, "ItemsIndexed" -> {}},
GridBoxItemSize->{
                  "Columns" -> {{Automatic}}, "ColumnsIndexed" -> {},
                   "Rows" -> {{1.}}, "RowsIndexed" -> {},
                   "Items" -> {}, "ItemsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.35]},
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]},
Offset[0.2]}, "RowsIndexed" -> {}, "Items" -> {},
                   "ItemsIndexed" -> {}}],
"Piecewise",
DeleteWithContents->True,
Editable->False,
SelectWithContents->True,
Selectable->False]\) ) (-0.4923077743819351` -
              0.1792378074713546` Cos[\[Theta]] -
              0.16419736106352353` Cos[2 \[Theta]] +
              0.8357429429168132` Cos[3 \[Theta]] +
              0.002388059687027475` Sin[\[Theta]] +
              0.004775880570076289` Sin[2 \[Theta]] +
              0.007163223869047984` Sin[3 \[Theta]]) -
           0.39181403133768666` ( \!\(\*
TagBox[GridBox[{
{"\[Piecewise]", GridBox[{
{"Indeterminate",
RowBox[{
RowBox[{
RowBox[{"-", "0.01`"}], "+", "\[Theta]"}], "==", "0"}]},
{"0",
TagBox["True",
"PiecewiseDefault",
AutoDelete->True]}
},
AllowedDimensions->{2, Automatic},
Editable->True,
GridBoxAlignment->{
                    "Columns" -> {{Left}}, "ColumnsIndexed" -> {},
                    "Rows" -> {{Baseline}}, "RowsIndexed" -> {},
                    "Items" -> {}, "ItemsIndexed" -> {}},
GridBoxItemSize->{
                    "Columns" -> {{Automatic}},
                    "ColumnsIndexed" -> {}, "Rows" -> {{1.}},
                    "RowsIndexed" -> {}, "Items" -> {},
                    "ItemsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.84]},
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]},
Offset[0.2]}, "RowsIndexed" -> {}, "Items" -> {},
                    "ItemsIndexed" -> {}},
Selectable->True]}
},
GridBoxAlignment->{
                  "Columns" -> {{Left}}, "ColumnsIndexed" -> {},
                   "Rows" -> {{Baseline}}, "RowsIndexed" -> {},
                   "Items" -> {}, "ItemsIndexed" -> {}},
GridBoxItemSize->{
                  "Columns" -> {{Automatic}}, "ColumnsIndexed" -> {},
                   "Rows" -> {{1.}}, "RowsIndexed" -> {},
                   "Items" -> {}, "ItemsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.35]},
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]},
Offset[0.2]}, "RowsIndexed" -> {}, "Items" -> {},
                   "ItemsIndexed" -> {}}],
"Piecewise",
DeleteWithContents->True,
Editable->False,
SelectWithContents->True,
Selectable->False]\) ) (0.0005992450328750604` Cos[\[Theta]] +
              0.0023968602834924056` Cos[2 \[Theta]] +
              0.005392486225805579` Cos[3 \[Theta]] +
              0.17369695482741626` Sin[\[Theta]] -
              1.6694388668581954` Sin[2 \[Theta]] +
              0.4958866389704566` Sin[
                3 \[Theta]]) + (0.1792378074713546` Cos[\[Theta]] +
              0.6567894442540941` Cos[2 \[Theta]] -
              7.521686486251318` Cos[3 \[Theta]] -
              0.002388059687027475` Sin[\[Theta]] -
              0.019103522280305155` Sin[2 \[Theta]] -
              0.06446901482143186` Sin[
                3 \[Theta]]) UnitStep[-0.01` + \[Theta]] -
           0.19590701566884333` (0.17369695482741626` Cos[\[Theta]] -
              3.338877733716391` Cos[2 \[Theta]] +
              1.4876599169113698` Cos[3 \[Theta]] -
              0.0005992450328750604` Sin[\[Theta]] -
              0.004793720566984811` Sin[2 \[Theta]] -
              0.016177458677416736` Sin[
                3 \[Theta]]) UnitStep[-0.01` + \[Theta]])) +
     0.3588327668041265` ((-0.1367788536270296` +
           0.22165442361786794` Cos[\[Theta]] -
           0.0433321923224954` Cos[2 \[Theta]] -
           0.041543377668342985` Cos[3 \[Theta]] +
           0.9284408543946542` Sin[\[Theta]] -
           0.14311113535576353` Sin[2 \[Theta]] -
           0.21464881411190453` Sin[
             3 \[Theta]]) UnitStep[-0.01` + \[Theta]] -
        0.054429237999962535` (-0.495726932278196` -
           0.17369695482741626` Cos[\[Theta]] +
           0.8347194334290977` Cos[2 \[Theta]] -
           0.16529554632348553` Cos[3 \[Theta]] +
           0.0005992450328750604` Sin[\[Theta]] +
           0.0011984301417462028` Sin[2 \[Theta]] +
           0.0017974954086018597` Sin[
             3 \[Theta]]) UnitStep[-0.01` + \[Theta]] -
        0.04525014706857046` (-0.19590701566884333` \
(-0.495726932278196` - 0.17369695482741626` Cos[\[Theta]] +
              0.8347194334290977` Cos[2 \[Theta]] -
              0.16529554632348553` Cos[3 \[Theta]] +
              0.0005992450328750604` Sin[\[Theta]] +
              0.0011984301417462028` Sin[2 \[Theta]] +
              0.0017974954086018597` Sin[
                3 \[Theta]]) UnitStep[-0.01` + \[Theta]] + \
(-0.4923077743819351` - 0.1792378074713546` Cos[\[Theta]] -
              0.16419736106352353` Cos[2 \[Theta]] +
              0.8357429429168132` Cos[3 \[Theta]] +
              0.002388059687027475` Sin[\[Theta]] +
              0.004775880570076289` Sin[2 \[Theta]] +
              0.007163223869047984` Sin[
                3 \[Theta]]) UnitStep[-0.01` + \[Theta]])));
NIntegrate[ff, {\[Theta], 0.2, 0.8}]
Plot[ff, {\[Theta], 0.2, 0.8}]
 
Physics news on Phys.org
Dale said:
I don't get an error. It evaluates to 0.0661306 for me.
Thanks for responding, Dale! So you copy-pasted everything I did? Can you tell me what you get from 0 to 2 pi?

This is so weird! I quit the Kernal too and still getting 0. Any ideas what's happening on my machine?
 
joshmccraney said:
So you copy-pasted everything I did?
Yes.
joshmccraney said:
Can you tell me what you get from 0 to 2 pi?
I get -0.827297

No idea what is happening on your machine. I am using Mathematica 11.0
 
Dale said:
I get -0.827297

No idea what is happening on your machine. I am using Mathematica 11.0
I'm also running 11, and yes, I know your answer is correct. This is really bad, I have no clue what I should do. Any recommendations?
 
You might have to clear some files out. Some program keep metadata around that is out of sync with your stuff.

Of course you could turn this terrible turn of events around and buy a new machine. :-)

Have you searched the Mathematica site?
 
I did clear the kernal. Same issue. I also had a friend run the same code on their machine (I'm on mac, they are PC) and they also get 0.

Would either of you mind running the notebook if I send it to you (not sure why I can't upload it) since it has the function built rather than me copy-pasting it? Only takes a few minutes to run.
 
Dale said:
Sure. If it can’t upload as a .nb then you can just change the extension to .txt or similar
I did this but it outputs tons of random text. Will it still work?
 

Attachments

I just found something new: if I expand the integrand via //Expand, and then copy paste that into NIntegrate, I get the correct solution. However, if I do not expand, I get 0. Any ideas what's happening? This has to be a bug, right?
 
Sorry, let me send you something that makes much more sense (it's way cleaner).

Also, I did do Evaluate and it didn't work.
 

Attachments

Also Dale, I asked someone else in my lab to run the script I just posted and they got good results, like you had. They use Mathematica 11, but I'm using Mathematica 11.3.

Is that the difference?
 
joshmccraney said:
Also Dale, I asked someone else in my lab to run the script I just posted and they got good results, like you had. They use Mathematica 11, but I'm using Mathematica 11.3.

Is that the difference?
It could be. When I ran your notebook it did complain that it came from a more recent version. Perhaps there is a bug in 11.3 that did not exist previously
 
Dale said:
It could be. When I ran your notebook it did complain that it came from a more recent version. Perhaps there is a bug in 11.3 that did not exist previously
I can now confirm: yes, the issue is 11.3. I had several people in my lab run this code. Everyone on 11 had good outputs but everyone on 11.3 had errors. Thanks for helping. I'll report the error to Mathematica.
 
  • Like
Likes   Reactions: Dale