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]=ibvp_ode_ex8(n,dom,kind)
function [x,solnum]=ibvp_ode_ex8(n,dom,kind)
% Example: y^(8)+y^(7)+...+y'+y=9 exp(x),x in [0,1]
%          y(0)=y'(0)=y''(0)=...=y^(7)(0)=1
% Exact solution: solex=exp(x)
% call: [x,solnum]=ibvp_ode_ex8(32,[0 1],2);
% 
tic;
A=zeros(n);b=zeros(n,1);
x=pd(n,dom,kind);D=deriv(n,dom);
myDE;myBC;sol=A\b;% the solution in spectral form
toc;
solnum = t2x(sol,kind);% the solution in physical form
myOUT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myDE
    E=speye(n);
    A=(((((((D+E)*D+E)*D+E)*D+E)*D+E)*D+E)*D+E)*D+E;
    b=x2t(9*exp(x),kind);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myBC
    T=cpv(n,dom(1),dom);
    A(n-7,:)=T;b(n-7)=1;A(n-6,:)=T*D;b(n-6)=1;A(n-5,:)=A(n-6,:)*D;b(n-5)=1;
    A(n-4,:)=A(n-5,:)*D;b(n-4)=1;A(n-3,:)=A(n-4,:)*D;b(n-3)=1;
    A(n-2,:)=A(n-3,:)*D;b(n-2)=1;A(n-1,:)=A(n-2,:)*D;b(n-1)=1;
    A(n,:)=A(n-1,:)*D;b(n)=1;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myOUT
    solex=exp(x);
    plot(x,solnum,'b');grid;xlabel('x');ylabel('y(x)');
    title(['The solution (error= ',num2str(norm(solnum-solex)),')']);  
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end

Contact us