function [t,sol]=qualitative_studies_Ex1()
close all
clf;

% plot reference functions 
t=linspace(-3,3,50);
figure(1);
plot(t,-atan(t),'b-')
hold on
plot(t,atan(t),'g-')
hold on
plot(t,zeros(size(t)),'k--')
hold on
plot(t,pi/2*ones(size(t)),'m-')
hold on
plot(t,-pi/2*ones(size(t)),'c-')
ylim([-2,2])

% solve ODE forward in time (t>t0)
tspan=linspace(1,3,50);
y0=0;
[tt,y] = ode23s(@(tt,y) y^2-(atan(tt)).^2, tspan, y0);
plot(tt,y,'r-o')

% solve ODE backward in time (t<t0)
xmesh = linspace(-3,1,50);
solinit = bvpinit(xmesh, @guess);


sol = bvp4c(@bvpfcn, @bcfcn, solinit);

hold on
plot(sol.x, sol.y, 'r-*');
legend('y=-arctan(t)','y=arctan(t)','y=0','y=\pi/2','y=-\pi/2','y(t) forward sol','y(t) backward sol')
hold on

% plot y-axis (not in the legend)
plot(zeros(size(t)),t,'k-')


% auxiliary functions for backward solution
    
    function res = bcfcn(ya,yb)
res = [yb(1)];
end

function dydx = bvpfcn(t,y)
dydx = [y.^2-(atan(t)).^2];
end

function g = guess(x)
g = [-atan(x)];
end

end
