Optimizing parameters without specifying them (Mathematica)

  • Context: Mathematica 
  • Thread starter Thread starter yourgoldteeth
  • Start date Start date
  • Tags Tags
    Mathematica Parameters
Click For Summary
SUMMARY

The discussion focuses on optimizing parameters in Mathematica using the NMinimize function without manually specifying them for different vector sizes. The user seeks a method to automate the declaration of parameters based on the vector's dimensions, utilizing anonymous variables or dynamically generated parameter names. The provided solution involves a custom function, myNMinimize, which constructs parameter names programmatically and successfully returns optimized values for the specified parameters.

PREREQUISITES
  • Familiarity with Mathematica programming
  • Understanding of optimization techniques in computational mathematics
  • Knowledge of NMinimize function in Mathematica
  • Basic concepts of variable manipulation and dynamic variable creation
NEXT STEPS
  • Explore advanced features of NMinimize in Mathematica
  • Learn about dynamic variable creation in Mathematica
  • Investigate the use of anonymous variables in Mathematica
  • Study optimization of multi-dimensional functions in Mathematica
USEFUL FOR

Mathematica users, data scientists, and researchers involved in optimization tasks who require dynamic parameter handling in their computations.

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:

Similar threads

  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 6 ·
Replies
6
Views
5K