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,solnum]=Ex5pant(n)
function [t,solnum]=Ex5pant(n)
% Example 5
% u'(t)+1/2*u'(t/2)^2-3/2*u(t), u(0)=u'(0)=1, uex=exp(t)
% use: [t,solnum]=Ex5pant(8)
%
dom=[0 1];kind=2;
[t,w]=pd(n,dom,kind);D=deriv(n,dom);T=cpv(n,0,dom);S=dev(n,t,dom,t/2);
Uinit=x2t(1+t,kind);
options=optimset('Display','iter','TolFun',1.e-12,'TolX',1.e-12,'MaxFunEvals',20000,'MaxIter',200);
U=fsolve(@fun_ex5,Uinit,options);
solnum(:,1)=t2x(U,kind);solex=exp(t);
semilogy(t,abs(solnum-solex));grid;
err=max(abs(solnum-solex))
function F=fun_ex5(U)
du=t2x(S*D*U,kind);
f=-x2t(du.^2/2,kind);
A=D-3/2*eye(n);A(n-1,:)=T;f(n-1)=1;A(n,:)=T*D;f(n)=1;
F=A*U-f;
end
end

Contact us