智能優化 之 下山單純形法 C++

 

單純形法簡介在其餘網站上均可以查到,我就很少說了html

咱們主要說方法函數

它主要解決的是局部最優解的問題網站

利用多邊形進行求解的,如有n個變量,則利用n+1邊形spa

咱們這裏以兩個變量爲例,求解第三維度的最優解3d

例如解決code

min  f(x,y)=x2 - 4*x + y2 - y - x*y
orm

 

matlab 圖htm

 

能夠看出,差很少是(3,2)附近取得最小對象

 

咱們來用下山單純形求解blog

 

咱們設立三個初始點 (0,0),(1.2,0),(0,0.8)

咱們把它們分別帶入f中,函數值越小的越接近解,咱們把它稱爲最好點,反之,函數值最大的點,咱們稱之爲最壞點

咱們要作的是,利用已知點,尋找更加接近解的點

咱們須要瞭解幾種尋找下一個點的思想

 

反射 reflect

 

假設三角形的三個點是ABP,其中P是最壞點,那麼咱們尋找一個Q點,使得APBQ是一個平行四邊形

設向量α爲p->A,β爲p->B    (假設1)

那麼Q = p + (α+β),其中p和Q是座標

 

擴張 extern

 

假設,咱們獲得的新點Q,它比原來三角形中最好的點還要好,那麼,咱們能夠假定這個探索方向是正確的,咱們不妨再往前走一步!

其中Q->R = (p->R)/2,咱們這裏稱擴張Q點

設向量α爲Q->A, β爲Q->B     (假設2)

因而,R =  Q - (α+β)/2

 

收縮 Shrink

我認爲收縮有兩種

由於咱們通常先作反射點,因此,以後的操做若是針對反射點,那麼就是對反射點進行收縮

基於(假設2),R = Q + (α+β)/4

 

還有一種是最優解原本就在三角形PAB中,咱們對P作收縮

基於(假設1),則Q = P + (α+β)/4

 

壓縮 compress

 

咱們認爲,若是上述操做均沒有找到更好的點來替代最壞點,那麼說明以前的三角形是非法的,那麼咱們進行壓縮操做

即,取兩邊中點與最壞點構成新的三角形

 

咱們用下山單純形法求解步驟以下:

求出初始點的最壞點,構成三角形

重複下述,直到知足精度

先作一次反射

  若是反射點比最好點還要好(更加接近條件:min f(x0,y0))->作一次擴張

    若是擴張點比反射點還要好->擴張點代替以前的最壞點,造成新的三角形

    反之->反射點代替以前的最壞點

  反之,若是反射點比最壞點還要壞->反射點作收縮1

    若是收縮點1比最壞點好->收縮點1代替最壞點

    反之->最壞點作收縮2

      若是收縮點2比最壞點好->收縮點2代替最壞點

      反之->三角形作壓縮

  反之,反射點代替最壞點,造成新的三角形

 

 

C++代碼:

triangle.h

#pragma once

#define stds std::

#define VEC2_OUT

#include "lvgm\lvgm.h"    //本人博客: https://www.cnblogs.com/lv-anchoret/category/1367052.html
#include <vector>
#include <algorithm>
using namespace lvgm;


class Mountain
{
public:
    typedef dvec2 valtype;

    typedef double(*_Fun)(const valtype&);

    Mountain() {    }

    /*
    p: three position coordinates(in ordered or not)
    f: the function Ptr
    δ: the solution precision
    */
    Mountain(const valtype& p1, const valtype& p2, const valtype& p3, const double δ)
        : _δ(δ)
    {
        _positions.resize(3);
        _positions[0] = p1;
        _positions[1] = p2;
        _positions[2] = p3;
        sort();
    }

    static void setF(_Fun f)
        {
        _f = f;
        }

    void setδ(double delt)
        {
        _δ = delt;
        }

public:

    /*
    origion: the bad position
    vec1: bad position -> min position
    vec2: bad position -> mid position
    */
    valtype reflect(const valtype& origion, const valtype& vec1, const valtype& vec2)
        {
        return origion + (vec1 + vec2);
        }

    /*
    origion: the change position
    vec1: change position -> left position
    vec2: change position -> right position
    */
    valtype shrink(const valtype& origion, const valtype& vec1, const valtype& vec2)
        {
        return origion + (vec1 + vec2) / 4;
        }

    /*
    origion: the origion position
    vec1: origion position -> left position
    vec2: origion position -> right position
    */
    void compression(const valtype& origion, const valtype& vec1, const valtype& vec2)
        {
        _positions[0] = origion + min(vec1, vec2) / 2;
        _positions[1] = origion + max(vec1, vec2) / 2;
        }
    
    /*
    origion: the change position
    vec1: change position -> left position
    vec2: change position -> right position
    */
    valtype exter(const valtype& origion, const valtype& vec1, const valtype& vec2)
        {
        return origion - (vec1 + vec2) / 2;
        }

    void go()
    {
        double delt = (_positions[2] - _positions[0]).normal();
        static int i = 0;
        while (delt > _δ)
        {
            stds cout << ++i << "" << _positions[0] << "\t" << _positions[1] << "\t" << _positions[2] << stds endl;
            valtype t = reflect(_positions[2], _positions[1] - _positions[2], _positions[0] - _positions[2]);
            if (_f(t) < _f(_positions[0]))
            {
                valtype ex = exter(t, _positions[1] - t, _positions[0] - t);
                if (_f(ex) < _f(t))
                    _positions[2] = ex;
                else
                    _positions[2] = t;
            }
            else if (_f(t) > _f(_positions[2]))
            {
                valtype sh = shrink(t, _positions[1] - t, _positions[0] - t);
                if (_f(sh) < _f(_positions[2]))        //反射點收縮
                    _positions[2] = sh;
                else    //三角內部內縮
                {
                    sh = reflect(sh, _positions[1] - sh, _positions[0] - sh);
                    if (_f(sh) < _f(_positions[2]))
                        _positions[2] = sh;
                    else    //針對原始點內縮,針對反射點收縮,都無論用,那麼選擇壓縮
                        compression(_positions[0], _positions[1] - _positions[2], _positions[0] - _positions[2]);
                }
            }
            else
                _positions[2] = t;
            sort();
            delt = (_positions[2] - _positions[0]).normal();
        }
        stds cout << "\n最好點爲" << _positions[0] << "\t精度爲:" << _δ << stds endl << "函數值爲:" << _f(_positions[0]) << stds endl << stds endl;
    }

protected:

    const valtype& min(const valtype& vec1, const valtype& vec2)
        {
        return _f(vec1) < _f(vec2) ? vec1 : vec2;
        }

    const valtype& max(const valtype& vec1, const valtype& vec2)
        {
        return _f(vec1) > _f(vec2) ? vec1 : vec2;
        }

    friend bool cmp(const valtype& pos1, const valtype& pos2)
        {
        return Mountain::_f(pos1) < Mountain::_f(pos2);
        }

    void sort()
        {
        stds sort(_positions.begin(), _positions.end(), cmp);
        }
    
private:

    stds vector<valtype> _positions;    //min, mid, max  or  good, mid, bad

    double _δ;

    static _Fun _f;
};

 

main.cpp(原錯誤版本

#include "triangle.h"

Mountain::_Fun Mountain::_f=[](const Mountain::valtype& v)->double    {    return 0.;    };

int main()
{
    auto fun = [](const Mountain::valtype& v)->double
    {
        return v.x()*v.x() - 4 * v.x() + v.y()*v.y() - v.y() - v.x()*v.y();
    };

    Mountain m(Mountain::valtype(0, 0), Mountain::valtype(1.2, 0), Mountain::valtype(0, 0.8), 0.1);

    m.setF(fun);

    m.go();

    m.setδ(0.01);

    m.go();

    m.setδ(0.001);

    m.go();

    m.setδ(0.0001);

    m.go();

    m.setδ(0.00001);

    m.go();

}

 

error:錯在初始化的時候寫了一個默認函數,建立對象以後才進行setF設置內部函數,致使第一個三角形在構造函數中第一次sort的時候,並無正確排序

 

咱們稍微改動一下:

main.cpp

#include "triangle.h"

Mountain::_Fun Mountain::_f
{ [](const Mountain::valtype& v)->double {    return v.x()*v.x() - 4 * v.x() + v.y()*v.y() - v.y() - v.x()*v.y();    } };

int main()
{
    Mountain m(Mountain::valtype(0, 0), Mountain::valtype(1.2, 0), Mountain::valtype(0, 0.8), 0.1);

    m.go();

    m.setδ(0.01);

    m.go();

    m.setδ(0.001);

    m.go();

    m.setδ(0.0001);

    m.go();

    m.setδ(0.00001);

    m.go();

    m.setδ(0.000001);

    m.go();
}

 

這樣咱們收斂地更好:

結果:

迭代次數    good    medium        bad
1次  [ 1.2, 0 ]         [ 0, 0.8 ]      [ 0, 0 ]
2次  [ 1.8, 1.2 ]       [ 1.2, 0 ]      [ 0, 0.8 ]
3次  [ 1.8, 1.2 ]       [ 3, 0.4 ]      [ 1.2, 0 ]
4次  [ 3.6, 1.6 ]       [ 1.8, 1.2 ]    [ 3, 0.4 ]
5次  [ 3.6, 1.6 ]       [ 2.4, 2.4 ]    [ 1.8, 1.2 ]
6次  [ 3.6, 1.6 ]       [ 2.4, 2.4 ]    [ 4.2, 2.8 ]
7次  [ 2.4, 1.6 ]       [ 3.6, 1.6 ]    [ 2.4, 2.4 ]
8次  [ 2.7, 2 ]         [ 2.4, 1.6 ]    [ 3.6, 1.6 ]
9次  [ 2.7, 2 ]         [ 3.075, 1.7 ]  [ 2.4, 1.6 ]
10次  [ 2.7, 2 ]        [ 3.375, 2.1 ]  [ 3.075, 1.7 ]
11次  [ 3.01875, 2.225 ]        [ 2.7, 2 ]      [ 3.375, 2.1 ]
12次  [ 3.11719, 2.10625 ]      [ 3.01875, 2.225 ]      [ 2.7, 2 ]
13次  [ 3.11719, 2.10625 ]      [ 3.01875, 2.225 ]      [ 3.25195, 2.24844 ]
14次  [ 3.11719, 2.10625 ]      [ 2.88398, 2.08281 ]    [ 3.01875, 2.225 ]
15次  [ 2.98242, 1.96406 ]      [ 3.11719, 2.10625 ]    [ 2.88398, 2.08281 ]
16次  [ 2.98242, 1.96406 ]      [ 3.11719, 2.10625 ]    [ 3.13271, 2.01133 ]
17次  [ 2.98242, 1.96406 ]      [ 2.96689, 2.05898 ]    [ 3.11719, 2.10625 ]

最好點爲[ 2.98242, 1.96406 ]    精度爲:0.1
函數值爲:-6.99903

18次  [ 2.98242, 1.96406 ]      [ 2.96689, 2.05898 ]    [ 2.90339, 1.96416 ]
19次  [ 2.98242, 1.96406 ]      [ 3.04592, 2.05889 ]    [ 2.96689, 2.05898 ]
20次  [ 2.98242, 1.96406 ]      [ 3.03781, 1.98772 ]    [ 3.04592, 2.05889 ]
21次  [ 3.02802, 2.01739 ]      [ 2.98242, 1.96406 ]    [ 3.03781, 1.98772 ]
22次  [ 3.02802, 2.01739 ]      [ 2.97263, 1.99373 ]    [ 2.98242, 1.96406 ]
23次  [ 3.00928, 2.02631 ]      [ 3.02802, 2.01739 ]    [ 2.97263, 1.99373 ]
24次  [ 2.99564, 2.00779 ]      [ 3.00928, 2.02631 ]    [ 3.02802, 2.01739 ]
25次  [ 2.99564, 2.00779 ]      [ 3.00928, 2.02631 ]    [ 2.98968, 2.01688 ]
26次  [ 2.99564, 2.00779 ]      [ 3.01524, 2.01722 ]    [ 3.00928, 2.02631 ]
27次  [ 3.0016, 1.9987 ]        [ 2.99564, 2.00779 ]    [ 3.01524, 2.01722 ]
28次  [ 3.0016, 1.9987 ]        [ 2.99564, 2.00779 ]    [ 2.982, 1.98927 ]
29次  [ 3.0016, 1.9987 ]        [ 3.00693, 2.01023 ]    [ 2.99564, 2.00779 ]
30次  [ 3.0016, 1.9987 ]        [ 3.00858, 2.0028 ]     [ 3.00693, 2.01023 ]

最好點爲[ 3.0016, 1.9987 ]      精度爲:0.01
函數值爲:-6.99999

31次  [ 3.0016, 1.9987 ]        [ 3.00417, 1.99601 ]    [ 3.00858, 2.0028 ]
32次  [ 3.0016, 1.9987 ]        [ 3.00417, 1.99601 ]    [ 2.99719, 1.99191 ]
33次  [ 3.0016, 1.9987 ]        [ 3.00573, 2.00008 ]    [ 3.00417, 1.99601 ]
34次  [ 3.0016, 1.9987 ]        [ 3.00316, 2.00277 ]    [ 3.00573, 2.00008 ]
35次  [ 2.99903, 2.00139 ]      [ 3.0016, 1.9987 ]      [ 3.00316, 2.00277 ]
36次  [ 2.99903, 2.00139 ]      [ 3.0016, 1.9987 ]      [ 2.99747, 1.99732 ]
37次  [ 3.00174, 2.00141 ]      [ 2.99903, 2.00139 ]    [ 3.0016, 1.9987 ]
38次  [ 3.00099, 2.00005 ]      [ 3.00174, 2.00141 ]    [ 2.99903, 2.00139 ]
39次  [ 3.00099, 2.00005 ]      [ 3.0002, 2.00106 ]     [ 3.00174, 2.00141 ]
40次  [ 2.99945, 1.9997 ]       [ 3.00099, 2.00005 ]    [ 3.0002, 2.00106 ]
41次  [ 2.99945, 1.9997 ]       [ 3.00024, 1.99928 ]    [ 3.00099, 2.00005 ]

最好點爲[ 2.99945, 1.9997 ]     精度爲:0.001
函數值爲:-7

42次  [ 2.99945, 1.9997 ]       [ 2.99927, 1.99921 ]    [ 3.00024, 1.99928 ]
43次  [ 2.99945, 1.9997 ]       [ 2.9998, 1.99937 ]     [ 2.99927, 1.99921 ]
44次  [ 2.99998, 1.99986 ]      [ 2.99945, 1.9997 ]     [ 2.9998, 1.99937 ]
45次  [ 2.99998, 1.99986 ]      [ 2.99945, 1.9997 ]     [ 2.99964, 2.00019 ]
46次  [ 2.99998, 1.99986 ]      [ 2.99976, 1.99957 ]    [ 2.99945, 1.9997 ]
47次  [ 2.99998, 1.99986 ]      [ 3.00008, 1.99972 ]    [ 2.99976, 1.99957 ]
48次  [ 2.99998, 1.99986 ]      [ 3.0003, 2.00001 ]     [ 3.00008, 1.99972 ]
49次  [ 2.99998, 1.99986 ]      [ 3.00021, 2.00014 ]    [ 3.0003, 2.00001 ]
50次  [ 2.99989, 1.99999 ]      [ 2.99998, 1.99986 ]    [ 3.00021, 2.00014 ]
51次  [ 3.00007, 2.00003 ]      [ 2.99989, 1.99999 ]    [ 2.99998, 1.99986 ]
52次  [ 3.00007, 2.00003 ]      [ 2.99998, 2.00009 ]    [ 2.99989, 1.99999 ]
53次  [ 3.00007, 2.00003 ]      [ 3.00009, 2.0001 ]     [ 2.99998, 2.00009 ]

最好點爲[ 3.00007, 2.00003 ]    精度爲:0.0001
函數值爲:-7

54次  [ 3.00007, 2.00003 ]      [ 3.00003, 2.00008 ]    [ 3.00009, 2.0001 ]
55次  [ 3.00001, 2.00001 ]      [ 3.00007, 2.00003 ]    [ 3.00003, 2.00008 ]
56次  [ 3.00001, 2.00001 ]      [ 3.00004, 2 ]  [ 3.00007, 2.00003 ]
57次  [ 3.00001, 2.00001 ]      [ 2.99998, 1.99998 ]    [ 3.00004, 2 ]
58次  [ 3.00001, 2.00001 ]      [ 2.99998, 1.99998 ]    [ 2.99997, 1.99999 ]
59次  [ 3.00001, 2.00001 ]      [ 3.00002, 2 ]  [ 2.99998, 1.99998 ]
60次  [ 3, 1.99999 ]    [ 3.00001, 2.00001 ]    [ 3.00002, 2 ]
61次  [ 3, 1.99999 ]    [ 3.00001, 2.00001 ]    [ 2.99998, 2.00001 ]
62次  [ 3, 1.99999 ]    [ 3.00001, 2 ]  [ 3.00001, 2.00001 ]

最好點爲[ 3.00001, 2 ]  精度爲:1e-05
函數值爲:-7

63次  [ 3.00001, 2 ]    [ 3, 1.99999 ]  [ 3.00001, 2 ]
64次  [ 3.00001, 2 ]    [ 2.99999, 2 ]  [ 3, 1.99999 ]
65次  [ 3.00001, 2 ]    [ 3, 2 ]        [ 2.99999, 2 ]
66次  [ 3, 2 ]  [ 3.00001, 2 ]  [ 3, 2 ]
67次  [ 3, 2 ]  [ 3, 2 ]        [ 3.00001, 2 ]
68次  [ 3, 2 ]  [ 3, 2 ]        [ 3, 2 ]
69次  [ 3, 2 ]  [ 3, 2 ]        [ 3, 2 ]
70次  [ 3, 2 ]  [ 3, 2 ]        [ 3, 2 ]
71次  [ 3, 2 ]  [ 3, 2 ]        [ 3, 2 ]
72次  [ 3, 2 ]  [ 3, 2 ]        [ 3, 2 ]
73次  [ 3, 2 ]  [ 3, 2 ]        [ 3, 2 ]
74次  [ 3, 2 ]  [ 3, 2 ]        [ 3, 2 ]

最好點爲[ 3, 2 ]        精度爲:1e-06
函數值爲:-7

 

以前錯誤版本結果以下

結果:

1次  [ 0, 0 ]      [ 1.2, 0 ]     [ 0, 0.8 ]
2次  [ 1.2, 0 ]     [ 1.2, -0.8 ]   [ 0, 0 ]
3次  [ 1.2, 0 ]    [ 1.2, -0.8 ]   [ 2.4, -0.8 ]
4次  [ 1.2, 0 ]     [ 0.6, -0.2 ]   [ 1.2, -0.8 ]
5次  [ 1.2, 0 ]     [ 0.6, 0.6 ]    [ 0.6, -0.2 ]
6次  [ 1.5, 1.3 ]  [ 1.2, 0 ]      [ 0.6, 0.6 ]
7次  [ 2.1, 0.7 ]  [ 1.5, 1.3 ]    [ 1.2, 0 ]
8次  [ 2.4, 2 ]     [ 2.1, 0.7 ]    [ 1.5, 1.3 ]
9次  [ 2.4, 2 ]     [ 3, 1.4 ]      [ 2.1, 0.7 ]
10次  [ 2.4, 2 ]        [ 3, 1.4 ]      [ 3.3, 2.7 ]
11次  [ 3, 2.2 ]        [ 2.4, 2 ]      [ 3, 1.4 ]
12次  [ 3, 2.2 ]        [ 2.85, 1.75 ]  [ 2.4, 2 ]
13次  [ 3, 2.2 ]        [ 2.85, 1.75 ]  [ 3.45, 1.95 ]
14次  [ 3, 2.2 ]        [ 2.85, 1.75 ]  [ 2.6625, 1.9875 ]
15次  [ 3, 2.2 ]        [ 3.1875, 1.9625 ]      [ 2.85, 1.75 ]
16次  [ 2.97188, 1.91563 ]      [ 3, 2.2 ]      [ 3.1875, 1.9625 ]
17次  [ 2.97188, 1.91563 ]      [ 2.88516, 2.10547 ]    [ 3, 2.2 ]
18次  [ 2.97188, 1.91563 ]      [ 2.85703, 1.82109 ]    [ 2.88516, 2.10547 ]
19次  [ 2.97188, 1.91563 ]      [ 2.8998, 1.98691 ]     [ 2.85703, 1.82109 ]
20次  [ 2.97188, 1.91563 ]      [ 3.01465, 2.08145 ]    [ 2.8998, 1.98691 ]
21次  [ 2.97188, 1.91563 ]      [ 3.01465, 2.08145 ]    [ 3.08672, 2.01016 ]
22次  [ 2.94653, 1.99272 ]      [ 2.97188, 1.91563 ]    [ 3.01465, 2.08145 ]
23次  [ 2.98693, 2.01781 ]      [ 2.94653, 1.99272 ]    [ 2.97188, 1.91563 ]

最好點爲[ 2.98693, 2.01781 ]    精度爲:0.1
函數值爲:-6.99928

24次  [ 2.98693, 2.01781 ]      [ 2.9693, 1.96045 ]     [ 2.94653, 1.99272 ]
25次  [ 3.0097, 1.98553 ]       [ 2.98693, 2.01781 ]    [ 2.9693, 1.96045 ]
26次  [ 3.01282, 2.02228 ]      [ 3.0097, 1.98553 ]     [ 2.98693, 2.01781 ]
27次  [ 3.01282, 2.02228 ]      [ 3.0097, 1.98553 ]     [ 3.02342, 1.99696 ]
28次  [ 2.99909, 2.01086 ]      [ 3.01282, 2.02228 ]    [ 3.0097, 1.98553 ]
29次  [ 3.00782, 2.00105 ]      [ 2.99909, 2.01086 ]    [ 3.01282, 2.02228 ]
30次  [ 3.00782, 2.00105 ]      [ 2.9941, 1.98963 ]     [ 2.99909, 2.01086 ]
31次  [ 3.00003, 2.0031 ]       [ 3.00782, 2.00105 ]    [ 2.9941, 1.98963 ]
32次  [ 3.00003, 2.0031 ]       [ 3.00782, 2.00105 ]    [ 3.00884, 2.0083 ]

最好點爲[ 3.00003, 2.0031 ]     精度爲:0.01
函數值爲:-6.99999

33次  [ 3.00003, 2.0031 ]       [ 2.99901, 1.99585 ]    [ 3.00782, 2.00105 ]
34次  [ 3.00003, 2.0031 ]       [ 2.99901, 1.99585 ]    [ 2.99537, 1.99869 ]
35次  [ 3.00003, 2.0031 ]       [ 3.00367, 2.00026 ]    [ 2.99901, 1.99585 ]
36次  [ 3.00043, 1.99877 ]      [ 3.00003, 2.0031 ]     [ 3.00367, 2.00026 ]
37次  [ 3.00043, 1.99877 ]      [ 2.99851, 2.00127 ]    [ 3.00003, 2.0031 ]
38次  [ 3.00043, 1.99877 ]      [ 2.99851, 2.00127 ]    [ 2.99891, 1.99693 ]
39次  [ 3.00043, 1.99877 ]      [ 2.99975, 2.00156 ]    [ 2.99851, 2.00127 ]
40次  [ 3.00043, 1.99877 ]      [ 2.99975, 2.00156 ]    [ 3.00167, 1.99906 ]

最好點爲[ 2.9993, 2.00071 ]     精度爲:0.001
函數值爲:-7

41次  [ 2.9993, 2.00071 ]       [ 3.00043, 1.99877 ]    [ 2.99975, 2.00156 ]
42次  [ 2.99992, 1.99883 ]      [ 2.9993, 2.00071 ]     [ 3.00043, 1.99877 ]
43次  [ 2.9992, 2.00028 ]       [ 2.99992, 1.99883 ]    [ 2.9993, 2.00071 ]
44次  [ 2.99969, 1.99897 ]      [ 2.9992, 2.00028 ]     [ 2.99992, 1.99883 ]
45次  [ 2.99921, 2.00002 ]      [ 2.99969, 1.99897 ]    [ 2.9992, 2.00028 ]
46次  [ 2.99958, 1.99911 ]      [ 2.99921, 2.00002 ]    [ 2.99969, 1.99897 ]
47次  [ 2.99924, 1.99986 ]      [ 2.99958, 1.99911 ]    [ 2.99921, 2.00002 ]
48次  [ 2.99951, 1.99922 ]      [ 2.99924, 1.99986 ]    [ 2.99958, 1.99911 ]
49次  [ 2.99928, 1.99975 ]      [ 2.99951, 1.99922 ]    [ 2.99924, 1.99986 ]

最好點爲[ 2.99947, 1.9993 ]     精度爲:0.0001
函數值爲:-7

50次  [ 2.99947, 1.9993 ]       [ 2.99928, 1.99975 ]    [ 2.99951, 1.99922 ]
51次  [ 2.9993, 1.99968 ]       [ 2.99947, 1.9993 ]     [ 2.99928, 1.99975 ]
52次  [ 2.9993, 1.99968 ]       [ 2.99944, 1.99936 ]    [ 2.99947, 1.9993 ]
53次  [ 2.99932, 1.99963 ]      [ 2.9993, 1.99968 ]     [ 2.99944, 1.99936 ]
54次  [ 2.99938, 1.9995 ]       [ 2.99932, 1.99963 ]    [ 2.9993, 1.99968 ]
55次  [ 2.99938, 1.9995 ]       [ 2.9994, 1.99945 ]     [ 2.99932, 1.99963 ]
56次  [ 2.99938, 1.9995 ]       [ 2.99936, 1.99955 ]    [ 2.9994, 1.99945 ]
57次  [ 2.99938, 1.9995 ]       [ 2.99936, 1.99955 ]    [ 2.99935, 1.99957 ]
58次  [ 2.99938, 1.9995 ]       [ 2.99938, 1.99949 ]    [ 2.99936, 1.99955 ]
59次  [ 2.99938, 1.9995 ]       [ 2.99937, 1.99953 ]    [ 2.99938, 1.99949 ]
60次  [ 2.99938, 1.9995 ]       [ 2.99936, 1.99954 ]    [ 2.99937, 1.99953 ]
61次  [ 2.99937, 1.99951 ]      [ 2.99938, 1.9995 ]     [ 2.99936, 1.99954 ]
62次  [ 2.99937, 1.99951 ]      [ 2.99938, 1.99949 ]    [ 2.99938, 1.9995 ]
63次  [ 2.99938, 1.9995 ]       [ 2.99937, 1.99951 ]    [ 2.99938, 1.99949 ]
64次  [ 2.99937, 1.99954 ]      [ 2.99938, 1.9995 ]     [ 2.99937, 1.99951 ]
65次  [ 2.99938, 1.99954 ]      [ 2.99937, 1.99954 ]    [ 2.99938, 1.9995 ]

最好點爲[ 2.99938, 1.99954 ]    精度爲:1e-05
函數值爲:-7

 

感謝您的閱讀,生活愉快~

相關文章
相關標籤/搜索