代数方程与最优化问题精选PPT.ppt
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《代数方程与最优化问题精选PPT.ppt》由会员分享,可在线阅读,更多相关《代数方程与最优化问题精选PPT.ppt(86页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、代数方程与最优化问题第1页,此课件共86页哦7.1代数方程的求解7.1.1 代数方程的图解法一元方程的图解法例:ezplot(exp(-3*t)*sin(4*t+2)+4*exp(-0.5*t)*cos(2*t)-0.5,0 5)hold on,line(0,5,0,0)%同时绘制横轴第2页,此课件共86页哦验证:syms t;t=3.52028;vpa(exp(-3*t)*sin(4*t+2)+4*exp(-0.5*t)*cos(2*t)-0.5)ans=-.19256654148425145223200161126442e-4第3页,此课件共86页哦二元方程的图解法例:ezplot(x2*
2、exp(-x*y2/2)+exp(-x/2)*sin(x*y)%第一个方程曲线 hold on%保持当前坐标系 ezplot(x2*cos(x+y2)+y2*exp(x+y)第4页,此课件共86页哦方程的图解法仅适用于一元、二元方程的求根问题。第5页,此课件共86页哦7.1.2 多项式型方程的准解析解法例:ezplot(x2+y2-1);hold on%绘制第一方程的曲线 ezplot(0.75*x3-y+0.9)%绘制第二方程为关于x的6次多项式方程应有6对根。图解法只能显示求解方程的实根。第6页,此课件共86页哦一般多项式方程的根可为实数,也可为复数。可用MATLAB符号工具箱中的solv
3、e()函数。最简调用格式:S=solve(eqn1,eqn2,eqnn)(返回一个结构题型变量S,如S.x表示方程的根。)直接得出根:(变量返回到MATLAB工作空间)x,=solve(eqn1,eqn2,eqnn)同上,并指定变量 x,=solve(eqn1,eqn2,eqnn,x,)第7页,此课件共86页哦例:syms x y;x,y=solve(x2+y2-1=0,75*x3/100-y+9/10=0)x=-.98170264842676789676449828873194-.55395176056834560077984413882735-.3547197646508079345686
4、3789934944*i-.55395176056834560077984413882735+.35471976465080793456863789934944*i .35696997189122287798839037801365 .86631809883611811016789809418650-1.2153712664671427801318378544391*i .86631809883611811016789809418650+1.2153712664671427801318378544391*iy=.19042035099187730240977756415289 .9293383
5、0226674362852985276677202-.21143822185895923615623381762210*i .92933830226674362852985276677202+.21143822185895923615623381762210*i .93411585960628007548796029415446-1.4916064075658223174787216959259-.70588200721402267753918827138837*i-1.4916064075658223174787216959259+.70588200721402267753918827138
6、837*i第8页,此课件共86页哦验证 eval(x.2+y.2-1)eval(75*x.3/100-y+9/10)ans=0,0 0,0 0,0 -.1e-31,0.5e-30+.1e-30*i,0.5e-30-.1e-30*i,0 由于方程阶次可能太高,不存在解析解。然而,可利用MATLAB的符号工具箱得出原始问题的高精度数值解,故称之为准解析解。第9页,此课件共86页哦例:x,y,z=solve(x+3*y3+2*z2=1/2,x2+3*y+z3=2 ,x3+2*z+2*y2=2/4);size(x)ans=27 1 x(22),y(22),z(22)ans=-1.08696547629
7、86136074917644096117 ans=.37264668450644375527750811296627e-1ans=.89073290972562790151300874796949 第10页,此课件共86页哦验证:err=x+3*y.3+2*z.2-1/2,x.2+3*y+z.3-2,x.3+2*z+2*y.2-2/4;norm(double(eval(err)ans=1.4998e-027多项式乘积形式也可,如把第三个方程替换一下。x,y,z=solve(x+3*y3+2*z2=1/2,x2+3*y+z3=2,x3+2*z*y2=2/4);err=x+3*y.3+2*z.2-
8、1/2,x.2+3*y+z.3-2,x.3+2*z.*y.2-2/4;norm(double(eval(err)%将解代入求误差ans=5.4882e-028第11页,此课件共86页哦例:求解(含变量倒数)syms x y;x,y=solve(x2/2+x+3/2+2/y+5/(2*y2)+3/x3=0,.y/2+3/(2*x)+1/x4+5*y4,x,y);size(x)ans=26 1 err=x.2/2+x+3/2+2./y+5./(2*y.2)+3./x.3,y/2+3./(2*x)+1./x.4+5*y.4;验证 norm(double(eval(err)ans=8.9625e-03
9、0第12页,此课件共86页哦例:求解(带参数方程)syms a b x y;x,y=solve(x2+a*x2+6*b+3*y2=0,y=a+(x+3),x,y)x=1/2/(4+a)*(-6*a-18+2*(-21*a2-45*a-27-24*b-6*a*b-3*a3)(1/2)1/2/(4+a)*(-6*a-18-2*(-21*a2-45*a-27-24*b-6*a*b-3*a3)(1/2)y=a+1/2/(4+a)*(-6*a-18+2*(-21*a2-45*a-27-24*b-6*a*b-3*a3)(1/2)+3 a+1/2/(4+a)*(-6*a-18-2*(-21*a2-45*a-
10、27-24*b-6*a*b-3*a3)(1/2)+3第13页,此课件共86页哦7.1.3 一般非线性方程数值解非线性方程的标准形式为f(x)=0 函数 fzero 格式 x=fzero(fun,x0)%用fun定义表达式f(x),x0为初始解。x=fzero(fun,x0,options)x,fval=fzero()%fval=f(x)x,fval,exitflag=fzero()x,fval,exitflag,output=fzero()说明 该函数采用数值解求方程f(x)=0的根。第14页,此课件共86页哦例:求 的根解:fun=x3-2*x-5;z=fzero(fun,2)%初始估计值为
11、2z=2.0946 format long opt=optimset(Tolx,1.0e-8);y=fzero(x3-2*x-5,2,opt)y=2.09455148211709第15页,此课件共86页哦7.1.4 一般非线性方程组数值解格式:最简求解语句 x=fsolve(Fun,x0)一般求解语句 x,f,flag,out=fsolve(Fun,x0,opt,p1,p2,)若返回的flag 大于0,则表示求解成功,否则求解出现问题,opt 求解控制参数,结构体数据。获得默认的常用变量 opt=optimset;用这两种方法修改参数(解误差控制量)opt.Tolx=1e-10;或 set(o
12、pt.Tolx,1e-10)第16页,此课件共86页哦例:自编函数:function q=my2deq(p)q=p(1)*p(1)+p(2)*p(2)-1;0.75*p(1)3-p(2)+0.9;OPT=optimset;OPT.LargeScale=off;x,Y,c,d=fsolve(my2deq,1;2,OPT)Optimization terminated successfully:First-order optimality is less than options.TolFun.x=0.3570 0.9341Y=1.0e-009*0.1215 0.0964第17页,此课件共86页哦
13、c=1d=iterations:7 funcCount:21 algorithm:trust-region dogleg firstorderopt:1.3061e-010 解回代的精度调用inline()函数:f=inline(p(1)*p(1)+p(2)*p(2)-1;0.75*p(1)3-p(2)+0.9,p);x,Y=fsolve(f,1;2,OPT);%结果和上述完全一致,从略。Optimization terminated successfully:First-order optimality is less than options.TolFun.若改变初始值 x0=-1,0T第
14、18页,此课件共86页哦 x,Y,c,d=fsolve(f,-1,0,OPT);x,Y,kk=d.funcCountOptimization terminated successfully:First-order optimality is less than options.TolFun.x=-0.9817 0.1904Y=1.0e-010*0.5619 -0.4500kk=15 初值改变有可能得出另外一组解。故初值的选择对解的影响很大,在某些初值下甚至无法搜索到方程的解。第19页,此课件共86页哦例:用solve()函数求近似解析解 syms t;solve(exp(-3*t)*sin(4
15、*t+2)+4*exp(-0.5*t)*cos(2*t)-0.5)ans=.67374570500134756702960220427474不允许手工选择初值,只能获得这样的一个解。可先用用图解法选取初值,再调用fsolve()函数数值计算第20页,此课件共86页哦 format long y=inline(exp(-3*t).*sin(4*t+2)+4*exp(-0.5*t).*cos(2*t)-0.5,t);ff=optimset;ff.Display=iter;t,f=fsolve(y,3.5203,ff)Norm of First-order Trust-region Iteratio
16、n Func-count f(x)step optimality radius 1 2 1.8634e-009 5.16e-005 1 2 4 3.67694e-019 3.61071e-005 7.25e-010 1Optimization terminated successfully:First-order optimality is less than options.TolFun.t=3.52026389294877f=-6.063776702980306e-010第21页,此课件共86页哦重新设置相关的控制变量,提高精度。ff=optimset;ff.TolX=1e-16;ff.T
17、olFun=1e-30;ff.Display=iter;t,f=fsolve(y,3.5203,ff)Norm of First-order Trust-region Iteration Func-count f(x)step optimality radius 1 2 1.8634e-009 5.16e-005 1 2 4 3.67694e-019 3.61071e-005 7.25e-010 1 3 6 0 5.07218e-010 0 1Optimization terminated successfully:First-order optimality is less than opt
18、ions.TolFun.t=3.52026389244155f=0第22页,此课件共86页哦例:求 的根解:化为标准形式设初值点为x0=-5 -5。function F=myfun(x)F=2*x(1)-x(2)-exp(-x(1);-x(1)+2*x(2)-exp(-x(2);x0=-5;-5;%初始点options=optimset(Display,iter);%显示输出信息 x,fval=fsolve(myfun,x0,options)第23页,此课件共86页哦 Norm of First-order Trust-region Iteration Func-count f(x)step
19、optimality radius 0 3 47071.2 2.29e+004 1 1 6 12003.4 1 5.75e+003 1 2 9 3147.02 1 1.47e+003 1 3 12 854.452 1 388 1 4 15 239.527 1 107 1 5 18 67.0412 1 30.8 1 6 21 16.7042 1 9.05 1 7 24 2.42788 1 2.26 1 8 27 0.032658 0.759511 0.206 2.5 9 30 7.03149e-006 0.111927 0.00294 2.5 10 33 3.29525e-013 0.00169
20、132 6.36e-007 2.5Optimization terminated:first-order optimality is less than options.TolFun.x=0.56714303139736 0.56714303139736fval=1.0e-006*-0.40590960570519 -0.40590960570519第24页,此课件共86页哦例:求矩阵x使其满足方程,并设初始解向量为x=1,1;1,1。解:function F=myfun(x)F=x*x*x-1,2;3,4;x0=ones(2,2);%初始解向量options=optimset(Display
21、,off);%不显示优化信息x,Fval,exitflag=fsolve(myfun,x0,options)x=-0.1291 0.8602 1.2903 1.1612Fval=1.0e-003*0.1541 -0.1163 0.0109 -0.0243exitflag=1第25页,此课件共86页哦7.2无约束最优化问题求解 7.2.1 解析解法和图解法第26页,此课件共86页哦例:syms t;y=exp(-3*t)*sin(4*t+2)+4*exp(-0.5*t)*cos(2*t)-0.5;y1=diff(y,t);%求取一阶导函数 ezplot(y1,0,4)%绘制出选定区间内一阶导函数
22、曲线第27页,此课件共86页哦 t0=solve(y1)%求出一阶导数等于零的点t0=1.4528424981725411893375778048840 y2=diff(y1);b=subs(y2,t,t0)%并验证二阶导数为正 b=7.8553420253333601379464405534591 t=0:0.4:4;y=exp(-3*t).*sin(4*t+2)+4*exp(-0.5*t).*cos(2*t)-0.5;plot(t,y)第28页,此课件共86页哦单变量函数求最小值的(数值解法)%求解区间优化问题标准形式为:s.t.函数 fminbnd格式 x=fminbnd(fun,x1,
23、x2)x=fminbnd(fun,x1,x2,options)x,fval=fminbnd()%fval为目标函数的最小值 x,fval,exitflag=fminbnd()exitflag为终止迭代的条件,若exitflag0,收敛于x,exitflag=0,表示超过函数估计值或迭代的最大数字,exitflag x,fval,exitflag,output=fminbnd(x3+cos(x)+x*log(x)/exp(x),0,1)x=0.5223fval=0.3974exitflag=1output=iterations:9 funcCount:11 algorithm:golden se
24、ction search,parabolic interpolation 第30页,此课件共86页哦例:在0,5上求下面函数的最小值 解:function f=myfun(x)f=(x-3).2-1;x=fminbnd(myfun,0,5)x=3第31页,此课件共86页哦7.2.2 基于MATLAB的数值解法第32页,此课件共86页哦例:f=inline(x(1)2-2*x(1)*exp(-x(1)2-x(2)2-x(1)*x(2),x);x0=0;0;ff=optimset;ff.Display=iter;x=fminsearch(f,x0,ff)Iteration Func-count m
25、in f(x)Procedure 1 3 -0.000499937 initial 2 4 -0.000499937 reflect 72 137 -0.641424 contract outsideOptimization terminated successfully:x=0.6111 -0.3056第33页,此课件共86页哦 x=fminunc(f,0;.0,ff)Directional Iteration Func-count f(x)Step-size derivative 1 2 -2e-008 0.001 -4 2 9 -0.584669 0.304353 0.343 3 16
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 代数方程 优化 问题 精选 PPT
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内