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.

Ex4_delay( n , lambda , K )
function [T,Y,y_coef,sol] = Ex4_delay( n , lambda , K )
% Kiss-Lessardt equation y'(t)=-lambda [y(t-tau1)+y(t-tau2)] [1+y(t)],
%    tau1=1.65, tau2=0.35, lambda=3.4, y(t)=2 for t in [-tau1,0]
% use: [T,Y,y_coef,sol]=Ex4_delay(16,3.4,400);
%
tic;kind=2;dom=[-1.7,-1.65];
for k=1:33
dom=dom+0.05;t(:,k)=pd(n,dom,kind);D=deriv(n,dom);
%y_val(:,k)=-3.5*t(:,k).*(t(:,k)+1.65)/0.35;
y_val(:,k)=2*ones(n,1);
y_coef(:,k)=x2t(y_val(:,k),kind);
dy_coef(:,k)=D*y_coef(:,k);dy_val(:,k)=t2x(dy_coef(:,k),kind);
end;
for k=34:K
    dom=dom+0.05;D=deriv(n,dom);
    F=fact(lambda*(y_coef(:,k-33)+y_coef(:,k-7)),n);
    A=D+F;b=-lambda*(y_coef(:,k-33)+y_coef(:,k-7));
    A(n,:)=cpv(n,dom(1),dom);b(n)=y_val(n,k-1);
    y_coef(:,k)=A\b;t(:,k)=pd(n,dom,kind);dy_coef(:,k)=D*y_coef(:,k);
    y_val(:,k)=t2x(y_coef(:,k),kind);dy_val(:,k)=t2x(dy_coef(:,k),kind);
end
T=reshape(t,n*K,1);Y=reshape(y_val,n*K,1);Y_coef=reshape(y_coef,n*K,1);
dY=reshape(dy_val,n*K,1);
figure(1);plot(T,Y);xlabel('t');ylabel('y');grid;hold on
figure(2);plot(Y,dY);xlabel('y');ylabel('y''');grid;hold on;toc;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
tic;options=ddeset('RelTol',1.e-5,'AbsTol',1.e-8);
sol=ddesd(@ddewride,[1.65,0.35],@ddewrihist,[0,(K-33)*0.05],options);
figure(1);plot(sol.x,sol.y,'.r');xlabel('t');ylabel('y');grid;
legend('Chebpack','ddesd');
figure(2);plot(sol.y,sol.yp,'.r');xlabel('y');ylabel('y''');toc;
function dydt=ddewride(t,y,Z)
dydt=-lambda*(Z(1)+Z(2))*(1+y);
end
    function s=ddewrihist(t)
        s=2;
    end
end

Contact us