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.

[t,solnum2]=Ex6pant(n)
function [t,solnum2]=Ex6pant(n)
% Example 6
% x'(t)-c*x'(t^2)=t^2, x(0)=0, (Nussbaum)
% Use: [t,solnum]=Ex6pant(128);
dom=[0 0.999];kind=2;
[t,w]=pd(n,dom,kind);D=deriv(n,dom);T=cpv(n,0,dom);S=dev(n,t,dom,t.^2);

%c=2
A=D-2*S*D;b=x2t(t.^2,kind);A(n,:)=T;b(n)=0;
sol=A\b;solnum2=t2x(sol,kind);

%c=1.5
A=D-1.5*S*D;b=x2t(t.^2,kind);A(n,:)=T;b(n)=0;
sol=A\b;solnum1p5=t2x(sol,kind);

%c=1, we must add a supplementary condition x'(0)=0
A=D-S*D;b=x2t(t.^2,kind);A(n-1,:)=T;b(n-1)=0;A(n,:)=T*D;b(n)=0;
sol=A\b;solnum1=t2x(sol,kind);

%c=0.5
A=D-0.5*S*D;b=x2t(t.^2,kind);A(n,:)=T;b(n)=0;
sol=A\b;solnum0p5=t2x(sol,kind);

% calculate the exact solution
solex=t.^3/3;
for i=1:16
    alphai=2^(i+1)+1;termi=2^i/alphai*(t.^alphai);
    solex=solex+termi;
end
plot(t,solex,'k-',t,solnum2,'k.',t,solnum1p5,'k--',t,solnum1,'k-.',t,solnum0p5,'k:');
xlabel('t');ylabel('x(t)');grid;
legend('exact, k=2','numeric, k=2','numeric, k=1.5','numeric, k=1','numeric, k=0.5');
end

Contact us