[Engineering Optimization] One-dimensional search method and Engineering Optimization search

Source: Internet
Author: User

[Engineering Optimization] One-dimensional search method and Engineering Optimization search

One-dimensional search methods are classified as follows:

This article mainly explains Golden division, binary division, Newton MethodThese three one-dimensional search methods. The golden division method only applies to the original function. The bipartite Division uses the first-order derivation of the function, and the Newton method uses the second-order derivation of the function. Because this article mainly implements some of the algorithms in the course of the previous semester, The theoretical part is mostly based on the courseware of the course.. Golden Division Basic concepts:



Algorithm idea:




The algorithm flowchart and advantages and disadvantages are as follows:



Bipartite Basic Idea:



Newton's method Basic Idea:




Algorithm flowchart:


Specific implementation: the specific implementation of the program is as follows, In the program, we set the original functions to both f (x) = sinx/x, and the search areas to []. In the Newton method, we assume that the initial value is set to 1. The specific procedure is as follows::
# Include <stdio. h> # include <math. h>/******************* Function Definition, first-order and second-order derivative modules BEGIN **** *********************//***************** * *********** \ input: x is the output of independent variables: * Function value \ *****************************/double Function (double x) {return (x-0.5) * (x-0.5); // enter the function f (x) Here ), modify according to your function}/***************************** \ input: x is the output of independent variables: the first-order derivative value \ ****************************/double corresponding to the x independent variable derivative (double x) // obtain the first derivative of the function {double eps = 0.0000001; // precision control double dx = 0.5; // set the initial interval, which is too large to be iterated multiple times, too small precision double dy = Function (x + dx)-Function (x); // incremental double dd1 = dy/dx; // derivative double dd2 = 0; // The derivative dx = dx/2 when dx changes; // the incremental dy = Function (x)-Function (x + dx) of x is continuously reduced ); dd2 = dy/dx; // calculate the new derivative value while (abs (dd1-dd2)> eps) // terminate the iteration when the derivative value of the adjacent two times is smaller than the accuracy, get the derivative {dd1 = dd2; dx = dx/2.0; dy = Function (x + dx)-Function (x); dd2 = dy/dx;} return dd2 ;} // evaluate the second derivative of a function, which is the same as the principle of first derivative, you only need to replace the Function used to evaluate the Function value with the Function Derivative /********************** * ****** \ input: x is the output of independent variables: second-order derivative value \ ***************************/double Derivative2 (double x) {double eps = 0.00000001; double dx = 0.5; double dy = Derivative (x + dx)-Derivative (x); double dd1 = dy/dx; double dd2 = 0; dx = dx/2; dy = Derivative (x)-Derivative (x + dx); dd2 = dy/dx; while (abs (dd1-dd2)> eps) {dd1 = dd2; dx = dx/2.0; dy = Derivative (x + dx)-Derivative (x); dd2 = dy/dx;} return dd2 ;} /****************** Function Definition, first-order and second-order derivative module END ****** *******************//******************* * *********************** \ input: a and B are the upper and lower limits of the interval, and n is the maximum number of iterations output: print the minimum value of the function and the corresponding independent variable x \******************************* * *********/void GoldenSection (double, double B, int n) // gold division {double l = a + 0.382 * (B-a); double h = a + 0.618 * (B-); double region = B-a; double fl; double fh; int num = 1; // number of iterations while (region> 0.0000000001 & num <n) {fl = Function (l); fh = Function (h); if (fl> fh) {a = l; l = h; h = a + 0.618 * (B-a);} else {B = h; h = l; l = a + 0.382 * (B-a);} num ++; region = abs (B-a);} if (num = n) printf ("minimum value not found"); else {printf ("golden division method: when x = % f, minimum f (x) = % f ", (a + B)/2, Function (a + B)/2 ));}} /*************************************** * ** \ input: the upper and lower limits of a and B are output: print the minimum value of the function and the corresponding independent variable x \******************************* * *********/void Dichotomy (double, double B) // bipartite {double eps = 0.0000001; double x = (a + B)/2; double region = B-a; double fxDerivative = Derivative (x ); while (region> 0.0000001 & abs (fxDerivative)> eps) {fxDerivative = Derivative (x); if (fxDerivative> eps) B = x; if (fxDerivative <-eps) a = x; x = (a + B)/2; region = abs (B-a);} printf ("\ n bipartite: x = % f, f (x) = % f \ n ", x, Function (x ));} /*************************************** * ** \ input: a and B are the upper and lower limits of the interval, and x1 is the output of the initial value: print the minimum value of the function and the corresponding independent variable x \******************************* * *********/void Newton (double, double B, double x1) {double eps = 0.0000001; double x = x1; double d1 = Derivative (x1); // Level 1 Derivative double d2; // Second-Order guided while (abs (d1)> eps) {d2 = Derivative2 (x); if (d2 <0) printf ("second-order guided less than 0, cannot be solved "); else {x = x-d1/d2; // x iteration formula d1 = Derivative (x) ;}} printf ("\ n Newton method: x = % f, f (x) = % f \ n ", x, Function (x);} void main () {GoldenSection (100000,); // The Golden Splitting Method Dichotomy ); // bipartite Newton (0, 1); // Newton method}

The running result is as follows:



Original article: http://blog.csdn.net/tengweitw/article/details/43488767

Author: nineheadedbird


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.