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.

volt_eq_ex1.m
```function [x,solnum]=volt_eq_ex1(n,dom,kind)
% Example: int_0^x cos(x-t)y(t)dt=sin(x), x in [0,pi]
% From: E. Babolian, A. S. Shamloo, J. Comp. Appl. Math. 214(2008), 495  508
% Exact solution: solex=1
% Remark: by differentiation y(x)-int_0^x sin(x-t)y(t)dt=cos(x)
% call [x,solnum]=volt_eq_ex1(16,[0,pi],2);
%
tic;
Vspec=volt(n,dom,kind);
F=x2t(myfun(x),kind);
sol=(eye(n)-Vspec)\F;solnum=t2x(sol,kind);
toc;myOUT
function [Vspec,Vphys]=volt(n,dom,kind)
% Volterra operator with kernel K(x,t)
x=pd(n,dom,kind);T=cpv(n,x,dom);[~,J0]=prim(n,dom);
V=T*J0/T;
[YY,XX]=meshgrid(x,x);KW=mykernel(XX,YY);
Vphys=V.*KW;Vspec=T\Vphys*T;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function res=mykernel(x,t)
% x,t matrices
res=sin(x-t);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function f=myfun(x)
f=cos(x);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myOUT
solex=1;subplot(2,1,1);semilogy(abs(sol),'.');
title('The absolute value of the coefficients of the solution');grid;
subplot(2,1,2);plot(x,solnum);grid;xlabel('x');ylabel('y(x)');
title(['The numerical solution (error = ',num2str(norm(solnum-solex)),')']);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end```