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

In summary, the conversation discusses a long function that is only 3 command lines. The function defines ff, numerically integrates the function, and plots it. However, the integral appears to be zero even though the plot shows otherwise. The conversation ends by asking for any ideas on what could be causing this discrepancy.
  • #1
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
  • #2
I don't get an error. It evaluates to 0.0661306 for me.
 
  • #3
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?
 
  • #4
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
 
  • #5
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?
 
  • #6
Did you restart the kernel? Maybe something is in memory messing up the computation.
 
  • #7
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?
 
  • #8
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.
 
  • #9
Sure. If it can’t upload as a .nb then you can just change the extension to .txt or similar
 
  • #10
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

  • Torus.txt
    122.6 KB · Views: 429
  • #11
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?
 
  • #12
How about if you do NIntegrate[Evaluate[ff]...
 
  • #13
Just ran your notebook. I get 0.0639344 this time.
 
  • #14
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

  • Torus 2.txt
    92.1 KB · Views: 388
  • #15
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?
 
  • #16
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
 
  • #17
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 Dale

What is numerical integration error?

Numerical integration error is the difference between the exact value of an integral and the approximate value calculated using numerical integration methods.

What causes numerical integration error?

Numerical integration error can be caused by a variety of factors, including the choice of integration method, the number of intervals used, and the precision of the calculations.

How is numerical integration error calculated?

Numerical integration error is typically calculated by taking the absolute value of the difference between the exact value and the approximate value of the integral.

How can numerical integration error be reduced?

Numerical integration error can be reduced by using more accurate integration methods, increasing the number of intervals, and using higher precision calculations.

What are the implications of numerical integration error?

Numerical integration error can impact the accuracy and reliability of scientific and engineering calculations. It is important to carefully consider the choice of integration method and the level of precision needed for a particular application.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
18
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top