% One-dimensional search method
CLC;
Clear all;
Close all;
X =-. 0;
Y = 3 * X. ^ 2-4. * x + 2;
Plot (X, Y, 'r-. ', 'linewidth', 2 );
Hold on
% Initialization
X0 = 0; % initial value;
K = 1; % initial step size;
LL = 0.002; % termination condition
Amin =-1;
Bmax = 1;
Lamda = 0.382;
X1 = Amin + Lamda * (Bmax-AMIN );
X2 = Amin + (1-Lamda) * (Bmax-AMIN );
Fx1 = fun_f (X1 );
Fx2 = fun_f (X2 );
P1 = line ([X1, X1], [0, fx1], 'linewidth', 2 );
% Hold on
P1 = line ([X2, x2], [0, fx2], 'linewidth', 2 );
C = [];
% Start of Search
While Bmax-Amin> LL
If fx1> fx2
Amin = x1;
% Bmax = Bmax;
X1 = x2;
Fx1 = fx2;
X2 = Amin + (1-lamda) * (Bmax-AMIN );
Fx2 = fun_f (X2 );
Else
% Amin = Amin;
Bmax = x1;
X2 = x1;
Fx2 = fx1;
X1 = Amin + Lamda * (Bmax-AMIN );
Fx1 = fun_f (X1 );
End
P1 = line ([X1, X1], [0, fx1], 'linewidth', 2 );
% Hold on
P1 = line ([X2, x2], [0, fx2], 'linewidth', 2 );
K = k + 1;
C = [C; [Amin, Bmax, x1, x2, fx1, fx2];
End
Function FX = fun_f (X)
FX = 3 * x ^ 2-4 * x + 2;
End
One-dimensional search