# Lagrangian for an oscillator with position-dependent damping

I wonder if the equation of motion of an oscillator with (position-dependent) damping \begin{equation*} \ddot{x}+\gamma(x)\dot{x}+\omega_{0}^{2}x=0 \end{equation*} can be derived directly from a damped Lagrangian?

Clearly, if $\gamma$ does not depend on the position, the time-dependent damped Lagrangian $$\mathcal{L}(x,\dot{x},t)=e^{\gamma t}/2(\dot{x}^{2}-\omega_{0}^{2}x^{2})$$ would do the job. Alternatively, the above equation can be derived by introducing the dissipation function $$Q(x,\dot{x})=-\frac{\partial\mathcal{F}}{\partial\dot{x}},$$ where $$\mathcal{F}(x,\dot{x})=\frac{1}{2}\gamma(x)\dot{x}^{2}.$$

TL;DR: Yes, a variational formulation exists locally if the variable $x$ is 1-dimensional (rather than multi-dimensional).

One can rewrite any second-order ODE (such as OP's eom) as 2 coupled first-order OPEs $$\dot{x}~=~f(x,y), \qquad \dot{y}~=~g(x,y).\tag{1}$$ More generally, a variational formulation exists locally for any system of the form (1).

Sketched existence proof:

1. It is explained in part II of my Phys.SE answer here that there exists locally a Hamiltonian formulation $$\dot{x}~=~\{x,H\}, \qquad \dot{y}~=~\{y,H\}\tag{2}$$ of the system (1).

2. A Poisson structure in 2 dimensions is fully determined by a single function $$B(x,y)~:=~\{x,y\}.\tag{3}$$

3. The corresponding symplectic 2-form $$\omega~=~\frac{1}{B}\mathrm{d}y\wedge \mathrm{d}x~=~\mathrm{d}\theta\tag{4}$$ is locally exact, where $$\theta~=~a(x,y)~\mathrm{d}x+b(x,y)~\mathrm{d}y\tag{5}$$ is a symplectic potential 1-form.

4. The Hamilton's equations (2) are the Euler-Lagrange (EL) equations of the following Hamiltonian Lagrangian: $$L_H~:=~a\dot{x}+b\dot{y}-H . \tag{6}$$ $\Box$

Note that the Lagrangian (6) does not depend explicitly on time.