The Quadratic Interpolation Method of MATLAB Unconstrained One-Dimensional Extreme Value

1. Algorithm principle

Set the curve F (x) and find its extreme value interval [x1, x2], so that it satisfies f (x1)> f ((x1 + x2) / 2), f ((x1 + x2) / 2) <f (x2), use the values ​​of these three points to fit a parabolic equation

f (x) = ax ^ 2 + bx + c, abc is the coefficient.

ax1^2+bx1+c=f(x1)
ax2^2+bx2+c=f(x2)

ax3^2+bx3+c=f(x3)

Written in matrix form

x1^2 x1  1         a         f(x1)

x2^2 x2  1    *    b    =   f(x2)

x3^2 x3  1         c          f(x3)

Simplified to vander (x1 x2 x3) * [abc] '= [f (x1) f (x2) f (x3)]'

After using Matlab to find the expression, find the minimum point xp of f (x).

Determine the value of f (xp) and f ((x1 + x2) / 2)

If f (xp)> f ((x1 + x2) / 2) 1, xp <(x1 + x2) / 2 <x2, the new interval is [xp, x2];

                                  2. (x1 + x2) / 2 <xp <x2, then the new interval [x1, xp]

If f (xp) <f ((x1 + x2) / 2) 1, x1 <xp <(x1 + x2) / 2, then the new interval is [x1, (x1 + x2) / 2];

                                  2. (x1 + x2) / 2 <xp <x2, then the new interval [(x1 + x2) / 2, x2];

The principle is to ensure that the value of the function is distributed in a high degree, and iterate continuously.

 

 

Second, the matlab program

clc
clear
f=@(x) x.^3-6*x+9;
ezplot(f,[-100 100])
[x,fx]=Min_erci(f,[0 5],100)  % a 函数值  b横坐标
function [x,result]=Min_erci(f,x0,k) %x0为初始区间端点,k为迭代次数

x1=x0(1);
x3=x0(2);
x2=(x1+x3)/2;

n=1;
while n < k
    % 确定抛物线的系数
    f1=f(x1);
    f2=f(x2);
    f3=f(x3);
    A=[x1^2    x1   1;
       x2^2    x2   1;
       x3^2    x3   1;];
   b=[f1;f2;f3];
   XS=A\b;  %求出抛物线系数a b c 存放在xs中
   xp=-XS(2)/(2*XS(1)); %二次多项式的极值点在x=-b/2a
   fp=f(xp); %求出该点函数值
   if abs(xp-x2) < 1e-8  %该点满足极值点条件
       x=xp;        %输出极值点
       result=f(x); %输出函数值
       return;
   end
   if fp > f2       %判断新的迭代区间
       if xp < x2
           x1=xp;
       else
           x3=xp;
       end
   else
       if xp < x2
           x3=x2;
           x2=xp;
       else
           x1=x2;
           x2=xp;
       end
   end
    n=n+1;   %迭代次数+1
end

if n == k        %如果超出迭代次数
    x=[];        %输出空    
    result=[];
    disp('超过迭代次数');
end
end

 

Published 10 original articles · praised 8 · visits 75

Guess you like

Origin blog.csdn.net/STM89C56/article/details/105464896