Given #H(p,q,t)=p^2/(2 a) -
b q p e^(-alpha t) + (a b)/
2 q ^2 e^(-alpha t) (alpha + b e^(-alpha t)) + (k q^2)/2#

by Legendre's transformation we have

#H=dot q p -L#

now #dotq = (partialH)/(partial p)=p/a - b e^(-alpha t) q#

solving for #p# we have

#p=a e^(-t alpha) (b q + e^(alpha t) dot q)#

substituting into #L# we have

#L=a e^(-alpha t)
dot q (b q + e^(alpha t) dot q) -
1/2 a e^(-2 alpha t) (b q +
e^(alpha t) dot q)^2#

The movement equation associated to that lagrangian is obtainable making

#d/dt((partial L)/(partial dot q))-(partial L)/(partial q)=0#

so

#a ddot q + k q=0# is the movement equation.

so an equivalent lagrangian is obtained as follows

#a ddot q dot q+k dot q q= 0# integrating we obtain the movement total energy (kinetic #1/2a dot q^2# plus potential #1/2q^2# ) so the lagrangian is

#L_(equ) = 1/2(a dot q^2-k q^2)#

because #L# and #L_(equ)# have the same movement equations.

and also

#H_(equ)=1/2(p^2/a+k q^2)#