最速下降法和牛顿法求最小值点的算法及结果_第1页
最速下降法和牛顿法求最小值点的算法及结果_第2页
最速下降法和牛顿法求最小值点的算法及结果_第3页
最速下降法和牛顿法求最小值点的算法及结果_第4页
最速下降法和牛顿法求最小值点的算法及结果_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1.最速下降法计算:f=(x-1)2+5(x-5)212(1)程序代码如下:#include<stdio.h>#include<math.h>doublef1(doublex,doubley){doubler;r=(pow(x-1,2)+5*pow((y-5),2));returnr;}//最速下降法求最优解voidmain(){doubleh=3,x0=3,x1,y0=6,y1,s,r0,r1;doublee0=0.000001,e1=0.000001;intk=0;s=sqrt(pow(2*x0-2,2)+pow(10*y0-50,2));printf("%dx1=%fx2=%fs=%f\n",k,x0,y0,s);while(s>e1){x1=x0;y1=y0;r0=f1(x0,y0);h=3;//一维搜索,成功失败法while(fabs(h)>e0){r1=f1((x1-h*2*(x1-1)),(y1-h*10*(y1-5)));if(r1<r0){x0=x1-h*2*(x1-1);y0=y1-h*10*(y1-5);r0=r1;h=h+h;}elseif(fabs(h)>e0)h=(-1)*h/4;}s=sqrt(pow(2*x0-2,2)+pow(10*y0-50,2));k++;printf("%dx1=%fx2=%fs=%f\n",k,x0,y0,s);}

printf("x1=%fx2=%f",x0,y0);}⑵初始值设为x1=3,x2=6时,运行结果如下图1-1:xl=3.000900x2=6-0S00O0Jj=10.7703301xl-2.25000Sx2-4.125000 ;i-9.1301372xl=1.781250x2=5.76562Ej=7.8140623xl一丄.634766x2-5.047852i-1.3567丄?4xl=1.158691x2=4.868408j=1.353651xl=1.1ZBVJ7xli=4.yyi77fcj=0.2706716xl=1.032234x2=5.022617i=0.2351827xl=1.020146x2=4.980210j=0.2019628xl=1.016369x2=4.998763i=0.0349979xl=1.004092x2=5.003401j=0.0349851Rxi=1一num贴K=R.3Rfi9ai11xl=1.000831x2=4.999415$=0.00607812xl-1.000520x2-5.600512s-0.30522013xl=1.000422x2=5.@00032s=0.00090314xl-1.0091QGx2-4.U99912i-0.00090415xl=1.009086x2=4.9999955=0.00018016xl=丄.009021x2=5.@00015£=0.900丄5717xl=1.009013x2=4.999987s=0.90013518xl=1.000011x2=4.999999$=0.00002319xl=1.009003x2=5.@00002s=0.90002320xl=1.009002x2=5.S00000s=0.90009521xl=1.009001x2=5.600000s=0.90009422xl=1.QQ&QQQx2=5.S00000s=0.900093殆x1=1.x2=F>-咎=0-3RROW1xl=1.000000 x2=5.S00OS0PFessanijkeytocontiniw.图1-1(3)初始值设为x1=30000,x2=60000时,运行结果如下图1-2:

姓名:龚尚映学号:1103121816 第3页>1=36000.000600 x2=E0006.00S000s=602942.5864081Ml=24375.187500 x2=3754.687500s=61501.3796592xl=15234.867188x2=-3275.976563s=44774.586076xl=9522.166992>2=2875.854492 s=34^49.8336014xl=5951.729370I>2=-2506.997681s=27796.7256155>1=3720.205856>2=2202.997971 s=23204.514144hxl=2325.503660I>2=-1918.248224s=19786.400«87xl=1889.659224:>2=-115.203014 s=3963.9640668xl=473.164806x2=33E.558289s=3437.824^039xl=296.103004x2=-284.238502s=2951.988188IMxl=k4H.7711^1>Z=-13.H774Mbs=51ki.4B4JllW11xl=60.942798x2=54.712868s=511.37997312xl=41?.7M352Jx2=«.1W7W54s=102.24241413xl=13.175881x2=-3.544399s=88.846406丄4xl-0.6B9925x2-丄2.咗7E349s-76.29694415xl=7.183064x2=5.467272s=13.2195101Gxl-2.54G7GGx2-3.715B02i-13.21GG3517xl=2.255935x2=4.919688s=2.63713818xl-1.313984x2-5.22S859=-2.29613G19xl=1.196240x2=4.806748s=1.97196820xl=1.159445x2=4.987922s=0.24099721xl=1.039861x2=5.033215s=0.34158522=1s=R.RfiRR2li|23xl=1.008097x2=4.994291s=0.05934124xl=1.005061x2=5.004995s=0.05096725xl=1.004112x2=5.000312s=0.00879626xl=1.001028x2=4.999141s=0.00882827xl=1.000835x2=4.999946s=0.00175^28xl=1.006209x2=5.060148s=0.00153429xl=1.006130x2=4.999871s=0.00131730xl=1.006106x2=4.999992s=0.00022731xl=1.006027x2=5.000022s=0.06022832xl=1.000022x2=5.0S0001s=0.000045J3xl=1.MMUMUbx2=4.yyy^bs=M.34xl=1.00S003x2=5.000003s=0.0S003435xl=1-0000阿3x2=5.060O0SS=0.0S000636xl=1.00S001x2=4.999999s=0.0S000637xl一丄-00000丄x2-5.060O0BS-O.0G00O138xl=1.00S000x2=5.00000SS=0.0S000139xl-1.00SQ00x2-5.0000005-0.060001=1.&&&&&&x2=5.060000Pressanijkeytocontinue.图1-22.牛顿法计算:f=(x-1)2+5(x-5)212程序代码如下:#includevstdio.h>#includevmath.h>doublefl(doublex,doubley){return(pow(x-l,2)+5*pow(y-5,2));}〃牛顿法求最优解voidmain(){doubleh=3,x0=3,xl,y0=6,yl,s,r0,rl;doublee0=0.000001,el=0.000001;intk=0;s=sqrt(pow(2*x0-2,2)+pow(10*y0-50,2));printf("%dx=%fy=%fs=%f\n",k,x0,y0,s);while(s>e1){x1=x0;y1=y0;r0=f1(x0,y0);h=3;〃一维搜索while(fabs(h)>e0){r1=f1((x1-h*(x1-1)),(y1-h*(y1-5)));if(r1<r0){x0=x1-h*(x1-1);y0=y1-h*(y1-5);r0=r1;h=h+h;}elseif(fabs(h)>e0)h=(-1)*h/4;}s=sqrt(pow(2*x0-2,2)+pow(10*y0-50,2));k++;printf("%dx=%fy=%fs=%f\n",k,x0,y0,s);}printf("x=%fy=%f",x0,y0);}(2)初始值设为x1=3,x2=6时,运行结果如下图2-1:亍X=3.000000y=6.000000==10.7703301X~1.50S000S-2.G925B22x=1.125000U=5.062500==0.6731463x-1.03125By-5.015625u-0.1682864x=1.007813y=5.083906==0.0420725x=1.001^536x=1.000488y=5.000244s=0.0026297x=l.000122U=5.000061==0.0006578x=1.000031</=5.0000155=0.0001649x=l.006008y=5.000064S=0.00004110X=1.0S0002y=5.000001S=0.00001011X=1.060000S)=5.000600S=0.00000312x=i.FiFinnniis=fi.nnupiFiix=1.000000 y=5;.000000PFessanykeytocontinue.图2-1(3)初始值设为x1=30000,x2=60000时,运行结果如下图2-2:亍s=602942.5B64081x=7baW.7btJtia(!l s=150735.b4t>btJ22x=1875.937500 y=3754.687500s=37683.9116503x=469.734375y=942.^21875s=9420.9779134x=1lR.1R^R94・=刃9一詰H4R9s:=23^R.24447R5x=3B.295898ij=63.588867s=588.811120Gx-8.323975y-19.C47217s-147.2B27807x=2.830994U=8.661804s=36.8006958x=1.457748iF=b.?154bls=?.2001749x=1.114437y=5.228863s=2.30004310x=l.028609U=5.057216s=057501111x=l.007152y=5.014304s=014375312x=1.001788ij=5.803576s=003593813x-l.000447^-5.000894O-000098514x=l.000112ij=5.000223s=000224615x=1.0S0028Si=5.O00S56s=B00056216X=1.06000?SJ=5.000614s=000014617X=1.0S0002ij=5.000S03s=000003518X=1.060000y=5.000601s=000000919X=1.000000ij=5.000000s=000000220x_l.0S000O*一£.000Q00O-000O0Q1X=1-000006 y=5.000000Pre£sanyke^Ftocontinue图2-23.最速下降法求:f=(x-1)2+(x-1)2+5(x-5)2+5(x-5)212 3 4(1)程序代码如下:#includevstdio.h>#includevmath.h>doublef1(doublex,doublex1,doubley,doubley1){doubler;r=(pow(x-1,2)+pow(x1-1,2)+5*pow(y-5,2)+5*pow(y1-5,2));returnr;}〃最速下降法求最优解voidmain(){〃x1,x2,x3,x4分别为多项式函数中四个分量的初始值〃x5,x6,x7,x8分别为对应的下一个值doubled=3,x1=3,x5,x2=4,x6,x3=8,x7,x4=6,x8,s,r0,r1;doublee0=0.000001,e1=0.000001;intk=0;s=sqrt(pow(2*x1-2,2)+pow(2*x2-2,2)+pow(10*x3-50,2)+pow(10*x4-50,2));printf("%dx1=%fx2=%fx3=%fx4=%fs=%f\n",k,x1,x2,x3,x4,s);while(s>e1){x5=x1;x6=x2;x7=x3;x8=x4;r0=f1(x1,x2,x3,x4);d=3;//一维搜索while(fabs(d)>e0){r1=f1((x5-d*2*(x5-1)),(x6-d*2*(x6-1)),(x7-d*10*(x7-5)),(x8-d*10*(x8-5)));if(r1<r0){x1=x5-d*2*(x5-1);x2=x6-d*2*(x6-1);x3=x7-d*10*(x7-5);x4=x8-d*10*(x8-5);r0=r1;d=d+d;}elseif(fabs(d)>e0)d=(-1)*d/4;}s=sqrt(pow(2*x1-2,2)+pow(2*x2-2,2)+pow(10*x3-50,2)+pow(10*x4-50,2));k++;printf("%dx1=%fx2=%fx3=%fx4=%fs=%f\n",k,x1,x2,x3,x4,s);}printf("\nx1=%fx2=%fx3=%fx4=%fs=%f\n",x1,x2,x3,x4,s);}(2)初始值设为x1=3,x2=4,x3=8,x4=6时,运行结果如下图3-1:101112131415161718192021222324xi=3.000S00>1=1.4062505=1xl=1.206299>1=1.051575xl=1.041904>1=1.010476xl=1.006548xl=1.005320xl=1.001330xl=1.001081xl=1.000270xl=1.000169xl=1.000137xl=1.000034xl=1.006028xl=1.00S007xl=1.00S004xl=1.00S004xl=1.00S001xl=1.00S001xl=1.QQ&QQQxl=1.00S000xl=1.00S000m2=4.000000>2=1.609375>2=1.^RfiflS9>2=1.309448>2=1.077362x2=1.062857>2=1.015714>2=1.009821>2=1.007980Ix2=1.001995x2=1.001621Ix2=1.00S405x2=1.0002531x2=1.000206x2=1.000051x2=1.0000421x2=1.006010:x2=1.000007:x2=1.000005x2=1.000001x2=1.000001Ix2=1.QQ&QQQIx2=1.000000Ix2=1.00S000x3=8.000Q00x3=4.484375^=S.4S1172x3=5.028198x3=4.922^55x3=4.995153x3=5.013328x3=4.988338x3=4.999271x3=5.002004x3=5.000125x3=4.999655x3=5.006301x3=5.006019x3M.999948x3=4.999997Ix3=5.0000091x3=4.999992x3=5.00S00Ox3=5.000001x3=5.00SO00Ix3Ix3=5.00S000Ix3=5.000000»4=6.000000:^4=R.RA2RRRx4=4.828125^4=S.1Sfi^91x4=5.009399x4=4.974152x4=4.998384x4=5.0044435(4=4.996113x4=4.999757x4=5.00Q668x4=5.000042x4M.999885x4=5.000100x4=5.000006x4M.9999831x4=4.999999x4=5.000003x4=^.999997Ix4=5.000000x4=5.000000Ix4=5.000000Ix4=5.000000Ix4=5.000000Ix4=5.000000s=32.434549s=A.1R^^9Ss=5.629078s=4.843081s=0.801011s=B.838283s=0.159492s=0.145479s=B.125175s=0.020663s=0.021666s=0.004114s=0.003760Is=0.003235s=0.000533s=0.000560S=0.000106s=0.0000971s=0.3000B4IS=0.000014IS=0.000014IS=0.000003IS=0.000003Is=0.300002Is=0.0000S0bcl=1-00S000x2=l.00S000x3=5.000000x4=5.00S000S=0.000000Pressanykeytccontinue图3-1(3)初始值设为xl=30000,x2=40000,x3=80000,x4=60000时,运行结果如下图3-2:xl=30000.030000x2=40000.QQQ0QQx3=86000.&QQQQQx4=60000.000000s=1004917.630957kxl=24375.187500x2=32500.187500x3=5004.687500x4=3754.687500s=102503.150987xl=15234.8671880x2=20312.992188x3=-4369.726563x4=-3275.97&S63s=7^625.82874xl=15234.8671880x2=20312.992188x3=-4369.726563x4=-3275.97&S63s=7^625.82874Sxl-9522.丄6599玄x2-丄2695.995丄丄7x3-3832.885742x4-2875.854492s-57417.014593xl=59E1.72?370x2=7935.371948xl=3720.205856x2=4959.982468xl=2325.503660x2=3100.364042xl=59E1.72?370x2=7935.371948xl=3720.205856x2=4959.982468xl=2325.503660x2=3100.364042xl=1889.65?224x2=2519.2332842935.725321x4=2202.997971 =38674.674145-2559.384394x4=-1918.248224s=32977.759233-155.274025x4=-115.203014s=6606.646873xl=473.164806x2=630.558321x3=445.753568x4=335.558289s=5729.780283卩xl=29fc.l03004x2=394.473951x3=-380.659372x4=-284.238502s=4920.044345<1=240.771191x2=320.697585x3=-19.103711x4=-13.077406s=854.145905xl=66.942798x2=80.924396x3=71.285205x4=54.7128S8s=852.310945\L2Kl=4?.703523x2=65.938572x3=9.142825x4=8.丄07旦5*4s=170.40505813xl=13.175881x2=17.234643x3=-6.392770x4=-3.544399s=148.07922914xl-8.G0992Gx2-±1.14GG52x3-14■爭x4-12.47t349g-127.16322815xl=7.183064x2=9.244155x3=5.623042x4=5.467272s=22.03265616xl=2.5457&6x2=3x3=3.286634x4=3_715002s=22.02800917xl=2.255935x2=2.674594x3=4.892915x4=4-919688s=439525718xl=1.313984x2=l.418648x3=5.294485x4=5_220859s=382693119xl=1.196240x2=l.261655x3=4.742326x4=4-806748s=3286656<1=1.159445x2=l.212595x3=4.983895x4=4-987922s=0568332Lilxl=1.W3V«E>1x2=1.053149x3=b.U442UUx4=5.W33215s=W56V315Q2xl=1.032387x2=l.043183x3=5.002768x4=5.002676s=0113367E3k1-1.0080J7x2-1.010796x3-4.992388x4"4«994291S~00989B3Q4xl=1.0050B1x2=l.00674?x3=5.00&660x4=5.004995s=0084947餐4=1RR4112ntS=1.RHS4H2x^=R.flfia41Ax4=5.000312R14660Q6xl=1.001028x2=l.001371x3=4.998855x4=4-999141s=0014714E7xl=1.000835x2=l.0B1114x3=4.999928x4=4-999946s=0002924Q8xl=1.000239x2=l.0B0278x3=5.000197x4=5_000148s=0002556E9xl=1.000130x2=l.0B0174x3=4.999828x4=4-999871s=0002196buKl=l.UMMlkl6xH=lx4=4-鹑邢Hs=MUUUJYHhixl=1.000027x2=l.0B0035x3=5.009030x4=5.000622s=000038002xl-1.000022x2-1.0B002?x3-5.009002x4-5„000601S-000007533xl=1.000035x2=l-00000?x3=4.999995x4=4-999996s=0000066R4=1-000腼2=1-000004xl=F»-00M004x4=5_<?=0Q5xl=1.000033x2=l.000004x3=5.009000x4=5_QQ0&Q0s=000001036xl=1.000031x2=l.Q&Q0Q1x3=4.999999x4=4-999999s=0000010B7xl=1.000031x2=lx3=5.QQ&QQQx4=5.s=0000002hsKl=1.000030x2=l-000000x3=5.00B000x4=5_000000s=0000002byxl=1.xExJ=5.x4=5.s=Mkexl=1.000030x2=lx3=5.009000x4=5_QQ0&Q0s=0000000图3-24.牛顿法计算:f=(x-1)2+(x-1)2+5(x-5)2+5(x-5)212 3 4(1)程序代码如下:#includevstdio.h>#includevmath.h>doublefl(doublex,doublexl,doubley,doubley1){doubler;r=(pow(x-l,2)+pow(xl-l,2)+5*pow(y-5,2)+5*pow(yl-5,2));returnr;}〃最速下降法求最优解voidmain(){//x1,x2,x3,x4分别为多项式函数中四个分量的当前值//x5,x6,x7,x8分别为多项式函数中四个分量对应的下一个值doubled=3,x1=3,x5,x2=4,x6,x3=8,x7,x4=6,x8,s,r0,r1;doublee0=0.000001,e1=0.000001;intk=0;s=sqrt(pow(2*x1-2,2)+pow(2*x2-2,2)+pow(10*x3-50,2)+pow(10*x4-50,2));printf("%dx1=%fx2=%fx3=%fx4=%fs=%f\n",k,x1,x2,x3,x4,s);while(s>e1){x5=x1;x6=x2;x7=x3;x8=x4;r0=f1(x1,x2,x3,x4);d=3;//一维搜索while(fabs(d)>e0){r1=f1((x5-d*(x5-1)),(x6-d*(x6-1)),(x7-d*(x7-5)),(x8-d*(x8-5)));if(r1<r0){x1=x5-d*(x5-1);x2=x6-d*(x6-1);x3=x7-d*(x7-5);x4=x8-d*(x8-5);r0=r1;d=d+d;}elseif(fabs(d)>e0)d=(-1)*d/4;}s=sqrt(pow(2*x1-2,2)+pow(2*x2-2,2)+pow(10*x3-50,2)+pow(10*x4-50,2));k++;printf("%dx1=%fx2=%fx3=%fx4=%fs=%f\n",k,x1,x2,x3,x4,s);}printf("\nx1=%fx2=%fx3=%fx4=%fs=%f\n",x1,x2,x3,x4,s);}(2)初始值设为x1=3,x2=4,x3=8,x4=6时,运行结果如下图4-1:

xl=3x2=4.000000x3=8x4=6.00S000s=32.4345491xl-i.5@0003x2-1.750300x3-5.7S0060xl-5.256000s-6.108G37*xl=l.125003x2=1.187500x3=5.187500x4=5.062500s=2.027159xl=1.031259x2=1.046875x3=5.046875x4=5.015625s=8.506799kxl=1.067813x2=1.011719x3=5.011719x4=5.003906s=8.126697xl=l.001953x2=1.002?3Bx3=5.002930x4=5.006977s=0.031674*xl=1.0S048Bx2=1.000732x3=5.000732x4=5.006244s=8.007919xl=i.000122x2=1.000183x3=5.000183x4=5.00@061s=0.001980E=1一耐umiv2=1.RRH34A.000046s=n.RRR49SPxl=ix2=1.000911x3=5.000011x4=5.000004s=0.00012410111213x2—1-009002x2=l.009001x.2-1.009000x2=l.009000x2_G.300603k4_5.060001x3=5.90OS01«4=5.OS00O0x3-5.90060On4-5.O600O0x3=5.&QQ&QQx4=5.0S0000xl_1.@00032xl=l.S0000Oxl-1.SOO03Oxl=l.S0O000c-0.Q00021s=0.S00O98^-0.G00O32s=0.SO0090bcl=1.0900S0x2=1.000000x3=5.S00090x4=5.000000s=0.0O00S0Pressanykeytocontinue图4-1(3)初始值设为xl=30000,x2=40000,x3=80000,x4=60000时,运行结果如下图4-2:X1=7500.750000x2=13000.750600X1=7500.750000x2=13000.750600x3=20003.750006x4=15003.750000s=251229.40773xl=1875.937500x2=2500.937500x3=5004.687500>4=3754.687500s=62807.351935xl=469.734375x2=625.984375x3=1254.921875x4=942.421875s=15701.837984xl=118.183594x2=157.246094x3=3丄7-4召0469x4=239.35546?s=3?25.459496xl=30.295898x2=40.061523x3=83.120117x4=63.588867s=981.3648741011121314151011121314151617181920xl-8.023

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论