%%This M-file will generate the phase portrait for the Inverse Harmonic
%%Oscillator Potential V=-1/2*Kx^2.

%%Total Energy E is constant:

clf;
hold on;
axis([-1 1 -1 1]);

for E=-.5:.05:.5

    if E >= 0
        x=(-1:0.01:1);
        dx=gradient(x);
        v=sqrt(2*E+x.^2);       
        dv=gradient(v);
        plot(x,v);
        plot(x,-v);
        h=quiver(x(90),v(90),dx(90),dv(90)); 
        i=quiver(x(90),-v(90),dx(90),-dv(90));
        set(i,'LineWidth',3);
        set(i,'Color','red');
        set(h,'LineWidth',3);
        set(h,'MarkerSize',10000);
        set(h,'Color','black');
        
    end 
   
    if E <0
        xmin=sqrt(-2*E);
        x=(xmin+.00001:0.01:4*xmin);
        v=sqrt(2*E+x.^2);
        plot(x,v);
        plot(-x,v);
        plot(x,-v);
        plot(-x,-v);
    end    

end
