Optimizing parameters without specifying them (Mathematica)

  • Context: Mathematica 
  • Thread starter Thread starter yourgoldteeth
  • Start date Start date
  • Tags Tags
    Mathematica Parameters
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 2K views
yourgoldteeth
Messages
9
Reaction score
0
I use NMinimize to optimize a likelihood function. The number of parameters included depends on the dimensions of a vector I pass. I would like to have Mathematica check the dimensions of the vector, declare the correct number of parameters for me, and then solve for them.

Right now, I have to hard code my notebook for each different size of vector I hand it. Is there anyway to have Mathematica either use anonymous variables, or declare parameter1, parameter2... parameterN variables for me, automatically, and use them?

Thanks
 
Physics news on Phys.org
myNMinimize[f_,n_]:=NMinimize[f,Table[ToExpression["parameter"<>ToString],{i,1,n}]]

Then
myNMinimize[(parameter1-3)^2+2(parameter2+1)^4+parameter3^2,3]
returns
{parameter1->3., parameter2->-1., parameter3-> 0.}
 
Last edited: