Speeding up the fminbnd function
Mostra commenti meno recenti
Hi!
I have a function of T as,
CV_inf = @(T) T.*(4/(n+1)) - integral(@(t) psitildasq(t),(-T),(T),'Arrayvalued',true);
where
psitildasq = @(t) (1/n^2)*(sum(cos(x*t))).^2 + (1/n^2)*(sum(sin(x*t))).^2;
x is a (1*n) vector of inputs.
I want to find the global minimum as well as the first(smallest) local minimum of this function.
To find the global minimum I use
[Tinf,Tinf_val,Tinf_exitflag,output] = fminsearch(CV_inf,0);
and to find the local minimum I follow this method,
[Tloc1,Tloc1_val,Tloc1_exitflag] = fminbnd(CV_inf,0,Tinf);
g = Tinf - Tloc1;
if g <= 0.0001
Tloc = Tinf;
Tloc_val = Tloc1_val;
Tloc_exitflag = Tloc1_exitflag;
else
while g > 0.0001
[Tloc,Tloc_val,Tloc_exitflag] = fminbnd(CV_inf,0,Tloc1);
g = Tloc1 - Tloc;
Tloc1 = Tloc;
end
end
But when I have a large dataset like n=10000, the code seems to run forever. Could there be a possibility of speeding up the process?
Thanks.
Risposta accettata
Più risposte (1)
Torsten
il 22 Mag 2015
0 voti
You could take the first derivative of your function CV_inf with respect to T, set the derivative to 0 and solve for T.
That way no integration is required in your calculation.
Best wishes
Torsten.
2 Commenti
Walter Roberson
il 23 Mag 2015
You will, though, need to solve for all of the 0's and use the derivative to classify them. As they are trig functions, there is a risk of an infinite number of roots, though one might be able to establish a period for them. The differences between x values act as phase shifts, so as long as the x values can all be expressed as rational numbers, you can find a LCM (Least Common Multiple) of the numbers, multiply by 2*Pi, and that should be the period for the entire psitildasq. But then the additive T of CV_inf ... ah yes, as you can put an upper bound on the sum of n cosines (or n sines), you can put bounds on the range of psitildasq... muse, muse, muse
Torsten
il 26 Mag 2015
I don't think a minimizer works more efficient on a function with several local minima than a root finder on its derivative.
Best wishes
Torsten.
Categorie
Scopri di più su Creating and Concatenating Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!