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_test.m
```function [x,solnum]=volt_eq_test(n,dom,kind)
% Example: y(x)=-int_0^x exp(x-t)y(t)dt+1, x in [0,1]
% From:E. Babolian, A. S. Shamloo, J. Comp. Appl. Math. 214(2008), 495508
% Exact solution: solex=1-x
% call [x,solnum]=volt_eq_test(16,[0,1],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=-exp(x-t);% K(x,t) given by the user
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function f=myfun(x)
f=ones(n,1);% f(x) given by the user
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myOUT
solex=1-x;
subplot(2,1,1);semilogy(abs(sol),'.');
title('The absolute value of the Chebyshev coefficients');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```