Create a for loop using fminsearch
4 次查看(过去 30 天)
显示 更早的评论
I am creating a matlab code that utilizes fminsearch over a number of guesses for initial variables (3 variables total, 10 guess). I have created an array of guesses, i.e. a 10x3 matrix with each row representing one iteration (1,1 = var1, 1,2 = var2, 1,3 = var3). I have run the code with nominal values and a single iteration works, but I don't know how to incorporate the for loop with fminsearch. The objective function is elusive to me. In this particular problem, second order differential equations are solved for each set of variables, and then a corresponding statistical value is calculated for each case. When creating the objective function to use for fminsearch, should I put my for loop within the main script, or in the objective function? Additionally, since the objective function can only take one variable array, and I have recently been told it is nothing but a placeholder, should I define my variables within the objective function? An example of using a for loop with fminsearch using ode45 and how to choose the proper objective function would be very helpful. I understand that the objective function is the function I want to minimize, however the function I want to minimize (which is a statistical value sigma), depends on a number of other functions. Any help appreciated. Apologize if this is a poor description. Also, please do not suggest using the optimization toolbox, I need to solve this strictly using code. Thanks!
0 个评论
回答(2 个)
Chibuzo Nnonyelu
2016-4-21
If I understand your question correctly, you want to be able to run the fminsearch for each initial guess at the time time?
Well, you can use the parfor and make sure to have every variable you need inside the parfor loop.
However, parfor loop does not allow the creation of figures inside the loop.
My suggestion is that you use the optimtool and export the code after entering the details in the optimtool GUI. You can format the code as a function and run inside the parfor loop.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Quadratic Programming and Cone Programming 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!