technologyforchapter7andchapter13maple.docx
- 文档编号:29005457
- 上传时间:2023-07-20
- 格式:DOCX
- 页数:29
- 大小:141.98KB
technologyforchapter7andchapter13maple.docx
《technologyforchapter7andchapter13maple.docx》由会员分享,可在线阅读,更多相关《technologyforchapter7andchapter13maple.docx(29页珍藏版)》请在冰豆网上搜索。
technologyforchapter7andchapter13maple
TechnologyforChapter7andChapter13:
ContinuousOptimization(NumericalTechniques)
Chapter7:
DiscreteSingleVariableTechniques
Labcoversthefollowingtechniques:
Dichotomous
GoldenSection
Maple:
Programswerewrittenforeachofthesetechniques.
DICHOTOMOUSSEARCHALGORITHM-Maximization
Dr.WilliamP.Fox,NavalPostgraduateSchool,Monterey,CA93953
>restart;
>
>DICHOTOMOUS:
=proc(f:
:
procedure,a:
:
numeric,b:
:
numeric,T:
:
numeric,Ep:
:
numeric)
>localx1,x2;
>
>x1:
=(a+b)/2-Ep;
>x2:
=(a+b)/2+Ep;
>printf("Theinterval[a,b]is[%4.2f,%4.2f]anduserspecifiedtolerancelevelis%6.5f.\n",a,b,T);
>###WARNING:
%xor%Xformatshouldbe%yor%Yifusedwithfloatingpointarguments
printf("Thefirst2experimentalendpointsarex1=%6.3fandx2=%6.3f.\n",x1,x2);
>printf("\n");
>printf("\n");
>N:
=ceil((ln(T/(b-a))/ln(0.5)));
>printf("Iterationx
(1)x
(2)f(x1)f(x2)Interval\n");
>iterate(f,a,b,N,x1,x2,Ep);
>
>val:
=f(mdpt);
>printf("\n");
>printf("\n");
>printf("Themidpointofthefinalintervalis%9.6fandf(midpoint)=%7.3f.\n",mdpt,val);
>printf("\n");
>printf("\n");
>###WARNING:
%xor%Xformatshouldbe%yor%Yifusedwithfloatingpointarguments
printf("Themaximumofthefunctionis%7.3fandthexvalue=%9.6f\n",fkeep,xkeep);
>printf("\n");
>printf("\n");
>end:
>iterate:
=proc(f:
:
procedure,a:
:
numeric,b:
:
numeric,N:
:
posint,x1:
:
numeric,x2:
:
numeric,Ep:
:
numeric)
>localx1n,x2n,an,bn,i,fx1,fx2,j,f1,f2,fmid;
>globalmdpt,fkeep,xkeep;
>i:
=1;
>x1n
(1):
=x1;
>x2n
(1):
=x2;
>an
(1):
=a;
>bn
(1):
=b;
>i:
=1;
>forjfrom1toN+1do
>fx1(i):
=f(x1n(i));
>fx2(i):
=f(x2n(i));
>iffx1(i)<=fx2(i)then
>an(i+1):
=x1n(i);
>bn(i+1):
=bn(i);
>x1n(i+1):
=(an(i+1)+bn(i+1))/2-Ep;
>x2n(i+1):
=(an(i+1)+bn(i+1))/2+Ep;
>else
>an(i+1):
=an(i);
>bn(i+1):
=x2n(i);
>x1n(i+1):
=(an(i+1)+bn(i+1))/2-Ep;
>x2n(i+1):
=(an(i+1)+bn(i+1))/2+Ep;
>fi;
>printf("%3.0f%11.4f%10.4f%10.4f%10.4f[%6.4f,%6.4f]\n",i,x1n(i),x2n(i),fx1(i),fx2(i),an(i),bn(i));
>mdpt:
=(an(i)+bn(i))/2;
>i:
=i+1;
>if(i=N+1)then
>if(f(an(i))>f(bn(i))orf(an(i))>f(mdpt))then
>
>fkeep:
=f(an(i));xkeep:
=an(i);
>else
>if(f(bn(i))>f(mdpt))then
>fkeep:
=f(bn(i));xkeep:
=bn(i);
>else
>fkeep:
=f(mdpt);xkeep:
=mdpt;
>fi;
>fi;
>fi;
>od;
>
>end:
>
>
>
Warning,`N`isimplicitlydeclaredlocaltoprocedure`DICHOTOMOUS`
Warning,`val`isimplicitlydeclaredlocaltoprocedure`DICHOTOMOUS`
>
>f:
=x->-x^2-2*x;
>DICHOTOMOUS(f,-3,6,.2,.01);
Theinterval[a,b]is[-3.00,6.00]anduserspecifiedtolerancelevelis0.20000.
Thefirst2experimentalendpointsarex1=1.490andx2=1.510.
Iterationx
(1)x
(2)f(x1)f(x2)Interval
11.49001.5100-5.2001-5.3001[-3.0000,6.0000]
2-0.7550-0.73500.94000.9298[-3.0000,1.5100]
3-1.8775-1.85750.23000.2647[-3.0000,-0.7350]
4-1.3162-1.29620.90000.9122[-1.8775,-0.7350]
5-1.0356-1.01560.99870.9998[-1.3162,-0.7350]
6-0.8953-0.87530.98900.9845[-1.0356,-0.7350]
7-0.9655-0.94550.99880.9970[-1.0356,-0.8753]
Themidpointofthefinalintervalis-0.955469andf(midpoint)=0.998.
Themaximumofthefunctionis0.999andthexvalue=-1.035625
>f:
=x->3*exp(.1*x)+cos(x)+sqrt(x);
>DICHOTOMOUS(f,0,2.5,.1,.01);
Theinterval[a,b]is[0.00,2.50]anduserspecifiedtolerancelevelis.10000.
Thefirst2experimentalendpointsarex1=1.240andx2=1.260.
Iterationx
(1)x
(2)f(x1)f(x2)Interval
11.24001.26004.83444.8312[0.0000,2.5000]
2.6200.64004.79324.8004[0.0000,1.2600]
3.9300.95004.85464.8553[.6200,1.2600]
41.08501.10504.85244.8508[.9300,1.2600]
51.00751.02754.85574.8553[.9300,1.1050]
6.9688.98884.85574.8559[.9300,1.0275]
Themidpointofthefinalintervalis.998125andf(midpoint)=4.856.
Themaximumofthefunctionis4.855andthexvalue=.930000
>f:
=x->-(x^2)-2*x;
>DICHOTOMOUS(f,-3,6,.2,.01);
Theinterval[a,b]is[-3.00,6.00]anduserspecifiedtolerancelevelis.20000.
Thefirst2experimentalendpointsarex1=1.490andx2=1.510.
Iterationx
(1)x
(2)f(x1)f(x2)Interval
11.49001.5100-5.2001-5.3001[-3.0000,6.0000]
2-.7550-.7350.9400.9298[-3.0000,1.5100]
3-1.8775-1.8575.2300.2647[-3.0000,-.7350]
4-1.3163-1.2963.9000.9122[-1.8775,-.7350]
5-1.0356-1.0156.9987.9998[-1.3163,-.7350]
6-.8953-.8753.9890.9845[-1.0356,-.7350]
7-.9655-.9455.9988.9970[-1.0356,-.8753]
Themidpointofthefinalintervalis-.990547andf(midpoint)=1.000.
Themaximumofthefunctionis.999andthexvalue=-1.035625
>
>
Example1
Maximizethefunctionf(x)=1-exp(x)+1/(1+x)overtheinterval[0,20]..
>f:
=x->1-exp(-x)+(1/(1+x));
>DICHOTOMOUS(f,0,20,.001,.001);
Theinterval[a,b]is[0.00,20.00]anduserspecifiedtolerancelevelis.00100.
Thefirst2experimentalendpointsarex1=9.999andx2=10.001.
Iterationx
(1)x
(2)f(x1)f(x2)Interval
19.999010.00101.09091.0909[0.0000,20.0000]
24.99955.00151.15991.1599[0.0000,10.0010]
32.49982.50181.20361.2036[0.0000,5.0015]
43.74963.75161.18701.1870[2.4998,5.0015]
53.12473.12671.19851.1985[2.4998,3.7516]
62.81222.81421.20221.2022[2.4998,3.1267]
72.65602.65801.20331.2033[2.4998,2.8142]
82.57792.57991.20361.2036[2.4998,2.6580]
92.53882.54081.20361.2036[2.4998,2.5799]
102.51932.52131.20361.2036[2.4998,2.5408]
112.50952.51151.20361.2036[2.4998,2.5213]
122.51442.51641.20361.2036[2.5095,2.5213]
132.51202.51401.20361.2036[2.5095,2.5164]
142.51072.51271.20361.2036[2.5095,2.5140]
152.51132.51331.20361.2036[2.5107,2.5140]
162.51172.51371.20361.2036[2.5113,2.5140]
Themidpointofthefinalintervalis2.512803andf(midpoint)=1.204.
Themaximumofthefunctionis1.204andthexvalue=2.512346
Example2.
>
>f:
=x->-(x^2)-1;
>DICHOTOMOUS(f,-1,0.75,.25,.01);
Theinterval[a,b]is[-1.00,.75]anduserspecifiedtolerancelevelis.25000.
Thefirst2experimentalendpointsarex1=-.135andx2=-.115.
Iterationx
(1)x
(2)f(x1)f(x2)Interval
1-.1350-.1150-1.0182-1.0132[-1.0000,.7500]
2.2975.3175-1.0885-1.1008[-.1350,.7500]
3.0813.1013-1.0066-1.0103[-.1350,.3175]
4-.0269-.0069-1.0007-1.0000[-.1350,.1013]
Themidpointofthefinalintervalis.037188andf(midpoint)=-1.001.
Themaximumofthefunctionis-1.018andthexvalue=-.135000
Example3.
>
>p:
=piecewise(x<=2,x/2,x>2,-x+3);
>f:
=x->piecewise(x<=2,x/2,x>2,-x+3);
>plot(piecewise(x<=2,x/2,x>2,-x+3),x=0..3);
>DICHOTOMOUS(f,0,3,.25,.01);
11.49001.5100Theinterval[a,b]is[0.00,3.00]anduserspecifiedtolerancelevelis.25000.
Thefirst2experimentalendpointsarex1=1.490andx2=1.510.
Iterationx
(1)x
(2)f(x1)f(x2)Interval
11.49001.5100.7450.7550[0.0000,3.0000]
22.23502.2550.7650.7450[1.4900,3.0000]
31.86251.8825.9313.9413[1.4900,2.2550]
42.04882.0688.9513.9313[1.8625,2.2550]
51.95561.9756.9778.9878[1.8625,2.0688]
Themidpointofthefinalintervalis2.012188andf(midpoint)=.988.
Themaximumofthefunctionis.931andthexvalue=1.862500
Example4.
Maximizingafunctionthatdoesnothaveaderivative.
>f:
=x->-(abs(2-x)+abs(5-4*x)+abs(8-9*x));
>DICHOTOMOUS(f,0,3,.1,.01);
Theinterval[a,b]is[0.00,3.00]anduserspecifiedtolerancelevelis.10000.
Thefirst2experimentalendpointsarex1=1.490andx2=1.510.
Iterationx
(1)x
(2)f(x1)f(x2)Interval
11.49001.5100.7450.7550[0.0000,3.0000]
22.23502.2550.7650.7450[1.4900,3.0000]
31.86251.8825.9313.9413[1.4900,2.2550]
42.04882.0688.9513.9313[1.8625,2.2550]
51.95561.9756.9778.9878[1.8625,2.0688]
62.00222.0222.9978.9778[1.9556,2.0688]
Themidpointofthefinalintervalis1.988906andf(midpoint)=.994.
Themaximumofthefunctionis.983andthexvalue=1.965625
GoldenSection
GOLDENSECTIONSEARCHALGORITHM-
ThisprogramperformstheGoldenSectionSearchalgorithmtofindthemaximumofaunimodalfunction,f(x),overaninterval,a (b-a)(0.618^k) ToutilizietheGoldensectionroutineyouneedthefollowing: UserINPUTs- Theuserentersthefunctionfusing f: =x-> TypeGOLD(f,a,b,tolerance)forspecificvaluesofa,b,andthetolerance. Theoutputistheiterativeprocess(eachstep). Thelastoutputprovidedisthemidpointofthefinalintervalandthevalueoff(x)atthatpoint. D
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- technologyforchapter7andchapter13maple