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.

ex5_work.m
function [t,x,Fval]=ex5_work(h)
% from: Juan J. Nieto, Donal O'Regan, Variational approach to impulsive 
% differential equations, Nonlinear Analysis: Real World Applications 
% 10(2009), 680690.
% Use: [t,x]=ex5_work(2.7);
%
n=32;kind=2;
doml=[0,pi/2];tl=pd(n,doml,kind);Dl=deriv(n,doml);Jl=prim(n,doml);
Tl=cpv(n,doml,doml);sl=sin(tl);
domr=[pi/2,pi];tr=pd(n,domr,kind);Dr=deriv(n,domr);Jr=prim(n,domr);
Tr=cpv(n,domr,domr);sr=sin(tr);
Aeq=zeros(3,2*n);Aeq(1,1)=1;Aeq(2,n)=1;Aeq(2,n+1)=-1;Aeq(3,2*n)=1;
beq=[0;0;0];
xold=[h*2/pi*tl;h*2/pi*(pi-tr)];
options=optimset('Algorithm','interior-point',...
    'MaxFunEvals',30000,'Display','iter');
[x,Fval]=fmincon(@ex6fun,xold,[],[],Aeq,beq,[],[],[],options);
t=[tl;tr];plot(t,x);grid;
function f=ex6fun(x)
xl=x(1:n);xr=x(n+1:2*n);Xl=x2t(xl,kind);Xr=x2t(xr,kind);
f=(Tl(2,:)-Tl(1,:))*Jl*x2t(t2x(Dl*Xl,kind).^2+xl.^2,kind)/2;
f=f+(Tr(2,:)-Tr(1,:))*Jr*x2t(t2x(Dr*Xr,kind).^2+xr.^2,kind)/2;
f=f-3/4*nthroot(xl(end)^4,3);
f=f+(Tl(2,:)-Tl(1,:))*Jl*x2t(sl.*xl-xl.^3/3,kind);
f=f+(Tr(2,:)-Tr(1,:))*Jr*x2t(sr.*xr-xr.^3/3,kind);
end
end

Contact us