<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8">
    
    <title>scipy.integrate.cumtrapz &mdash; SciPy v1.1.0.dev0+4e64658 Reference Guide</title>
    
    <link rel="stylesheet" type="text/css" href="../_static/css/spc-bootstrap.css">
    <link rel="stylesheet" type="text/css" href="../_static/css/spc-extend.css">
    <link rel="stylesheet" href="../_static/scipy.css" type="text/css" >
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" >
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '1.1.0.dev0+4e64658',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  false
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/scipy-mathjax/MathJax.js?config=scipy-mathjax"></script>
    <script type="text/javascript" src="../_static/js/copybutton.js"></script>
    <link rel="index" title="Index" href="../genindex.html" >
    <link rel="search" title="Search" href="../search.html" >
    <link rel="top" title="SciPy v1.1.0.dev0+4e64658 Reference Guide" href="../index.html" >
    <link rel="up" title="Integration and ODEs (scipy.integrate)" href="../integrate.html" >
    <link rel="next" title="scipy.integrate.simps" href="scipy.integrate.simps.html" >
    <link rel="prev" title="scipy.integrate.trapz" href="scipy.integrate.trapz.html" > 
  </head>
  <body>

  <div class="container">
    <div class="header">
    </div>
  </div>


    <div class="container">
      <div class="main">
        
	<div class="row-fluid">
	  <div class="span12">
	    <div class="spc-navbar">
              
    <ul class="nav nav-pills pull-left">
	
        <li class="active"><a href="../index.html">SciPy v1.1.0.dev0+4e64658 Reference Guide</a></li>
	
          <li class="active"><a href="../integrate.html" accesskey="U">Integration and ODEs (<code class="docutils literal"><span class="pre">scipy.integrate</span></code>)</a></li> 
    </ul>
              
              
    <ul class="nav nav-pills pull-right">
      <li class="active">
        <a href="../genindex.html" title="General Index"
           accesskey="I">index</a>
      </li>
      <li class="active">
        <a href="../py-modindex.html" title="Python Module Index"
           >modules</a>
      </li>
      <li class="active">
        <a href="scipy.integrate.simps.html" title="scipy.integrate.simps"
           accesskey="N">next</a>
      </li>
      <li class="active">
        <a href="scipy.integrate.trapz.html" title="scipy.integrate.trapz"
           accesskey="P">previous</a>
      </li>
    </ul>
              
	    </div>
	  </div>
	</div>
        

	<div class="row-fluid">
      <div class="spc-rightsidebar span3">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../index.html">
              <img class="logo" src="../_static/scipyshiny_small.png" alt="Logo">
            </a></p>
  <h4>Previous topic</h4>
  <p class="topless"><a href="scipy.integrate.trapz.html"
                        title="previous chapter">scipy.integrate.trapz</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="scipy.integrate.simps.html"
                        title="next chapter">scipy.integrate.simps</a></p>


        </div>
      </div>
          <div class="span9">
            
        <div class="bodywrapper">
          <div class="body" id="spc-section-body">
            
  <div class="section" id="scipy-integrate-cumtrapz">
<h1>scipy.integrate.cumtrapz<a class="headerlink" href="#scipy-integrate-cumtrapz" title="Permalink to this headline">¶</a></h1>
<dl class="function">
<dt id="scipy.integrate.cumtrapz">
<code class="descclassname">scipy.integrate.</code><code class="descname">cumtrapz</code><span class="sig-paren">(</span><em>y</em>, <em>x=None</em>, <em>dx=1.0</em>, <em>axis=-1</em>, <em>initial=None</em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/scipy/scipy/blob/4e64658/scipy/integrate/quadrature.py#L209-L298"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#scipy.integrate.cumtrapz" title="Permalink to this definition">¶</a></dt>
<dd><p>Cumulatively integrate y(x) using the composite trapezoidal rule.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>y</strong> : array_like</p>
<blockquote>
<div><p>Values to integrate.</p>
</div></blockquote>
<p><strong>x</strong> : array_like, optional</p>
<blockquote>
<div><p>The coordinate to integrate along.  If None (default), use spacing <em class="xref py py-obj">dx</em>
between consecutive elements in <em class="xref py py-obj">y</em>.</p>
</div></blockquote>
<p><strong>dx</strong> : float, optional</p>
<blockquote>
<div><p>Spacing between elements of <em class="xref py py-obj">y</em>.  Only used if <em class="xref py py-obj">x</em> is None.</p>
</div></blockquote>
<p><strong>axis</strong> : int, optional</p>
<blockquote>
<div><p>Specifies the axis to cumulate.  Default is -1 (last axis).</p>
</div></blockquote>
<p><strong>initial</strong> : scalar, optional</p>
<blockquote>
<div><p>If given, uses this value as the first value in the returned result.
Typically this value should be 0.  Default is None, which means no
value at <code class="docutils literal"><span class="pre">x[0]</span></code> is returned and <em class="xref py py-obj">res</em> has one element less than <em class="xref py py-obj">y</em>
along the axis of integration.</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>res</strong> : ndarray</p>
<blockquote class="last">
<div><p>The result of cumulative integration of <em class="xref py py-obj">y</em> along <em class="xref py py-obj">axis</em>.
If <em class="xref py py-obj">initial</em> is None, the shape is such that the axis of integration
has one less value than <em class="xref py py-obj">y</em>.  If <em class="xref py py-obj">initial</em> is given, the shape is equal
to that of <em class="xref py py-obj">y</em>.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p><a class="reference external" href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.cumsum.html#numpy.cumsum" title="(in NumPy v1.13)"><code class="xref py py-obj docutils literal"><span class="pre">numpy.cumsum</span></code></a>, <a class="reference external" href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.cumprod.html#numpy.cumprod" title="(in NumPy v1.13)"><code class="xref py py-obj docutils literal"><span class="pre">numpy.cumprod</span></code></a></p>
<dl class="last docutils">
<dt><a class="reference internal" href="scipy.integrate.quad.html#scipy.integrate.quad" title="scipy.integrate.quad"><code class="xref py py-obj docutils literal"><span class="pre">quad</span></code></a></dt>
<dd>adaptive quadrature using QUADPACK</dd>
<dt><a class="reference internal" href="scipy.integrate.romberg.html#scipy.integrate.romberg" title="scipy.integrate.romberg"><code class="xref py py-obj docutils literal"><span class="pre">romberg</span></code></a></dt>
<dd>adaptive Romberg quadrature</dd>
<dt><a class="reference internal" href="scipy.integrate.quadrature.html#scipy.integrate.quadrature" title="scipy.integrate.quadrature"><code class="xref py py-obj docutils literal"><span class="pre">quadrature</span></code></a></dt>
<dd>adaptive Gaussian quadrature</dd>
<dt><a class="reference internal" href="scipy.integrate.fixed_quad.html#scipy.integrate.fixed_quad" title="scipy.integrate.fixed_quad"><code class="xref py py-obj docutils literal"><span class="pre">fixed_quad</span></code></a></dt>
<dd>fixed-order Gaussian quadrature</dd>
<dt><a class="reference internal" href="scipy.integrate.dblquad.html#scipy.integrate.dblquad" title="scipy.integrate.dblquad"><code class="xref py py-obj docutils literal"><span class="pre">dblquad</span></code></a></dt>
<dd>double integrals</dd>
<dt><a class="reference internal" href="scipy.integrate.tplquad.html#scipy.integrate.tplquad" title="scipy.integrate.tplquad"><code class="xref py py-obj docutils literal"><span class="pre">tplquad</span></code></a></dt>
<dd>triple integrals</dd>
<dt><a class="reference internal" href="scipy.integrate.romb.html#scipy.integrate.romb" title="scipy.integrate.romb"><code class="xref py py-obj docutils literal"><span class="pre">romb</span></code></a></dt>
<dd>integrators for sampled data</dd>
<dt><a class="reference internal" href="scipy.integrate.ode.html#scipy.integrate.ode" title="scipy.integrate.ode"><code class="xref py py-obj docutils literal"><span class="pre">ode</span></code></a></dt>
<dd>ODE integrators</dd>
<dt><a class="reference internal" href="scipy.integrate.odeint.html#scipy.integrate.odeint" title="scipy.integrate.odeint"><code class="xref py py-obj docutils literal"><span class="pre">odeint</span></code></a></dt>
<dd>ODE integrators</dd>
</dl>
</div>
<p class="rubric">Examples</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">scipy</span> <span class="k">import</span> <span class="n">integrate</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">num</span><span class="o">=</span><span class="mi">20</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span> <span class="o">=</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y_int</span> <span class="o">=</span> <span class="n">integrate</span><span class="o">.</span><span class="n">cumtrapz</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">initial</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y_int</span><span class="p">,</span> <span class="s1">&#39;ro&#39;</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="s1">&#39;b-&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
<div class="figure">
<img alt="../_images/scipy-integrate-cumtrapz-1.png" src="../_images/scipy-integrate-cumtrapz-1.png" />
</div>
</dd></dl>

</div>


          </div>
        </div>
          </div>
        </div>
      </div>
    </div>

    <div class="container container-navbar-bottom">
      <div class="spc-navbar">
        
      </div>
    </div>
    <div class="container">
    <div class="footer">
    <div class="row-fluid">
    <ul class="inline pull-left">
      <li>
        &copy; Copyright 2008-2016, The Scipy community.
      </li>
      <li>
      Last updated on Sep 21, 2017.
      </li>
      <li>
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.6.3.
      </li>
    </ul>
    </div>
    </div>
    </div>
  </body>
</html>