赞
踩
- clc,clear
- fh = @(x)2*exp(-x).*sin(x);
- Xrange = [0,8];
- gx = @(x)3*exp(-x)*0.8.*sin(x);
- fplot(fh,Xrange,'r-*','LineWidth',1.5)
- hold on
- grid on
- fplot(gx,Xrange,'b-o','LineWidth',1.5)
- axis([-0.5,8.5,-0.1,0.85])
- legend('fh = @(x)2*exp(-x).*sin(x)','gx = @(x)3*exp(-x)*0.8.*sin(x)')
- legend('boxoff')
- title('fplot函数绘制示例')
- xlabel('X')
- ylabel('Y')
- function y = eqsfun_fplot(x)
- y(:,1) = 200*sin(x)./x;
- y(:,2) = x.^2 - 3.5*x + 10;
- end
- clc,clear
- fplot(@eqsfun_fplot,[-20,20],'LineWidth',1.5)
- grid on
- legend('y_1 = 200*sin(x)./x','y_2 = x.^2 - 3.5*x + 10')
- legend('boxoff')
一元函数极值
- clc,clear
- fh = @(x)x - 1./x + 5;
- fplot(fh,[-10,10],'b-','LineWidth',1.5)
- grid on
- % fminbnd: Single-variable bounded nonlinear function minimization.
- % exitflag > 0收敛到解,exitflag = 0已达最大迭代次数,exitflag < 0不收敛;
- options = optimset('Display','iter','PlotFcns',@optimplotfval,'TolX',1e-6);
- [x,fval,exitflag,output] = fminbnd(fh,-10,1,options)
- fh_min = @(x)2*exp(-x).*sin(x); %最小值匿名函数
- fh_max = @(x)-2*exp(-x).*sin(x); %最大值匿名函数,前加负号
- [xmin,fmin,exitflag] = fminbnd(fh_min,0,8);
- [xmax,fmax,exitflag] = fminbnd(fh_max,0,8);
- fplot(fh_min,[0,8])
- axis([0 8 -0.1 0.7]) %改变坐标轴的范围
- text(xmin+0.1,fmin,['最小值点:',num2str(fmin)])
- text(xmax+0.1,-fmax,['最大值点:',num2str(-fmax)])
- hold on
- plot(xmin,fmin,'ro', xmax,-fmax, 'bo')
- grid on
多元函数的极小值:
- % [x,fval,exitflag,output] = fminsearch(@fh, x0, options)
- % 此函数使用单纯型法搜索最值。其中声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/275598推荐阅读
相关标签
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。