%%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([-10 10 -10 10]);

for E=8:.1:10

    j=1;

    if E >= 0
        xo=[.2:0.001:4];
        for i=1: length(xo)
            if (2*E-xo(i)^2-1/(xo(i)^2)) > 0,
               x(j)=xo(i);
               v(j)=sqrt(2*E-xo(i)^2-1/(xo(i)^2));       
               j=j+1;       
            end;    
        end;
        dx=gradient(x);
        dv=gradient(v);
        plot(x,v);
        plot(x,-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=[-10:0.01:-0.1,0.1:0.01:10];
    %    v=sqrt(2*E-x.^2-1./(x.^2)); 
     %   plot(x,v);
      %  plot(-x,v);
       % plot(x,-v);
        %plot(-x,-v);
        %   end    

end
