Matlab code, one-dimensional search and retreat method to determine the search interval

Source: Internet
Author: User

In the use of two-dimensional optimization algorithm, it is often necessary to call one-dimensional search algorithm to find the step, while one-dimensional search algorithm needs to determine the search interval. The method can not only be used as a one-dimensional search algorithm, but also can be used to determine the one-dimensional searching interval.

The principle of the search interval determined by the Retreat method is:

Suppose the one-dimensional objective function is a single-peak function, the initial point x0, the step h, and the iteration point x1= x0+h. The Lamda initial value is set to 1.

(1) if f (x0) > F (x1), then x2=x1+lamda*h. Find a Lamda, make F (x2) > F (x1), Output search interval [x1, X2].

(2) if f (x0) <= F (x1), then x2=x1-lamda*h. Find a Lamda, make F (x2) > F (x0), output search interval [x2, x0].


Individuals think only to determine the search interval, the step value will not be reduced, has been enlarged. The MATLAB code is as follows:

function [LOW,UP]=MINJT (fun,x0,h)
% fun is an anonymous function

lamda=1;
X1=x0;x2=x0+h;

If Fun (x1) >fun (x2)
    x_panduan=x2;
    While 1
        x1=x2;x2=x1+lamda*h;
        Lamda=1.1*lamda;
        If Fun (x2) >fun (X_panduan) break
            ;
        End
    End
else
    x_panduan=x1;
    While 1
        x1=x2;x2=x1-lamda*h;
        Lamda=1.1*lamda;
        If Fun (x2) >fun (X_panduan) break
            ;
        End
    End
End

low=min (X_PANDUAN,X2);
Up=max (X_PANDUAN,X2);

End

For example:

[Low,up]=minjt (@ (x) x^4-x^2-2*x-5,0,0.1)

Output:

Low =
0.1000

up =
1.6937

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.