Mathematica 9 is now available
Student Support Forum
Student Support Forum > General > > "For loop in Maximize function"

Post Reply:
Email Address:

Please send email when my message is replied to.

Url (optional):
Message: view original message?
Attachment (optional):
Please answer this:5+3 =

Original Message (ID '364682') By Bill Simpson:
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.