Student Support Forum: 'For loop in Maximize function' topicStudent Support Forum > General > "For loop in Maximize function"

 < Previous Comment Help | Reply To Comment | Reply To Topic
 Author Comment/Response Bill Simpson 02/24/13 6:54pm I think I understand the urge to use For[]. This doesn't show you how to do that, but perhaps you can see how to use this to get the answer you need. In[1]:= n=4; In[2]:= Total[Table[x[i],{i,1,n}]] Out[2]= x[1]+x[2]+x[3]+x[4] In[3]:= Total[Table[x[i],{i,1,n}]]<100 Out[3]= x[1]+x[2]+x[3]+x[4]<100 In[4]:= Total[Table[i*x[i],{i,1,n}]]<100n Out[4]= x[1]+2 x[2]+3 x[3]+4 x[4]<400 and In[5]:= Table[x[i],{i,1,n}] Out[5]= {x[1],x[2],x[3],x[4]} Now assemble pieces like that into Maximize In[6]:= Maximize[ { Total[Table[x[i],{i,1,n}]], Total[Table[x[i],{i,1,n}]]<100, Total[Table[i*x[i],{i,1,n}]]<100n }, Table[x[i],{i,1,n}] ] From In[6]:= Maximize::wksol : Warning: There is no maximum in the region described by the contraints; returning a result on the boundary. Out[6]= {100,{x[1]->100,x[2]->0,x[3]->0,x[4]->0}} Perhaps with your actual function n, the function you wish to maximize and your constraints it will not give you a warning and will give the solution you are looking for. But if you are really asking "given some arbitrary n that I will not tell you find me a maximum" then I do not believe Mathematica will likely do that. URL: ,

 Subject (listing for 'For loop in Maximize function') Author Date Posted For loop in Maximize function Wei Zhao 02/23/13 10:18am Re: For loop in Maximize function Bill Simpson 02/24/13 6:54pm
 < Previous Comment Help | Reply To Comment | Reply To Topic