~ubuntu-branches/ubuntu/karmic/scilab/karmic

« back to all changes in this revision

Viewing changes to macros/elem/inttrap.sci

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2002-03-21 16:57:43 UTC
  • Revision ID: james.westby@ubuntu.com-20020321165743-e9mv12c1tb1plztg
Tags: upstream-2.6
ImportĀ upstreamĀ versionĀ 2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function v = inttrap(x,y)
 
2
//inttrap  Trapezoidal numerical integration.
 
3
//v = inttrap(x,y) computes the integral of y with respect to x using
 
4
//trapezoidal integration.  x and y must be vectors of the same dimension
 
5
//v = inttrap(y) computes the trapezoidal integral of y assuming unit
 
6
//spacing between the data points. 
 
7
// Copyright INRIA
 
8
 
 
9
[lhs,rhs]=argn(0)
 
10
if rhs<2 then
 
11
  y=x;
 
12
  v=sum(y(1:$-1) + y(2:$))/2;
 
13
else
 
14
  if size(x,'*')<>size(y,'*') then
 
15
    error('input vectors must have the same dimension');
 
16
  end
 
17
  x=x(:);y=y(:);
 
18
  v=(x(2:$)-x(1:$-1))'*(y(1:$-1) + y(2:$))/2;
 
19
end
 
20