Lagrangian and Hamiltonian formalism for damped pendulum Suppose I have a simplified pendulum (massless string of length $l$, ball of mass $m$ and some non-zero volume). I want to derive the equations of motion, but I want to take air resistance under account. I know how to do it by applying Newton's 2nd law, but is there any way I can do that using lagrangian or hamiltonian? What would be the form of lagrangian/hamiltonian in such case?
 A: For a general damping force there is no Least Action Principle. However you can obtain the equations of motions from d'Alembert Principle. The procedure is explained here and the equations of motions are
$$\frac{d}{dt}\frac{\partial L}{\partial \dot q_i}-\frac{\partial L}{\partial q_i}=Q_i^p,$$
where $L=T-V$ is the Lagrange function and
$$Q_i^p\equiv\sum_\alpha\vec F_\alpha\cdot\frac{\partial \vec r_\alpha}{\partial q_i},$$
is the so-called generalized force which depends on the damping force $\vec F_\alpha$ acting of particle $\alpha$.
Since for general damping we cannot formulate a variational principle, $L$ itself is not enough determine the dynamic evolution of the system. Therefore there is no Hamiltonian $H$ satisfying 
$$\delta S=\delta\int_{t_1}^{t_2}\left[\sum_i p_i\dot q_i-H(q,p,t)\right]dt=0.$$
Recall that the canonical equations can also be obtained from the variational principle above so there is no function $H$ satisfying the canonical equations and the equations of motion of the system (which shall take the damping into account) simultaneously.
In the case of linear damping, you can follow the Bateman idea which is mentioned in ZeroTheHero's answer or use the Rayleigh dissipation function
A: It depends on the form of the damping, but if you write
$$
L=e^{\alpha t}\left(\textstyle\frac{1}{2}m\dot{q}^2 -V(q)\right)
$$
then you get an equation of motion of the form
$$
e^{\alpha t}\left( m\ddot{q}+m\alpha \dot{q}+\frac{dV}{dq}\right)=0
$$
which may account for the friction depending on your friction model.  
The Hamiltonian would be computed in the usual way but clearly $L$ depends explicitly on $t$ so the energy is not conserved in your system.

Edit: changed $\alpha\to -\alpha$ after a correct comment. 
A: In a sense yes; you'll need to write the force of air resistance as if it can be derived from a velocity dependent potential. 
A common example of this is a particle in a magnetic field. The force of the magnetic field on the particle depends on its velocity, so the potential is written as $\vec{A} \cdot \vec{v}$. 
