## Copyright (C) 2007 Tiago Charters de Azevedo ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA function inttrap(a,b,n) %Trapezoidal integration rule % Integrates a function f:[a,b]->R with n subintervals format short g; if (nargin != 3) disp("") usage ("Integrates f:[a,b], n sub-intervals"); disp("") endif disp("") h=(b-a)/n; x=[a:h:b]; I=h/2.*(2*sum(f(x))-f(a)-f(b)); endfunction