资源预览内容
第1页 / 共2页
第2页 / 共2页
亲,该文档总共2页全部预览完了,如果喜欢就下载吧!
资源描述
第 2 次作业,上机作业:编程 ( 用 C+)求解,一维搜索求 f(x)=(x2-1)2+(x-1)2+3 x-10,10 最小值。 (上交调试通的正确的源程 序) 。 解:利用黄金分割法求一维搜索源程序:#include #include #include #include using namespace std; double f(double x); double GoldenSection( double a, double x1, double x2, double b); int main() double a=-10,b=10; double x1 = 0.312 * (b-a), x2=0.618 * (b-a); double x = GoldenSection(a,x1,x2,b); double y = f(x); cout y2 ) return GoldenSection( x1, x1 + 0.312*(b - x1), x1 + 0.618*(b - x1),b); if( y1 = y2 ) return GoldenSection( x1,x1+0.312*(x2-x1), x1+0.618*(x2-x1), x2); 运行结果:
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号