Code covered by the BSD License

# Chebpack

### Damian Trif (view profile)

15 Jul 2011 (Updated )

The MATLAB package Chebpack solves specific problems for differential or integral equations.

```function [int,gridpts] = quadcheb(myfun,n,dom,kind,tol,gridpts,I)
% Calculates the integral of "myfun" on "dom" using n Chebyshev
% points of the kind "kind" per subinterval, by domain splitting and recursivity
% until the tolerance "tol" is reached
% input arguments "gridpts" and "I" are working variables
% output arguments: int is the numerical value of the integral,
% gridpts is the final grid
%        err=abs(int-0.37853001712416130988),plot(gridpts,'.');ylabel('[0,1]');
%
persistent xs ws
a=dom(1);b=dom(2);c=(a+b)/2;
if nargin<5,tol=1.e-10;end
if nargin<6,gridpts=[];end
if nargin<7,
[xs,ws]=pd(n,[-1,1],kind);
x=a+(b-a)*(xs+1)/2;w=ws*(b-a)/2;
I=w*myfun(x);
end
x1=a+(c-a)*(xs+1)/2;w1=ws*(c-a)/2;I1=w1*myfun(x1);
x2=c+(b-c)*(xs+1)/2;w2=ws*(b-c)/2;I2=w2*myfun(x2);
int=I1+I2;if abs(I-int)<tol,gridpts=[gridpts,x1,x2];return;end