Fastest way to minimize a function
이전 댓글 표시
I have to perform many minimizations of a function, so I want to do it quickly. Here is the problem: given different values of T, the minimization should find L = ((g*T^2)/(2*pi))*tanh(2*pi*D/L) where g and D are constants. Below is how I am doing it, but is there a faster way?
g = 9.8066 ;
D = 50 ;
periodList = linspace(3, 15, 100) ;
fh = @(L,T) (L-((g*T.^2)/(2*pi))*tanh(2*pi*D/L)) ; % Handle to L as a function of T
for iPeriod = 1:length(periodList)
T = periodList(iPeriod) ;
guessL = g*(T^2)/(2*pi) ; % Initial guess at L
L(iPeriod) = fzero(@(L) fh(L, T), guessL) ;
end
Since this problem is finding the wavelength L of water waves given the wave period T and water depth D, there are some constraints on the problem: L must always be positive with a nominal solution accuracy of +/-1 meter, the period T will lie between 0 and ~20 seconds, and the water depth D ranges from ~10 to 1000 meters. g is the acceleration due to gravity, so it will always be 9.8066 m/s^2.
댓글 수: 3
Sean de Wolski
2012년 2월 10일
fmincon() or ga() could both be your friends.
K E
2012년 2월 10일
Sean de Wolski
2012년 2월 10일
ga is definitely not faster, fmincon might be but probably not. But they're significantly more powerful.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Linear Least Squares에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!