Speeding up the fminbnd function
이전 댓글 표시
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.
채택된 답변
추가 답변 (1개)
Torsten
2015년 5월 22일
0 개 추천
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
Walter Roberson
2015년 5월 23일
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
2015년 5월 26일
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.
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!