# Extract the potential energy from the gravity vector

I have a recursive Newton Euler algorithm from which I can compute the gravity vector. My question is, which is the better way to compute the potential energy? I know the following relation between gravity vector and potential energy $$\textbf{g} = \left( \frac{\partial U}{\partial q}\right)^T$$ so in theory I could integrate numerically and get the potential energy, but since it is a gradient I'm not sure how to proceed. Of course I can compute it just computing all the contribution of the potential energy of each link knowing the mass and the center of gravity but I would like to know if there is a smarter and faster way to get it.

• yes I know, but in this case I have a recursive Newton Euler model of my robot so this means that I don't have a model in symbolical form that can be evaluated, but of course I have all the necessary information to compute the potential energy i.e. the mass of each link and the position of the center of gravity. The fact is that for some reason I don't want to compute the potential energy in this way and I would like to know if I can compute it using the gravity vector. What I have now is the following dynamical model $$M(q)\ddot{q}+C(q,\dot{q})+g(q)=\tau$$all the elements are not symbolic. Commented Feb 3, 2022 at 8:10