坐标上升算法(Coordinate Ascent)及C++编程实现
生活随笔
收集整理的這篇文章主要介紹了
坐标上升算法(Coordinate Ascent)及C++编程实现
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
坐標上升算法(Coordinate Ascent)及C++編程實現
編程實現: [cpp] view plaincopyprint?#include?<iostream>?? using?namespace?std;?? #define?f(x1,x2,x3)?(-x1*x1-2*x2*x2-3*x3*x3+2*x1*x2+2*x1*x3-4*x2*x3+6)?? int?main()?? {?? ????double?x1=1;?? ????double?x2=1;?? ????double?x3=1;?? ????double?f0=f(x1,x2,x3);?? ????double?err=1.0e-10;?? ????while?(true)?? ????{?? ????????x1=x2+x3;?? ????????x2=0.5*x1-x3;?? ????????x3=1.0/3*x1-2.0/3*x2;?? ????????double?ft=f(x1,x2,x3);?? ????????if?(abs(ft-f0)<err)?? ????????{?? ????????????break;?? ????????}?? ????????f0=ft;?? ????}?? ????cout<<"@author:鄭海波?email:zhb931706659@126.com"<<endl;?? ????cout<<"\nmax{f(x1,x2,x3)}="<<f(x1,x2,x3)<<endl;?? ????cout<<"取得最大值時的坐標:\n(x1,x2,x3)=("<<x1<<","<<x2<<","<<x3<<")"<<endl;?? ????return?0;?? }??
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀
編程實現: [cpp] view plaincopyprint?
總結
以上是生活随笔為你收集整理的坐标上升算法(Coordinate Ascent)及C++编程实现的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: eclipse 快捷键大全,eclips
- 下一篇: 梯度下降法(一)入门