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.

[x,solnum]=fred_eq_ex1(n,dom,kind)
function [x,solnum]=fred_eq_ex1(n,dom,kind)
% Example: y(x)=1+1/pi int_-1^1{a/(a^2+(x-t)^2)y(t)}dt, x in [-1,1], a=1
% From: R. Piessens, M. Branders, J. Comp. Phys, 21(1976), 178-196
% Remark: Love's equation
% call [x,solnum]=fred_eq_ex1(400,[-1,1],2);
%
tic;a=1;
Fspec=fred(n,dom,kind);
F=x2t(myfun(x),kind);
sol=(speye(n)-Fspec)\F;% solution in the spectral space
solnum=t2x(sol,kind);% solution in the physical space
toc;myOUT
function [Fspec,Fphys]=fred(n,dom,kind)
% Fredholm operator with kernel K(x,t)
[x,w]=pd(n,dom,kind);T=cpv(n,x,dom);
[YY,XX]=meshgrid(x,x);KW=mykernel(XX,YY);
Fphys=KW*diag(w);Fspec=T\Fphys*T;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function res=mykernel(x,t)
    % x,t matrices
    res=a/pi./(a^2+(x-t).^2);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function f=myfun(x)
    f=ones(n,1);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myOUT 
    figure(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');
    display('Spectral coefficients');
    display(sol(1:20));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end

Contact us