Minimize \(f(x) = \sin (x) + \sin (\sqrt{2}x)\) on the interval \([0, 100]\) using \(n=100000\) points. Then use (30.2.2) to estimate the true global minimum of \(f\) on this interval.
Solution.
f = @(x) sin(x) + sin(sqrt(2)*x);
a = 0;
b = 100;
n = 100000; % number of points
x = linspace(a, b, n);
y = f(x);
[fm, ind] = min(y);
fprintf('Minimum %g attained near %g \n', fm, x(ind));
The output is “Minimum -1.99306 attained near 29.9413”. To estimate the accurac, note that \(|f'(x)|\le 1+\sqrt{2}\approx 2.4\) everywhere, and that \(h = (100-0)/(10^6 - 1)\approx 10^{-4}\text{.}\) So \(Mh/2 \approx 0.00012\) and therefore, the true global minimum of \(f\) lies between \(-1.99306 - Mh/2 = -1.99218\) and \(-1.99306\text{.}\)
