Code covered by the BSD License  

Highlights from
Chebpack

image thumbnail

Chebpack

by

 

15 Jul 2011 (Updated )

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

[int,grid]=quad_ex2(n,a,x,tol)
function [int,grid]=quad_ex2(n,a,x,tol)
% Calculates \int_-1^1 (a./(a^2+(x-y).^2))dy using "quadcheb.m"
% call: [int,grid]=quad_ex2(64,1.e-4,0.25,1.e-15);
 tic;[int,grid]=quadcheb(@(y) a./(a^2+(x-y).^2),n,[-1,1],2,tol);toc;
 Iex=atan((1-x)/a)+atan((1+x)/a);err=abs(int-Iex);
 yy=linspace(-1,1,100000);
 subplot(2,1,1);plot(grid,'.');ylabel('y');
 title(['The final grid: the error = ',num2str(err)]);
 subplot(2,1,2);plot(yy,a./(a^2+(x-yy).^2));xlabel('y');ylabel('f(y)');
 title(['\int_{-1}^1 a/(a^2+(x-y)^2)dy = ',num2str(int), ', a=1.e-4, x=0.25']);
 numeric=int,exact=Iex,

Contact us