1

What is the number of solutions of a linear equation? for example look at this equation:

$X_1+X_2+...+X_n=r$

The number of solutions is the following formula, because the way of choosing $r$ objects from $n$ distinct objects when repetition is allowed is going to be this formula

$C(n+r-1,r)$

Now what about this equation

$2X_1+4X_2+X_3=24$

What is the number of solutions?$X_i$ is non negative integer

M a m a D
  • 471
  • What are $x_i$? integers? rationals? – Galc127 Oct 18 '14 at 13:42
  • they are all integers – M a m a D Oct 18 '14 at 13:42
  • Let's fix $x_1$ to some value, say $x_1=4$, so we get the equation $x_3=-4x_2+16$. How much solutions does this equation have? If you are asking about natural numbers, then it's different. – Galc127 Oct 18 '14 at 13:45
  • @Galc127 $X_i$s are non negative integer, this problem is in the discrete mathematics – M a m a D Oct 18 '14 at 13:47
  • This sounds like the NP complete subset sum problem. – Irvan Oct 18 '14 at 13:50
  • @Irvan This problem is asked in the discrete math book of Grimaldi at the end of the first season! – M a m a D Oct 18 '14 at 13:51
  • Well, the equation you asked is of a very special form where all the coefficients divides each other. There's a polynomial algorithm (which can be translated to a formula) to solve this form.

    However, if the coefficients can be arbitrary, I'm pretty sure even finding out whether it has a solution is NP complete.

    – Irvan Oct 18 '14 at 13:53
  • $X_3$ must also be even, so it can be represented by $2k$, which then gives us $$X_1 + 2X_2 + k = 12$$ – amWhy Oct 18 '14 at 13:56
  • @amWhy no it is not at all – M a m a D Oct 18 '14 at 14:03

2 Answers2

2

The equation is $2x_1+4x_2+2x_3=24$.

We can show that $x_3$ has to be divisible by 2. Say $x_3=2y$ we get the equation $2x_1+4x_2+2y=24$.

Dividing by 2 we get $\displaystyle x_1+2x_2+y=12 \rightarrow x_2=\frac{12-x_1-y}{2}$.

We can conclude that both $x_1$ and $y$ are even or both are odd.

If they are even then $x_1=2k \ , \ y=2m$ and we get $\displaystyle x_2=\frac{12-2k-2m}{2}=6-k-m \rightarrow k+m+x_2=6$. You can use your first formula.

If they are odd then $x_1=2k+1 \ , \ y=2m+1$ and we get $\displaystyle x_2=\frac{12-(2k+1)-(2m+1)}{2}=5-k-m \rightarrow k+m+x_2=5$. You can use your first formula.

Does this answer help?

Galc127
  • 4,491
  • You answer is very customized to this problem what if the coefficients are 2,3 and 5? does this work this well? – M a m a D Oct 18 '14 at 13:58
  • 1
    In the general case of equation of the form $\displaystyle a_1x_1+a_2x_2+a_3x_3+...+a_kx_k=C$ we can use generating functions - http://en.wikipedia.org/wiki/Generating_function. – Galc127 Oct 18 '14 at 14:00
2

This is very similar to "making change" type problems, such as this question.

They can easily be solved with recurrences or generating functions.

So for example in this case, consider the coefficient of $x^{24}$ in the expansion of $\dfrac{1}{(1-x)(1-x^2)(1-x^4)}$ which is $1+x+2 {x}^{2}+2 {x}^{3}+4 {x}^{4}+4 {x}^{5}+6 {x}^{6}+6 {x}^{7}+9 {x}^{8}+9 {x}^{9}+12 {x}^{10}+12 {x}^{11}+16 {x}^{12}+16 {x}^{13}+20 {x}^{14}+20 {x}^{15}+25 {x}^{16}+25 {x}^{17}+30 {x}^{18}+30 {x}^{19}+36 {x}^{20}+36 {x}^{21}+42 {x}^{22}+42 {x}^{23}+49 {x}^{24}+\cdots$ so giving the result $49$.

Henry
  • 169,616