Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Max with variable number of inputs' topicStudent Support Forum > General > Archives > "Max with variable number of inputs"

< Previous Comment | Next Comment >Help | Reply To Comment | Reply To Topic
Author Comment/Response
toen
02/22/12 09:22am

g'day Dave,

I'd do the following:

fn[t_] := Product[(1 - t[[i]]), {i, 1, Length@t}];

maxFn[vectorLength_] :=

Module[{x, vars = Array[x, vectorLength], constraints},
constraints = ((0 <= # <= 1) & /@ vars)~Join~{Plus @@ vars == 1};
Maximize[{fn[vars], constraints}, vars]]

This will take quite a while to run for all but the smallest vector lengths, see for example:

Table[Timing[maxFn[j]], {j, 1, 5}]

cheers,
toen

URL: ,

Subject (listing for 'Max with variable number of inputs')
Author Date Posted
Max with variable number of inputs Dave Gaebler 02/21/12 12:08pm
Re: Max with variable number of inputs toen 02/22/12 09:22am
Re: Re: Max with variable number of inputs Dave Gaebler 03/06/12 10:59am
< Previous Comment | Next Comment >Help | Reply To Comment | Reply To Topic