Code covered by the BSD License

# Chebpack

### Damian Trif (view profile)

15 Jul 2011 (Updated )

The MATLAB package Chebpack solves specific problems for differential or integral equations.

ex5.m
```function [t,x,F]=ex5(alpha)
% from: Juan J. Nieto, Donal O'Regan, Variational approach to impulsive
% differential equations, Nonlinear Analysis: Real World Applications
% 10(2009), 680690.
% use: for alpha=-0.6:0.005:1.7,[t,x,F]=ex5(alpha);
%      plot(alpha,F,'.k','MarkerSize',8);pause(0.1);
%      hold on;end;grid;hold off;
% or   [t,x,F]=ex5(-0.54155);
% or   [t,x,F]=ex5(1.65465);
%
n=64;kind=2;
doml=[0,pi/2];tl=pd(n,doml,kind);Dl=deriv(n,doml);
Tl=cpv(n,doml,doml);sl=sin(tl);
domr=[pi/2,pi];tr=pd(n,domr,kind);Dr=deriv(n,domr);
Tr=cpv(n,domr,domr);sr=sin(tr);
Al=-Dl^2+eye(n);Al(n-1,:)=Tl(1,:);Al(n,:)=Tl(1,:)*Dl;
Ar=-Dr^2+eye(n);Ar(n-1,:)=Tr(1,:);Ar(n,:)=Tr(1,:)*Dr;
xlold=0*tl;xrold=0*tr;
for iter=1:50
bl=x2t(xlold.^2-sl,kind);bl(n-1)=0;bl(n)=alpha;Xlnew=Al\bl;
br=x2t(xrold.^2-sr,kind);br(n-1)=Tl(2,:)*Xlnew;
br(n)=Tl(2,:)*Dl*Xlnew-nthroot(br(n-1),3);
Xrnew=Ar\br;
xlnew=t2x(Xlnew,kind);xrnew=t2x(Xrnew,kind);
err=norm(xlnew-xlold)+norm(xrnew-xrold);%display(err);
if err<1.e-6, break;end
xlold=xlnew;xrold=xrnew;
end;
F=xrnew(end);
t=[tl;tr];x=[xlnew;xrnew];
% uncomment for [t,x,F]=ex4(...);
% plot(t,x);xlabel('t');ylabel('x');grid;
% title(['x''(0)= ',num2str(alpha),', f = ',num2str(F)]);
end```