dydt=@(t,th) [th(2);-9.8*sin(th(1))];
ts=[0,10];n=20;
tspan=linspace(ts(1),ts(2),n);
t0=[pi/4;0];
tt=[];theta=[];
for k=1:n-1
    [t,th]=ode45(dydt,[tspan(k),tspan(k+1)],t0);
    t0=th(length(th),:);
    if(k<n-1)
        t(length(t))=[];th(length(th),:)=[];
    end
    tt=[tt,t];
    theta=[theta;th];
end
plot(tt,theta(:,1));grid('on');