您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 数据通信与网络 > 机械优化设计鲍威尔法编程
鲍威尔法求解二维函数极小值的程序说明一题目利用鲍威尔法求函数221212112(,)242fxxxxxxx的极小值点。二鲍威尔法基本思想:1)给定初始点0x,选取初始方向组,它由n各线性无关的向量00012,...nddd所组成。2)从0kx出发,顺次沿12,,...kkknddd作一维搜索得12,,...kkknxxx。接着以knx为起点,沿方向10kkknndxx移动一个0kknxx的距离,得到102kkknnxxx01,,kkknnxxx分别称为一轮迭代的始点,终点和反射点。始点,终点,反射点所对应的函数值分别表示为00231(),(),()kkknnFfxFfxFfx同时计算各中间点处的函数值,并记为()(0,1,2,..)kiiffxin因此有002,nFfFf计算n个函数值之差,记作1iiiff其中最大者记作1maxmimmff3)根据是否满足判别条件30FF和220230203(2)()0.5()mmFFFFFFF来确定是否要对原方向组进行替换。若不满足判别条件,则下轮迭代应对原方向组进行替换,将1knd补充到原方向组的最后位置,而除掉kmd。即新方向组为1kd,2kd,…,1kmd,1kmd,…,knd,1knd作为下轮迭代的搜索方向。下轮迭代的始点取1knd方向进行一维搜索得极小点10kx。4)判断是否满足收敛准则。若满足则取10kx为极小点,否则应置1kk,返回2,继续进行下一轮迭代。改进后的鲍威尔法程序框图如下:开始0,x给定0000,iixxde0k11:min()kkkkiiiikkkiiixxdfxd1()()kkiiifxfx?in1010,2kkkkkknnnndxxxxx00231(),(),(),maxkkknnmiFfxFfxFfx判别条件是否满足?101111:min()kkkknnnkkknnnxxdfxd11(,1,...)kkiiddimmn11(1,2,...1)kkiiddim23?FF10kknxx101kknxx0?kknxx*10kxx1kk1ii1i是否是否是否是否结束三用鲍威尔法求函数程序如下://鲍威尔法Dlg.cpp:implementationfile//#includestdafx.h#include鲍威尔法.h#include鲍威尔法Dlg.h#ifdef_DEBUG#definenewDEBUG_NEW#undefTHIS_FILEstaticcharTHIS_FILE[]=__FILE__;#endif///////////////////////////////////////////////////////////////////////////////CAboutDlgdialogusedforAppAboutclassCAboutDlg:publicCDialog{public:CAboutDlg();//DialogData//{{AFX_DATA(CAboutDlg)enum{IDD=IDD_ABOUTBOX};//}}AFX_DATA//ClassWizardgeneratedvirtualfunctionoverrides//{{AFX_VIRTUAL(CAboutDlg)protected:virtualvoidDoDataExchange(CDataExchange*pDX);//DDX/DDVsupport//}}AFX_VIRTUAL//Implementationprotected://{{AFX_MSG(CAboutDlg)//}}AFX_MSGDECLARE_MESSAGE_MAP()};CAboutDlg::CAboutDlg():CDialog(CAboutDlg::IDD){//{{AFX_DATA_INIT(CAboutDlg)//}}AFX_DATA_INIT}voidCAboutDlg::DoDataExchange(CDataExchange*pDX){CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(CAboutDlg)//}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CAboutDlg,CDialog)//{{AFX_MSG_MAP(CAboutDlg)//Nomessagehandlers//}}AFX_MSG_MAPEND_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////////CMyDlgdialogCMyDlg::CMyDlg(CWnd*pParent/*=NULL*/):CDialog(CMyDlg::IDD,pParent){//{{AFX_DATA_INIT(CMyDlg)m_x01=0.0f;m_x02=0.0f;m_x1=0.0f;m_x2=0.0f;//}}AFX_DATA_INIT//NotethatLoadIcondoesnotrequireasubsequentDestroyIconinWin32m_hIcon=AfxGetApp()-LoadIcon(IDR_MAINFRAME);}voidCMyDlg::DoDataExchange(CDataExchange*pDX){CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(CMyDlg)DDX_Text(pDX,IDC_x01,m_x01);DDX_Text(pDX,IDC_x02,m_x02);DDX_Text(pDX,IDC_x1,m_x1);DDX_Text(pDX,IDC_x2,m_x2);//}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CMyDlg,CDialog)//{{AFX_MSG_MAP(CMyDlg)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()//}}AFX_MSG_MAPEND_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////////CMyDlgmessagehandlersBOOLCMyDlg::OnInitDialog(){CDialog::OnInitDialog();//AddAbout...menuitemtosystemmenu.//IDM_ABOUTBOXmustbeinthesystemcommandrange.ASSERT((IDM_ABOUTBOX&0xFFF0)==IDM_ABOUTBOX);ASSERT(IDM_ABOUTBOX0xF000);CMenu*pSysMenu=GetSystemMenu(FALSE);if(pSysMenu!=NULL){CStringstrAboutMenu;strAboutMenu.LoadString(IDS_ABOUTBOX);if(!strAboutMenu.IsEmpty()){pSysMenu-AppendMenu(MF_SEPARATOR);pSysMenu-AppendMenu(MF_STRING,IDM_ABOUTBOX,strAboutMenu);}}//Settheiconforthisdialog.Theframeworkdoesthisautomatically//whentheapplication'smainwindowisnotadialogSetIcon(m_hIcon,TRUE);//SetbigiconSetIcon(m_hIcon,FALSE);//Setsmallicon//TODO:AddextrainitializationherereturnTRUE;//returnTRUEunlessyousetthefocustoacontrol}voidCMyDlg::OnSysCommand(UINTnID,LPARAMlParam){if((nID&0xFFF0)==IDM_ABOUTBOX){CAboutDlgdlgAbout;dlgAbout.DoModal();}else{CDialog::OnSysCommand(nID,lParam);}}//Ifyouaddaminimizebuttontoyourdialog,youwillneedthecodebelow//todrawtheicon.ForMFCapplicationsusingthedocument/viewmodel,//thisisautomaticallydoneforyoubytheframework.voidCMyDlg::OnPaint(){if(IsIconic()){CPaintDCdc(this);//devicecontextforpaintingSendMessage(WM_ICONERASEBKGND,(WPARAM)dc.GetSafeHdc(),0);//CentericoninclientrectangleintcxIcon=GetSystemMetrics(SM_CXICON);intcyIcon=GetSystemMetrics(SM_CYICON);CRectrect;GetClientRect(&rect);intx=(rect.Width()-cxIcon+1)/2;inty=(rect.Height()-cyIcon+1)/2;//Drawtheicondc.DrawIcon(x,y,m_hIcon);}else{CDialog::OnPaint();}}//Thesystemcallsthistoobtainthecursortodisplaywhiletheuserdrags//theminimizedwindow.HCURSORCMyDlg::OnQueryDragIcon(){return(HCURSOR)m_hIcon;}voidCMyDlg::OnOK(){//TODO:Addextravalidationhere//CDialog::OnOK();UpdateData(true);inti,n;doubleh1,h2,h3,m,flag,X00[2][1],d01[2][1],d02[2][1],d03[2][1];//确定键的执行程序doubleX01[2][1],X02[2][1],X03[2][1];doubleF0,F1,F2,F3,e1,e2,em;doubleX[2][1];doublef0,f1,f2,f3;X00[0][0]=m_x01;//对初始搜索点进行赋值X00[1][0]=m_x02;d01[0][0]=1,d01[1][0]=0;//初始索索方向的确定d02[0][0]=0,d02[1][0]=1;i=1;do{F0=(X00[0][0]*X00[0][0]+2*X00[1][0]*X00[1][0]-4*X00[0][0]-2*X00[0][0]*X00[1][0]),f0=F0;//初始点函数值h1=(4*d01[0][0]+2*d01[0][0]*X00[1][0]+2*d01[1][0]*X00[0][0])/(2*d01[0][0]*d01[0][0]+//确定搜索方向4*d01[1][0]*d01[1][0]-4*d01[1][0]*d01[0][0]);X01[0][0]=X00[0][0]+h1*d01[0][0],X01[1][0]=X00[1][0]+h1
本文标题:机械优化设计鲍威尔法编程
链接地址:https://www.777doc.com/doc-6002626 .html