Fastest way to minimize a function
Show older comments
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 Comments
Sean de Wolski
on 10 Feb 2012
fmincon() or ga() could both be your friends.
K E
on 10 Feb 2012
Sean de Wolski
on 10 Feb 2012
ga is definitely not faster, fmincon might be but probably not. But they're significantly more powerful.
Accepted Answer
More Answers (0)
Categories
Find more on Linear Least Squares in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!