Numerical integration with scipy.integrate.trapz returns a result but scipy.integrate.simps does not












0















I am trying to integrate the following data numerically:



t,y
9.960000000000001e-05,8.334379999999999e-05
9.98e-05,0.000126125
0.0001,0.00018125
0.0001002,0.0002385
0.00010040000000000001,0.000289625
0.0001006,0.000347313
0.0001008,0.000391719
0.000101,0.00043284399999999994
0.00010120000000000001,0.000472375
0.00010140000000000001,0.000502469
0.00010160000000000002,0.000528594
0.00010180000000000001,0.000546219
0.000102,0.000569188
0.0001022,0.000584719
0.0001024,0.000593969
0.00010260000000000001,0.000607375
0.0001028,0.000618906
0.000103,0.000629344
0.0001032,0.000629344
0.0001034,0.000636313
0.00010360000000000001,0.0006374999999999999
0.0001038,0.000630375
0.00010400000000000001,0.00059875
0.0001042,0.00046825
0.0001044,0.000287344
0.00010460000000000002,0.000208594
0.0001048,0.000196094
0.000105,0.000172625
0.00010520000000000001,0.000134781
0.0001054,0.000115906
0.0001056,0.00010306300000000001
0.00010580000000000001,9.31563e-05


As shown below, I read this data set from a csv file.
This is my code:



import pandas as pd
from scipy.integrate import trapz, simps

root="my/root/dir"

df = pd.read_csv(root+r"simps.csv")
print(trapz(df["t"], df["y"]))
print(simps(df["t"], df["y"]))


trapz returns a value (-9.5865055e-10) while simps returns nan and the following error:



anacondapathscipyintegratequadrature.py:324: RuntimeWarning: divide by zero encountered in true_divide
h0divh1 = h0 / h1
anacondapathscipyintegratequadrature.py:326: RuntimeWarning: divide by zero encountered in true_divide
y[slice1]*hsum*hsum/hprod +
anacondapathscipyintegratequadrature.py:327: RuntimeWarning: invalid value encountered in add
y[slice2]*(2-h0divh1))
anacondapathscipyintegratequadrature.py:326: RuntimeWarning: invalid value encountered in add
y[slice1]*hsum*hsum/hprod +


Why does this error occur?










share|improve this question



























    0















    I am trying to integrate the following data numerically:



    t,y
    9.960000000000001e-05,8.334379999999999e-05
    9.98e-05,0.000126125
    0.0001,0.00018125
    0.0001002,0.0002385
    0.00010040000000000001,0.000289625
    0.0001006,0.000347313
    0.0001008,0.000391719
    0.000101,0.00043284399999999994
    0.00010120000000000001,0.000472375
    0.00010140000000000001,0.000502469
    0.00010160000000000002,0.000528594
    0.00010180000000000001,0.000546219
    0.000102,0.000569188
    0.0001022,0.000584719
    0.0001024,0.000593969
    0.00010260000000000001,0.000607375
    0.0001028,0.000618906
    0.000103,0.000629344
    0.0001032,0.000629344
    0.0001034,0.000636313
    0.00010360000000000001,0.0006374999999999999
    0.0001038,0.000630375
    0.00010400000000000001,0.00059875
    0.0001042,0.00046825
    0.0001044,0.000287344
    0.00010460000000000002,0.000208594
    0.0001048,0.000196094
    0.000105,0.000172625
    0.00010520000000000001,0.000134781
    0.0001054,0.000115906
    0.0001056,0.00010306300000000001
    0.00010580000000000001,9.31563e-05


    As shown below, I read this data set from a csv file.
    This is my code:



    import pandas as pd
    from scipy.integrate import trapz, simps

    root="my/root/dir"

    df = pd.read_csv(root+r"simps.csv")
    print(trapz(df["t"], df["y"]))
    print(simps(df["t"], df["y"]))


    trapz returns a value (-9.5865055e-10) while simps returns nan and the following error:



    anacondapathscipyintegratequadrature.py:324: RuntimeWarning: divide by zero encountered in true_divide
    h0divh1 = h0 / h1
    anacondapathscipyintegratequadrature.py:326: RuntimeWarning: divide by zero encountered in true_divide
    y[slice1]*hsum*hsum/hprod +
    anacondapathscipyintegratequadrature.py:327: RuntimeWarning: invalid value encountered in add
    y[slice2]*(2-h0divh1))
    anacondapathscipyintegratequadrature.py:326: RuntimeWarning: invalid value encountered in add
    y[slice1]*hsum*hsum/hprod +


    Why does this error occur?










    share|improve this question

























      0












      0








      0








      I am trying to integrate the following data numerically:



      t,y
      9.960000000000001e-05,8.334379999999999e-05
      9.98e-05,0.000126125
      0.0001,0.00018125
      0.0001002,0.0002385
      0.00010040000000000001,0.000289625
      0.0001006,0.000347313
      0.0001008,0.000391719
      0.000101,0.00043284399999999994
      0.00010120000000000001,0.000472375
      0.00010140000000000001,0.000502469
      0.00010160000000000002,0.000528594
      0.00010180000000000001,0.000546219
      0.000102,0.000569188
      0.0001022,0.000584719
      0.0001024,0.000593969
      0.00010260000000000001,0.000607375
      0.0001028,0.000618906
      0.000103,0.000629344
      0.0001032,0.000629344
      0.0001034,0.000636313
      0.00010360000000000001,0.0006374999999999999
      0.0001038,0.000630375
      0.00010400000000000001,0.00059875
      0.0001042,0.00046825
      0.0001044,0.000287344
      0.00010460000000000002,0.000208594
      0.0001048,0.000196094
      0.000105,0.000172625
      0.00010520000000000001,0.000134781
      0.0001054,0.000115906
      0.0001056,0.00010306300000000001
      0.00010580000000000001,9.31563e-05


      As shown below, I read this data set from a csv file.
      This is my code:



      import pandas as pd
      from scipy.integrate import trapz, simps

      root="my/root/dir"

      df = pd.read_csv(root+r"simps.csv")
      print(trapz(df["t"], df["y"]))
      print(simps(df["t"], df["y"]))


      trapz returns a value (-9.5865055e-10) while simps returns nan and the following error:



      anacondapathscipyintegratequadrature.py:324: RuntimeWarning: divide by zero encountered in true_divide
      h0divh1 = h0 / h1
      anacondapathscipyintegratequadrature.py:326: RuntimeWarning: divide by zero encountered in true_divide
      y[slice1]*hsum*hsum/hprod +
      anacondapathscipyintegratequadrature.py:327: RuntimeWarning: invalid value encountered in add
      y[slice2]*(2-h0divh1))
      anacondapathscipyintegratequadrature.py:326: RuntimeWarning: invalid value encountered in add
      y[slice1]*hsum*hsum/hprod +


      Why does this error occur?










      share|improve this question














      I am trying to integrate the following data numerically:



      t,y
      9.960000000000001e-05,8.334379999999999e-05
      9.98e-05,0.000126125
      0.0001,0.00018125
      0.0001002,0.0002385
      0.00010040000000000001,0.000289625
      0.0001006,0.000347313
      0.0001008,0.000391719
      0.000101,0.00043284399999999994
      0.00010120000000000001,0.000472375
      0.00010140000000000001,0.000502469
      0.00010160000000000002,0.000528594
      0.00010180000000000001,0.000546219
      0.000102,0.000569188
      0.0001022,0.000584719
      0.0001024,0.000593969
      0.00010260000000000001,0.000607375
      0.0001028,0.000618906
      0.000103,0.000629344
      0.0001032,0.000629344
      0.0001034,0.000636313
      0.00010360000000000001,0.0006374999999999999
      0.0001038,0.000630375
      0.00010400000000000001,0.00059875
      0.0001042,0.00046825
      0.0001044,0.000287344
      0.00010460000000000002,0.000208594
      0.0001048,0.000196094
      0.000105,0.000172625
      0.00010520000000000001,0.000134781
      0.0001054,0.000115906
      0.0001056,0.00010306300000000001
      0.00010580000000000001,9.31563e-05


      As shown below, I read this data set from a csv file.
      This is my code:



      import pandas as pd
      from scipy.integrate import trapz, simps

      root="my/root/dir"

      df = pd.read_csv(root+r"simps.csv")
      print(trapz(df["t"], df["y"]))
      print(simps(df["t"], df["y"]))


      trapz returns a value (-9.5865055e-10) while simps returns nan and the following error:



      anacondapathscipyintegratequadrature.py:324: RuntimeWarning: divide by zero encountered in true_divide
      h0divh1 = h0 / h1
      anacondapathscipyintegratequadrature.py:326: RuntimeWarning: divide by zero encountered in true_divide
      y[slice1]*hsum*hsum/hprod +
      anacondapathscipyintegratequadrature.py:327: RuntimeWarning: invalid value encountered in add
      y[slice2]*(2-h0divh1))
      anacondapathscipyintegratequadrature.py:326: RuntimeWarning: invalid value encountered in add
      y[slice1]*hsum*hsum/hprod +


      Why does this error occur?







      python math scipy integrate






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 16 '18 at 7:45









      plane loverplane lover

      234




      234
























          1 Answer
          1






          active

          oldest

          votes


















          0














          A very stupid mistake: I exchanged x and y. Simps requires y as a first argument






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53333471%2fnumerical-integration-with-scipy-integrate-trapz-returns-a-result-but-scipy-inte%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            A very stupid mistake: I exchanged x and y. Simps requires y as a first argument






            share|improve this answer




























              0














              A very stupid mistake: I exchanged x and y. Simps requires y as a first argument






              share|improve this answer


























                0












                0








                0







                A very stupid mistake: I exchanged x and y. Simps requires y as a first argument






                share|improve this answer













                A very stupid mistake: I exchanged x and y. Simps requires y as a first argument







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 16 '18 at 14:46









                plane loverplane lover

                234




                234
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53333471%2fnumerical-integration-with-scipy-integrate-trapz-returns-a-result-but-scipy-inte%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Bressuire

                    Vorschmack

                    Quarantine