# How to solve equation inside a loop?

I am new to Mathematica, so probably this question will be very basic. I have three shares (that are between 0 and 1), say $a$, $b$ and $c$. They sum up to one $(a+b+c=1)$. For every $b$ from 0 to 1, I need to find all the possible combinations of $a$ and $c$. I tried with a solve equation inside a loop, like this:

p = For[b = 0, b <= 1, b += 0.01,
Solve[{a + b + c == 1 && 0 <= a <= 1 && 0 <= c <= 1}, {a, c}]]

and it does not work because of inexact coefficients. I also tried with FindRoot but did not work. Do you know some way that I could use to solve this problem? Thank you!

• I don't understand what you mean by all the possible combinations of a and c. There are infinitely many for each value of b (of course, except when b = 1) since you only have one (linear) equation, but three variables. Jun 8, 2018 at 21:56

The general problem, i.e. of finding all values of $a$ and $c$ for which $a+b+c=1$ for a certain value of $b$ admits infinite solutions, as mentioned in comments.
However, your proposed code seems to imply that you can work with a discrete resolution, i.e. that $a,b,c$ can vary by e.g. no less than $0.01$. You can use e.g. IntegerPartitions to solve this problem. If you want a resolution of $0.01=1/100$, then you can use IntegerPartitions to find all integer triplets that sum to $1/0.01=100$, then divide each triplet by $100$: