Find a convex combination of scalars given a point within them. I've been banging my head on this one all day! I'm going to do my best to explain the problem, but bear with me.
Given a set of numbers $S = \{X_1, X_2, \dots, X_n\}$ and a scalar $T$, where it is guaranteed that there is at least one member of $S$ that is less than $T$ and at least one member that's greater than $T$,
I'm looking for an algorithm to create a Convex Combination of these scalars that equals $T$. 
For example, for the set $\{2,4\}$ and the scalar $3$, the answer is:
$$.5 \cdot 2 + .5 \cdot 4 = 3.$$
I believe in many cases there are infinite infinitely many solutions.
I'm looking for a generalized algorithm/formula to find these coefficients.
Additionally, I would like for the coefficient weights to be distributed as evenly as possible (of course while still adding up to 1.)
For instance, for the set $\{1,2,4\}$ and the scalar $3$, a technically valid solution would be the same as the first example but with the coefficient for $1$ assigned a weight of 0 - but it would be prefferable to assign a non-zero weight.
I may not be thinking through this last part very clearly :)
 A: There are lots of functions you could use to define "distributed as evenly as possible."  
For example, you could define "distributed as evenly as possible" to mean that you want to minimize the total squared deviation of the coefficients from their mean.  This definition has the advantage of being particularly tractable analytically.  If you go this route, and you let $c_1, c_2, \ldots, c_n$ be the coefficients, you would need to solve the problem
$$
\begin{align}
\min \sum_{i=1}^n (c_i - \bar{c})^2& \\
\text{subject to }
\sum_{i=1}^n c_i X_1 &= T, \\
\sum_{i=1}^n c_i &= 1, \\
c_i& \geq 0, \text{ for each } i
\end{align}$$
This is a quadratic programming problem.  There are plenty of common software packages (e.g., Matlab) out there that will easily solve a quadratic programming problem for you.   Standard QP form requires that the objective function look like $$\min {\bf c}^T Q {\bf c}.$$
For your problem the form of $Q$ ends up being particularly nice: The diagonal elements of $Q$ are $\frac{n-1}{n}$, and the off-diagonal elements are all $-\frac{1}{n}$.
A: You try to prove the Caratheodory theorem for 1-dimensional space.
The algorithm can be found in its proof. See wikipedia.
A: If $X_1<T<X_2$, then $T$ is a weighted average of $X_1$ and $X_2$ with weights $\dfrac{X_2-T}{X_2-X_1}$ and $\dfrac{T-X_1}{X_2-X_1}$, as can be checked by a bit of algebra.
Now suppose $X_3$ is also $>T$.  Then $T$ is a weighted average of $X_1$ and $X_3$, and you can find the weights the same way.
Now take $40\%$ of the weight assigned to $X_2$ in the first case, and assign it to $X_2$, and $60\%$ of the weight assigned to $X_3$ in the second case and assign it to $X_3$ and let the weight assigned to $X_1$ be $40\%$ of the weight it got in the first case plus $60\%$ of the weight it got in the first case, and you've got another solution.  And as with $40$ and $60$, so also with $41$ and $59$, and so on, and you've got infinitely many solutions.
But don't say "infinite solutions" if you mean "infinitely many solutions".  "Infinite solutions" means "solutions, each one of which, by itself, is infinite".
Later note in response to comments:
Say you write $4$ as an average of $3$ and $5$ with weights $1/2$, $1/2$.
And you write $4$ as an average of $3$ and $7$ with weights $3/4$, $1/4$.
Then you have $4$ as a weighted average of $3$, $5$, and $7$ with weights $1/2,\ 1/2,\ 0$.
And you have $4$ as a weighted average of $3$, $5$, and $7$ with weights $3/4,\ 0,\ 1/4$.
So find a weighted average of $(1/2,\ 1/2,\ 0)$ and $(3/4,\ 0,\ 1/4)$.  For example, $40\%$ of the first plus $60\%$ of the second is $(0.65,\ 0.2,\ 0.15)$.
Then you have $4$ as a weighted average of $3$, $5$, and $7$ with weights $0.65$, $0.2$, and $0.15$.
And you can come up with infinitely many other ways to write $4$ as a weighted average of $3$, $5$, and $7$ by using other weights than $0.4$ and $0.6$.
A: Denote the set of numbers $S$ by the column vector $x=[x_1,x_2,\ldots,x_N]^T$. Let us denote the set of numbers we are looking for by the column vector $a=[a_1,a_2,\ldots,a_N]^T$. Also, denote $b=[1,1,\ldots,1]^T$ Then the set of all solutions for your problem can be found by solving 
\begin{align}
\min_a 0 \\
\text{subject to }&a^Tx=T \\
&a^Tb=1\\
&a\geq0
\end{align}
Let us say, you wish to give any particular weight to each of the solution, say the vector $w=[w_1,w_2,\ldots,w_N]^T$. Then the solution can be found by solving 
\begin{align}
\min_a w^Ta \\
\text{subject to }&a^Tx=T \\
&a^Tb=1\\
&a\geq0
\end{align}
Both of this problems are linear programming problems and hence should be solvable by simplex algorithm.
A: thanks for the detailed suggestions. I came up with a solution that uses some of your suggestions and thought it'd be best to post it as an answer. This uses much of Michael Hardy's suggestions and explanation, so big thanks there. Also thanks to those of you who suggested the MatLab solutions - in this case I wanted something I could code up easily and that would run efficiently in C#.
Ultimately, what I meant intuitively by "evenly distributed coefficients" was simply that I wanted to include contributions from every number in the set, as opposed to the trivial solution where you assign weights of 0 to everything but two of the numbers. I'm not sure what the name is for what my solution ultimately minimizes, but the end result is that all numbers greater than T have equal weights, and all numbers less than T have equal weights. This works out nicely for my purposes.
So here's the solution I used:


*

*Divide the set into two parts: numbers less than T (let's call this set $L$) and those greater than T (let's call this set $G$)

*Calculate the mean of L (call it $mL$) and the mean of G (call it $mG$)

*Using these two averages as if they were the only two numbers in the set, calculate their weights (w1, w2) such that $mL*w1 + mG*w1 = T$. This is a straightforward linear interpolation as Michael Hardy's answer provided at the beginning.

*Assign all values in $L$ a weight of $w1/(size of L)$, and all values in $G$ a weight of $w2/(size of G)$.
I can't prove why this works - but intuitively it makes sense, as you are simply distributing the weight needed to pull the overall weighted average towards T across all numbers on each side of T.
Again - thanks for all your help, I wouldn't have been able to do this without you folks! And please let me know if there's anything I should do differently as far as formatting etc.
