Minimizing one variable function with different parameters, time-efficient solution
5 次查看(过去 30 天)
显示 更早的评论
Hello,
I want to minimize a one variable function f(x) for different values of one parameter a. I found this solution:
function y=f(x,a)
y=abs(phi(x))+(x-a).^2; % phi is a differentiable function
end
-----------------
eps=0.2
for i=1:size(a,1)
xmin=fminbnd(@(x)f(x,a(i)),a(i)-eps,a(i)+eps); % we know the minimum is close to a
end
Vector a has more than 450000 values, so it takes an unacceptable computation time. Do you think there exists another more time-efficient solution?
Thank you in advance
1 个评论
Babak
2012-9-24
Are you looking to find xmin which is the same size as a?
In other words, xmin in your for loop is over-writing itself.
My understanding from your question is that you are looking for a curve of xmin(a) that for different values of a, gives you minimum values of the function g(x) = f(x,a). Am I right?
回答(1 个)
Matt J
2012-9-30
Do you expect xmin(i) to be close to xmin(i-1)? If so, you could do
eps=0.2;
xmin=nan(size(a)); %pre-allocate
xmin(1)=fminbnd(@(x)f(x,a(1)),a(1)-eps,a(1)+eps); %initialize
for i=2:size(a,1)
xmin(i)=fminsearch(@(x)f(x,a(i)),xmin(i-1));
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!