# Answer to Question #34020 in MatLAB | Mathematica | MathCAD | Maple for dothan

Question #34020

for a1=1:W

for a2=a1:W

for a3=a2:W

for a4=a3:W

for a5=i-a4-a3-a2-a1;

if(a4 <= a5 && a5<=W)

p2=[p2;a1,a2,a3,a4,a5];

end

end

end

end

end

end

Here if a1=1 then a2=1,2,3, if a1=2 then a2=2,3 and if a1=3 then a2=3. The same condition is for a3 & a4. Now I want to make this program only depends on "W" and "i" and I don't want to write a1,a2,a3,a4,a5.Because i need to run this code for i=4 and for a=2:4(a1 a2,a1 a2 a3,a1 a2 a3 a4)and again for i=5 and for a=2:4(a1 a2,a1 a2 a3,a1 a2 a3 a4,a1,a2,a3,a,a5).So i will be continue upto 17. and there are lot of values of "a".I just want to write "W,and i" and it will automatically generate value of "p2"

for a2=a1:W

for a3=a2:W

for a4=a3:W

for a5=i-a4-a3-a2-a1;

if(a4 <= a5 && a5<=W)

p2=[p2;a1,a2,a3,a4,a5];

end

end

end

end

end

end

Here if a1=1 then a2=1,2,3, if a1=2 then a2=2,3 and if a1=3 then a2=3. The same condition is for a3 & a4. Now I want to make this program only depends on "W" and "i" and I don't want to write a1,a2,a3,a4,a5.Because i need to run this code for i=4 and for a=2:4(a1 a2,a1 a2 a3,a1 a2 a3 a4)and again for i=5 and for a=2:4(a1 a2,a1 a2 a3,a1 a2 a3 a4,a1,a2,a3,a,a5).So i will be continue upto 17. and there are lot of values of "a".I just want to write "W,and i" and it will automatically generate value of "p2"

Expert's answer

#### Not answered

Need a fast expert's response?

Submit orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment