Determine the number of all nonnegative integer solutions to $x+y+z = 11$ with $x\leq 3$, $y\leq 4$, and $z \leq 6$.
Asked
Active
Viewed 1,105 times
-2
-
The answer is 5 but I don't knoıw how to solve – Bahadır Sefa Akçay Nov 26 '15 at 00:34
3 Answers
2
The number of solutions is $6$:
\begin{equation} \begin{array} \\ x = 1, & y = 4, & z = 6 \\ \\ x = 2, & y = 3, & z = 6 \\ \\ x = 2, & y = 4, & z = 5 \\ \\ x = 3, & y = 2, & z = 6 \\ \\ x = 3, & y = 3, & z = 5 \\ \\ x = 3, & y = 4, & z = 4 \\ \end{array} \end{equation}
Here is some R code that finds the solutions:
#Matrix for saving results
mat <- matrix(NA,ncol = 1,nrow = 3)
colnames(mat) <- c("x","y","z")
#Loop through all possible values
for (x in c(0,1,2,3)){
for (y in c(0,1,2,3,4)){
for (z in c(0,1,2,3,4,5,6)){
if(x+y+z == 11){
mat <- cbind(mat,c(x,y,z))
}
}
}
}
Rodrigo Zepeda
- 606
0
A program in VB to be run in Excel:
Sub Macro1546687()
'
CONT = 1
'
For I = 0 To 3
For J = 0 To 4
For K = 0 To 6
'
Sum = I + J + K
'
If Sum = 11 Then
Cells(CONT, 1) = I
Cells(CONT, 2) = J
Cells(CONT, 3) = K
CONT = CONT + 1
End If
'
Next K
Next J
Next I
'
End Sub
cgiovanardi
- 836