How do I calculate a upward-pulling force on a swinging pendulum? I'm trying to implement a simple pendulum using a 2d physics system that can model rigid bodies with gravity. The problem is that I don't know how to calculate the upward-pulling force of the rope, as in this image:

I've only found equations for calculating velocity of the pendulum, as shown on wikipedia, but the problem is that I can't change the velocity directly, as I need to be applying a force.

The problem is probably just the magnitude of the force vector. Since in the idle position the upward force is equal to negative gravity, I thought I could simply take something like $cos(\theta) \cdot v \cdot G$ where $v$ is the pendulum vector and G is gravity magnitude, but that doesn't work in my simulation.
 A: The rope pulls just enough that the pendulum doesn't fall to the ground, but follows an arc.
The following picture shows you how work out the force for the static case (no motion of the pendulum):
 
However, you need to take account of the fact that the pendulum is moving in an arc. When something moves in an arc, you need an additional force $F=\frac{mv^2}{r}$ to provide the centripetal force needed.
Combine these two forces, to obtain the total "mysterious force". Can you figure it out from here?
A: A properly drawn free-body diagram will have a tension force vector acting along the line of the rope, toward the pivot point and a gravity vector acting straight down. If you establish a coordinate system which is instantaneously parallel and perpendicular to the rope, you then will decompose the gravity vector into two components ( $mg$ times  trig functions of the angular position, $\theta$). Usually, $\theta$ is measured with respect to the vertical.
The vector sum of the components  parallel to the rope must equal $m\frac{v^2}{l}$ where $l$ is the length of the pendulum. 
$$ F_{tension}-mg\cdot\text{trig_function}(\theta)=m\frac{v^2}{l}
$$
The gravity component perpendicular to the rope must be $ml\alpha$ where $\alpha$ is the instantaneous angular acceleration, $\alpha= \dfrac{d^2\theta}{dt^2}$.
