-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindefint.py
More file actions
32 lines (23 loc) · 864 Bytes
/
indefint.py
File metadata and controls
32 lines (23 loc) · 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function g=indefint(y,dx)
% returns the indefinite integral of the function
% represented by the array y. y(1) is assumed to
% be y(a), the function value at the lower limit of the
% integration. The function values are assumed to be
% values at the edges of the subintervals rather than
% the midpoint values. Hence, we have to use the
% trapezoid rule instead of the midpoint rule:
%
% integral(y(x)) from x to x+dx is (y(x)+y(x+dx))/2*dx
% The answer is returned as an array of values defined
% at the same points as y
% the first value of g(x) is zero because at this first value
% x is at the lower limit so the integral is zero
g(1)=0;
N=length(y);
% step across each subinterval and use the trapezoid area
% rule to find each successive addition to the indefinite
% integral
for n=2:N
% Trapezoid rule
g(n)=g(n-1)+(y(n-1)+y(n))*.5*dx;
end