In this post, apply the golden-section search method to an example, as discussed in the previous post(142_Golden-Section Search). Since the method is straightforward, today's post will be brief.
Use the golden-section search method to find the maximum value of a function, setting ${x_l}=0$ and ${x_u}=4$.
First, create two internal points using the golden ratio.
Calculate the function values at the two internal points as follows.
Since $f({x_2})$ is greater than $f({x_1})$, the maximum value lies within the interval defined by ${x_l}$, ${x_2}$ and ${x_1}$. Therefore, in the new interval, the lower bound remains ${x_l}=0$, and ${x_1}$ becomes the new upper bound, setting ${x_u}=2.472$. The previous value of ${x_2}$ becomes the new ${x_1}$, which is ${x_1}=1.528$. Also, since $f({x_1})$ was calculated in the previous iteration, there is no need to recalculate it. Thus, only the values of $d$ and ${x_2}$ need to be computed.
Since the function value at ${x_2}$ is $1.531$, which is less then the function value at ${x_1}$, the maximum value is within the interval defined by ${x_2}, {x_1}$, and ${x_u}$. Therefore, the process repeats as follows.
fun = @(x) 2*sin(x) - (x^2)/10;
g = @(x) -fun(x);
x1 = 0;
x2 = 4;
x_max = fminbnd(g,x1,x2)
We can simply implement this using MATLAB's built-in function "fminbnd", and because it is a maximum value, the sign was changed through $g$. The x_max value is 1.4257, and the function value at this point is 1.7757.
'Numerical Methods' 카테고리의 다른 글
145_Newton's Method (0) | 2024.04.23 |
---|---|
144_Parabolic Interpolation (0) | 2024.04.22 |
142_Golden-Section Search (0) | 2024.04.20 |
141_Gauss-Seidel Method (1) | 2024.04.19 |
140_Cholesky Decomposition (0) | 2024.04.18 |