Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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:

NMaximize[{F[data,a1,a2],a1>0,a2>0},{a1,a2}]

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

NMaximize[{F[data,a1,a2,a3],a1>0,a2>0,a3>0},{a1,a2,a3}]

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

share|improve this question

1 Answer 1

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

 
discard

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.