Optimizing engines to produce a certain torque and net force Say we have $n$ engines sitting on a rigid body. Each engine has position $R_i$ and points in a certain direction and generates a force in that direction, $F_i$. The magnitude of that force ($k_i$) follows this constraint: $0 \leq k_i \leq m_i$. In other words, the engine can only output so much force.
I want to be able to find the values of $k$ that would bring the resultant force $F$ and torque $T$ closest to a desired value.
Based on the resultant force equation, I know that
$$F = \sum_{i=1}^{n} (k_iF_i)$$
and the torque:
$$T = \sum_{i=1}^{n} (R_i) \times (k_iF_i)$$
where $R_i$ is the position of the engine relative to the point of application of the resultant force.
However, I'm unsure of how to best proceed from here.

edit: I solved the problem one way using linear programming and minimizing the absolute value of the difference between each component of the ideal and actual force/torque, not optimizing for fuel. This allowed me to put constraints on the engine's force magnitude.
 A: The problem is one of least squares (until the point where the magnitude is capped).
Consider the target force vector $\vec{F}$ and the target moment vector $\vec{T}$ as the right-hand side $\boldsymbol{b}$ of a linear system of equations, and the vector $\boldsymbol{x}$ of $n$ force magnitudes is the unknowns.
$$ \mathbf{A}\;\boldsymbol{x} = \boldsymbol{b} $$
$$ [\mathbf{A}]_{6\times n}\; \begin{pmatrix}F_{1}\\
F_{2}\\
\vdots\\
F_{n}
\end{pmatrix}_{n\times1} = \begin{pmatrix}\vec{F}\\
\vec{T}
\end{pmatrix}_{6\times1} \tag{1}$$
We will get later into what the coefficient matrix $\mathbf{A}$ is. For now consider a case where $n \geq 6$, and the solution is given by
$$ \boldsymbol{x} = \mathbf{A}^\top \left( \mathbf{A} \mathbf{A}^\top \right)^{-1} \boldsymbol{b} \tag{2}$$
Where $^\top$ is the matrix transpose.
So what is $\mathbf{A}$? There are 6 rows and $n$ columns to this matrix, and the first 3 rows is filled with all $n$ force direction vectors $\vec{z}_i$, and the last 3 rows with all $n$ torque directions $\vec{r}_i \times \vec{z}_i$.
$$ \mathbf{A} = \begin{bmatrix}\vec{z}_{1} & \vec{z}_{2} & \cdots & \vec{z}_{n}\\
\vec{r}_{1}\times\vec{z}_{1} & \vec{r}_{2}\times\vec{z}_{2} & \cdots & \vec{r}_{n}\times\vec{z}_{n}
\end{bmatrix}_{6\times n} \tag{3}$$
The result isn't guaranteed to be within the force limits, but it will be the least possible force system overall.
Reduced Example
Consider a planar example (for simplicity with 3 DOF instead of 6) with $n=4$ forces arranged in a rectangle of size $a$, $b$, and each direction pointing to the next force location.
$$\begin{aligned} 
 \vec{r}_1 &= \pmatrix{-\tfrac{a}{2} \\ -\tfrac{b}{2} } & \vec{z}_1 &= \pmatrix{1\\0} & \vec{r}_1 \times \vec{z}_1 = \tfrac{b}{2}  \\ 
 \vec{r}_2 &= \pmatrix{ \tfrac{a}{2} \\ -\tfrac{b}{2} } & \vec{z}_2 &= \pmatrix{0\\1} & \vec{r}_2 \times \vec{z}_2 = \tfrac{a}{2}\\
 \vec{r}_3 &= \pmatrix{ \tfrac{a}{2} \\  \tfrac{b}{2} } & \vec{z}_3 &= \pmatrix{-1\\0} & \vec{r}_3 \times \vec{z}_3 = \tfrac{b}{2} \\
 \vec{r}_4 &= \pmatrix{-\tfrac{a}{2} \\  \tfrac{b}{2} } & \vec{z}_4 &= \pmatrix{0\\-1} & \vec{r}_4 \times \vec{z}_4 = \tfrac{a}{2} \\
\end{aligned} $$
with the target force $\vec{F}= \pmatrix{3 \\ 2} $ and moment $T=\pmatrix{1}$
$$ \boldsymbol{b} = \begin{pmatrix} 3 \\ 2 \\ 1 \end{pmatrix} $$
The coefficient matrix is composed from (3)
$$ \mathbf{A} = \begin{bmatrix} 1 & 0 & -1 & 0 \\ 0 & 1 & 0 & -1 \\ \tfrac{b}{2} & \tfrac{a}{2} & \tfrac{b}{2} & \tfrac{a}{2}\end{bmatrix} $$
and solution from (2)
$$ \pmatrix{F_1 \\ F_2 \\ F_3 \\ F_4} = \begin{bmatrix} 1 & 0 & -1 & 0 \\ 0 & 1 & 0 & -1 \\ \tfrac{b}{2} & \tfrac{a}{2} & \tfrac{b}{2} & \tfrac{a}{2}\end{bmatrix}^\top  \begin{bmatrix} 2 & 0 & 0 \\ 0 & 2 & 0 \\ 0 & 0 & \tfrac{a^2+b^2}{2} \end{bmatrix} ^{-1} \begin{pmatrix} 3 \\ 2 \\ 1 \end{pmatrix} = \pmatrix{\tfrac{3}{2} + \tfrac{b}{a^2+b^2} \\ 1+\tfrac{a}{a^2+b^2} \\ -\tfrac{3}{2}+\tfrac{b}{a^2+b^2} \\ -1+\tfrac{a}{a^2+b^2}}  $$
Let us check the result
$$ \vec{F}= F_1 \vec{z}_1 + F_2 \vec{z}_2 + F_3 \vec{z}_3 + F_4 \vec{z}_4 = \pmatrix{3\\2} \; \checkmark$$
$$ \vec{T} =F_1 (\vec{r}_1 \times \vec{z}_1) + F_2 (\vec{r}_2 \times \vec{z}_2) + F_3 (\vec{r}_3 \times \vec{z}_3) + F_4 (\vec{r}_4 \times \vec{z}_4) = \pmatrix{1} \; \checkmark$$

This method also solves the "Find the forces of the four legs of a table" problem given an arbitrary load on the table surface.

