Is there anyway I can use arrayfun and GlobalSearch at the same time?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Simran
el 29 de Abr. de 2025
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 comentarios
Ver también
Categorías
Más información sobre Linear Least Squares en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!