Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to use NMaximize to find the maximum value of a function with multiple variables. The problem is I would like to set this up so the number of variables is only decided when the function sees the data. So I have:


when there are data from two genes. But would like the function to be


if there are 3 genes...etc Any way to set this?

share|improve this question

Does this do what you want?

func[syms__Symbol] := NMaximize[{F[data, syms], Thread[{syms} > 0]}, {syms}]

func[q, r, s, t]
NMaximize[{F[data, q, r, s, t], {q > 0, r > 0, s > 0, t > 0}}, {q, r, s, t}]
share|improve this answer
Thanks for this. I've almost got it to work using pList = Table[Symbol["a"<>ToString[i]],{i,1,n}] to generate my list of variables, but there's a complication I'm still working on. – user6799 Apr 10 '13 at 16:48
@user6799 Can I help with whatever that complication is? – Mr.Wizard Apr 12 '13 at 18:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.