Speed up fminbnd using vectorization
조회 수: 3 (최근 30일)
이전 댓글 표시
I am trying to optimize this piece of code. I am using the function fminbnd on a vector, splitting the task on its single entries using a loop.
Would it be possible to speed it up vectorizing the process?
for i = 1:A
for ii= 1:B
for iii = 1:C
fun = @(x) (x * variable(i,ii,iii))^2 ;
[arg_min(i,ii,iii), min_(i,ii,iii)] = fminbnd(fun,0,2);
end
end
end
Thanks for the attention.
Sincerely
Luca
댓글 수: 0
채택된 답변
Matt J
2017년 8월 12일
In your example, the solution is always x=0, so a trivial vectorized solution would be
arg_min=zeros(A,B,C);
min_ = arg_min;
More generally, no, vectorization will not help in a situation like this. You could consider parallelizing the loop using PARFOR.
댓글 수: 0
추가 답변 (2개)
Nick Durkee
2018년 5월 24일
편집: Matt J
2018년 5월 24일
I actually developed a solution to this problem for my research. It's available on the file exchange.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!