欢迎来到天天文库
浏览记录
ID:16204353
大小:140.50 KB
页数:17页
时间:2018-08-08
《广东工业大学最优化课程设计》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、《最优化理论方法》课程实验报告项目名称:最优化学生班级:学生姓名:学生学号:完成日期:2015-11-01问题:1.用黄金分割法求解,已知初始单谷区间,要求精度.2.用抛物线插值法求解,已知初始单谷区间.解法:1、本次计算采用java语言编程根据题意,定下如下变量变量与方法符号数据类型说明Gold_Optimal()String递归方法主体,完成求解,输出最优解坐标Function()double命题函数,返回函数值a_k,b_kdouble区间值,初始值为0,[a_k,b_k]表示区间a_n,b_ndouble两个探测点,无初始值,a_n->0.382,b_n->0.
2、618GOLD_LINE_UPfinaldouble0.618GOLD_LINE_DOWMfinaldouble0.382Ldouble精确度,定值为0.001主体递归如下publicstaticStringGold_Optimal(doublea,doubleb,doublel){a_k=a;//给区间赋值b_k=b;//给区间赋值if(a_n==0)a_n=a_k+GOLD_LINE_DOWM*(b_k-a_k);//给探测点赋初始值if(b_n==0)b_n=a_k+GOLD_LINE_UP*(b_k-a_k);//给探测点赋初始值if((b_k-a_k)3、//递归出口:符合精确条件return"x1="+a_k+""+"x2="+b_k;}else{//进行递归if(funtion(a_n)>funtion(b_n)){//递归分类,计算探测点b_n型a_k=a_n;a_n=b_n;b_n=a_k+GOLD_LINE_UP*(b_k-a_k);}else{//递归分类,计算探测点a_n型b_k=b_n;b_n=a_n;a_n=a_k+GOLD_LINE_DOWM*(b_k-a_k);}returnGold_Optimal(a_k,b_k,l);}以上实现了计算最小值的递归操作,给初始探测点赋值也并到递归中,但设定了条件,4、他们都只能执行一次,在递归中也分成了两个类别。但是还差一个函数值,其实现如下:publicstaticdoublefuntion(doublea){returna*(a+2);}接着是主方法如下:publicstaticvoidmain(Stringargs[]){System.out.println(Gold_Optimal(-3f,5f,0.001f));}输出如下:2、本题同样是采用java语言编程实现。题目采用以抛物线去逼近三次方程,找出最小值,由于计算xk比较繁琐,同时又要多次计算,于是将其封装于一个类中,如下:publicclassGetParabolaDa5、ta{privatestaticdoublex1,x2,x3;//定义三个变量privatestaticdoublex_k;//定义二次函数极小值点publicstaticdoubleFuntion2(doublex){//函数返回值return8*x*x*x-2*x*x-7*x+3;}publicGetParabolaData(doublex1,doublex2,doublex3){//构造函数this.x1=x1;this.x2=x2;this.x3=x3;}publicstaticdoublegetB1(){//获得B1return(x2*x2-x3*x3)*Fu6、ntion2(x1);}publicstaticdoublegetB2(){//获得B2return(x3*x3-x1*x1)*Funtion2(x2);}publicstaticdoublegetB3(){//获得B3return(x1*x1-x2*x2)*Funtion2(x3);}publicstaticdoublegetC1(){//获得C1return(x2-x3)*Funtion2(x1);}publicstaticdoublegetC2(){//获得C2return(x3-x1)*Funtion2(x2);}publicstaticdoublegetC3(7、){//获得C3return(x1-x2)*Funtion2(x3);}publicstaticdoublegetX_k(){//获得函数极小值x_k=(getB1()+getB2()+getB3())/(2*(getC1()+getC2()+getC3()));returnx_k;}}如此一来,每次循环的时候只要通过3个变量实例化classGetParabolaData的对象即可,其递归方法如下:publicstaticdoubleParabola_Optimal(doublex1,doublex2,doublex3){parabola
3、//递归出口:符合精确条件return"x1="+a_k+""+"x2="+b_k;}else{//进行递归if(funtion(a_n)>funtion(b_n)){//递归分类,计算探测点b_n型a_k=a_n;a_n=b_n;b_n=a_k+GOLD_LINE_UP*(b_k-a_k);}else{//递归分类,计算探测点a_n型b_k=b_n;b_n=a_n;a_n=a_k+GOLD_LINE_DOWM*(b_k-a_k);}returnGold_Optimal(a_k,b_k,l);}以上实现了计算最小值的递归操作,给初始探测点赋值也并到递归中,但设定了条件,
4、他们都只能执行一次,在递归中也分成了两个类别。但是还差一个函数值,其实现如下:publicstaticdoublefuntion(doublea){returna*(a+2);}接着是主方法如下:publicstaticvoidmain(Stringargs[]){System.out.println(Gold_Optimal(-3f,5f,0.001f));}输出如下:2、本题同样是采用java语言编程实现。题目采用以抛物线去逼近三次方程,找出最小值,由于计算xk比较繁琐,同时又要多次计算,于是将其封装于一个类中,如下:publicclassGetParabolaDa
5、ta{privatestaticdoublex1,x2,x3;//定义三个变量privatestaticdoublex_k;//定义二次函数极小值点publicstaticdoubleFuntion2(doublex){//函数返回值return8*x*x*x-2*x*x-7*x+3;}publicGetParabolaData(doublex1,doublex2,doublex3){//构造函数this.x1=x1;this.x2=x2;this.x3=x3;}publicstaticdoublegetB1(){//获得B1return(x2*x2-x3*x3)*Fu
6、ntion2(x1);}publicstaticdoublegetB2(){//获得B2return(x3*x3-x1*x1)*Funtion2(x2);}publicstaticdoublegetB3(){//获得B3return(x1*x1-x2*x2)*Funtion2(x3);}publicstaticdoublegetC1(){//获得C1return(x2-x3)*Funtion2(x1);}publicstaticdoublegetC2(){//获得C2return(x3-x1)*Funtion2(x2);}publicstaticdoublegetC3(
7、){//获得C3return(x1-x2)*Funtion2(x3);}publicstaticdoublegetX_k(){//获得函数极小值x_k=(getB1()+getB2()+getB3())/(2*(getC1()+getC2()+getC3()));returnx_k;}}如此一来,每次循环的时候只要通过3个变量实例化classGetParabolaData的对象即可,其递归方法如下:publicstaticdoubleParabola_Optimal(doublex1,doublex2,doublex3){parabola
此文档下载收益归作者所有