Minimizing one variable function with different parameters, time-efficient solution
5 views (last 30 days)
Show older comments
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 Comment
Babak
on 24 Sep 2012
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?
Answers (1)
Matt J
on 30 Sep 2012
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 Comments
See Also
Categories
Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!