Abstract. The method of onedimensional optimization is explained in the context of capillarygravity waves.
1. Introduction.
R provides functions for both onedimensional and multidimensional optimization. The second topic is much more complicated than the former (see e.g. Nocedal 1999) and will be left for another day.
A convenient function for 1D optimization is optimize()
, also known as optimise()
. Its first argument is a function whose minimum (or maximum) is sought, and the second is a twoelement vector giving the range of values of the independent variable to be searched. (See ?optimize
for more.)
2. Application.
As an example, consider the phase speed of deep gravitycapillary waves, which is given by where is the frequency and is the wavenumber, and the two are bound together with the dispersion relationship , where is the acceleration due to gravity, is the surface tension parameter (0.074 N/m for an airwater interface) and is the water density (1000 kg/m^3 for fresh water). This yields wave speed given by the following R function.
phaseSpeed < function(k) { g < 9.8 sigma < 0.074 # waterair rho < 1000 # fresh water omega2 < g * k + sigma * k^3/rho sqrt(omega2)/k }
Readers with a background in the topic of waves may know that there is a minimum phase speed at wavelengths of about 0.02m, or a wavenumber of roughly 300. It always makes sense to plot a function to be optimized, if only to check that it has been coded correctly, so that's the next step. We’ll use a range of half an order of magnitude (factor of 3) smaller and larger .
k < seq(100, 1000, length.out = 100) par(mar = c(3, 3, 1, 1), mgp = c(2, 0.7, 0)) plot(k, phaseSpeed(k), type = "l", xlab = "Wavenumber", ylab = "Phase speed")
The results suggest that the range of illustrated in the diagram contains the minimum, so we provide that to optimize()
.
o < optimize(phaseSpeed, range(k)) phaseSpeed(o$minimum)
## [1] 0.2321
This speed is not especially fast; it would take about a heartbeat to move past your hand. (Or, about as fast as the waves that pulse your heart … presumably with different physics, though!)
3. Exercises
 Use
str(o)
to learn about the contents of the optimized solution. 
Use
abline()
to indicate the wavenumber at the speed minimum. 
Try other functions that are of interest to you.

Use the multidimensional optimizer named
optim()
on this problem.
References
Jorge Nocedal and Stephen J. Wright, 1999. Numerical optimization. Springer series in operations research. New York, NY, USA.