How to use fmincon in a loop
6 views (last 30 days)
Show older comments
Hello,
I am trying to use fmincon inside a for loop in such a way that the variable t can run from 1 to 517 while fmincon will be evaluated with variables that are indexed with t. Solutions should be saved each time in a matrix "output" that is 517x5 matrix. Apparently, I am unable to make it work. Here is example of my code:
output=zeros(517,5)
for t=1:517
e=1e-5
x0=[5 0.0503 0.05 0.15 -0.75];
lb = [e e e e -.999]; % Lower bounds for the parameter estimates
ub = [100 10 10 10 0]; % Upper bounds for the parameter estimates
output(t,:)= fmincon(@ObjFun,x0,[],[],[],[],lb,ub)
end
2 Comments
Roger Wohlwend
on 4 Aug 2014
Tell us please what kind of error you get. Where is the function ObjFun defined?
Answers (1)
Matt J
on 24 Aug 2014
Edited: Matt J
on 24 Aug 2014
Your question isn't entirely clear, but perhaps you are looking for this material
which talks about how to attach fixed data to an objective function. With these techniques, the objective function can be redefined in each loop iteration with new, loop-dependent fixed data.
0 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!