%This m-file will generate a phase-portrait for an object falling in a
%uniform gravitational field with a frictional force proportional to its
%velocity

clf;
hold on;
cmap=colormap;
axis([-7000 3500 -150 0]);
title('Phase Portrait of object falling in uniform gravitational field');
xlabel('Position--z'); ylabel('Velocity in Vertical Direction');

%zo=100;
%vzo=200;

m=10;
g=9.8;
a=1;

for i=1:15
    zo=200*i;
    for j=1:10 
        vzo=j*100/2-400;

        vz=zeros(1,50000);
        z=zeros(1,50000);
        t=zeros(1,50000);

        for i=1:50000
            t(i)=i*0.001;
            vz(i)=(vzo+m*g/a)*exp(-a*t(i)/m)-m*g/a;
            z(i)=(m/a)*(vzo+m*g/a)*(1-exp(-a*t(i)/m))-m*g*t(i)/a+zo;
    
        end

h=plot(z,vz);
color_index=j*6;
set(h,'color',cmap(color_index,:));

    end
end

c_bar=colorbar;
set(c_bar,'YTickLabel',[-300 -200 -100 0 100 200]);

text_on_screen=text(-6000,-25,'m=10 kg \newline\alpha=1 kg/s\newlinev_{term}\approx-100 m/s')
set(text_on_screen,'EdgeColor','blue','LineWidth',2)
