Is there anyway I can use arrayfun and GlobalSearch at the same time?
2 次查看(过去 30 天)
显示 更早的评论
Hello,
I am trying to use GlobalSearch but not sure how to implement it.
Sol = arrayfun( @(v,w,x) fminsearchbnd(@(cv) -valfunc1(c2,v,w,x,cv(1),cv(2),param,glob), [10;10], [glob.kmin;glob.dmin], [60;60]), s(:,1), s(:,2), s(:,3), 'UniformOutput', false);
I used to get code as above. So Sol(1) give me the minimizer 'cv' given s(1,1) s(1,2) s(1,3). Sol(2) gives me the minimizer given s(2,1) s(2,2) s(2,3)....
So if s(:,1) is 10*1 column (same as s(:,2),s(:,3)), then the Sol should give me 10*2 matrix of solutions.
I would like to use GlobalSearch instead of fminsearch.
I found out that the code for GlobalSearch should look like as follows
gs = GlobalSearch;
obj = @(cv)-valfunc1(c2,v,w,x,cv(1),cv(2),param,glob);
problem = createOptimProblem('fmincon','x0',[0 0],...
'objective',obj,'lb',[-20 2],'ub',[60 60]);
x = run(gs,problem);
I also want to use arrayfun to get the solution as a vector(10*2).
However, I am not sure how to use arryfun in this case.
So I was wondering if it is possible to use GlobalSearch and still use arrayfun at the same time.
Thanks in advance.
0 个评论
回答(1 个)
Simran
2025-4-29
You can use the “GlobalSearch” with “arrayfun” in MATLAB, just like you did with “fminsearchbnd”.
The key is to put all the code that sets up and runs the “GlobalSearch” optimization into a function of its own.
Then you can use the “arrayfun” function to call the previous function for each set of parameters you want to optimize.
That particular section of the code should be written as follows:
gs = GlobalSearch;
run_gs = @(v, w, x) ...
run(gs, createOptimProblem('fmincon', ...
'x0', [10 10], ...
'objective', @(cv) -valfunc1(c2, v, w, x, cv(1), cv(2), param, glob), ...
'lb', [glob.kmin, glob.dmin], ...
'ub', [60, 60]));
Sol = arrayfun(@(i) run_gs(s(i,1), s(i,2), s(i,3)), 1:size(s,1), 'UniformOutput', false);
For more information refer to the below documentation links:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear Least Squares 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!