restart;

H := subs(p=diff(f(q,P,t), q), 1/(2*m)*p^2 + 1/2*m*w^2*q^2) = -diff(f(q,P,t), t);

H:=subs( f(q,P,t) = f1(q) + f2(t), H);

sol:=dsolve({rhs(H)=E,lhs(H)=E});

S:=rhs(sol[1][1]+sol[1][2]);

subs(m=1, diff(S,q));

p := (E, theta) -> -(1/2)*sqrt(-q^2*w^2+2*E)+(1/2)*q^2*w^2/sqrt(-q^2*w^2+2*E)-E*(sqrt(w^2)/sqrt(-q^2*w^2+2*E)+sqrt(w^2)*q^2*w^2/(-q^2*w^2+2*E)^(3/2))/(sqrt(w^2)*(1+w^2*q^2/(-q^2*w^2+2*E)));

lst := [seq(p((1/2)*E, theta), E=0..5),seq(-p((1/2)*E, theta), E=0 .. 5)]:

plot(lst, theta = -3*Pi..3*Pi, color = black, numpoints=1000);

i plot it circle in circle, should i substitute a value to q before plot?

i guess q is velocity, is it?

why substitute E with 1/2*E?

subs(q=1, subs(m=1, diff(S,q)));

p := (E, w) -> -(1/2)*sqrt(-w^2+2*E)+(1/2)*w^2/sqrt(-w^2+2*E)-E*(sqrt(w^2)/sqrt(-w^2+2*E)+sqrt(w^2)*w^2/(-w^2+2*E)^(3/2))/(sqrt(w^2)*(1+w^2/(-w^2+2*E)));

lst := [seq(p((1/2)*E, w), E=1..5),seq(-p((1/2)*E, w), E=1 .. 5)]:

plot(lst, w = -3*Pi..3*Pi, color = black, numpoints=1000);