function Hw12

% %Section 6.4 #1
% 
% N=500; T_end=50;
% dt=T_end/N;
% 
% t=zeros(N+1,1);
% y=zeros(N+1,1);
% forcing=zeros(N+1,1);
% for it=1:N+1
%     t(it,1)=dt*(it-1);
%     ti=dt*(it-1);
%     y(it,1)=sin(ti)+1-cos(ti);
%     if ti>3*pi
%         y(it,1)=y(it,1)-(1+cos(ti));
%     end
%     if ti<3*pi
%         forcing(it,1)=1;
%     end
% end
% 
% plot(t,y,'r -',t,forcing,'b -')
% 
% print('SolutionProblem1Section6pt4','-depsc',figure(1))

%%

%Section 6.4 #2

N=500; T_end=15;
dt=T_end/N;

t=zeros(N+1,1);
y=zeros(N+1,1);
forcing=zeros(N+1,1);
for it=1:N+1
    t(it,1)=dt*(it-1);
    ti=dt*(it-1);
    y(it,1)=exp(-ti)*sin(ti);
    if ti>pi
        y(it,1)=y(it,1)+(1/2)*(1+exp(-(ti-pi))*cos(ti)+exp(-(ti-pi))*sin(ti));
    end
    if ti>2*pi
        y(it,1)=y(it,1)-(1/2)*(1-exp(-(ti-2*pi))*cos(ti)-exp(-(ti-2*pi))*sin(ti));
    end
    if ti>pi && ti<2*pi
        forcing(it,1)=1;
    end
end

plot(t,y,'r -',t,forcing,'b -')

print('SolutionProblem2Section6pt4','-depsc',figure(1))