Minimizing one variable function with different parameters, time-efficient solution
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Babak
le 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?
Réponses (1)
Matt J
le 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 commentaires
Voir également
Catégories
En savoir plus sur Statistics and Machine Learning Toolbox dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!