matlab里面sin函数是角度,应用matlab求函数f(x)=sin(x)/x^2+x*cos(x)在区间【1,9】内的极值点,并说明是 极大值点还是极小值点。...

www.mh456.com防采集。

求函数极值,可以用copyfminsearch()极小值函2113数来解决。求函数极大值5261就求函数极4102小值的1653反函数。

syms x v=int(pi*x^2*sin(x)^2,0,pi);double(v) ans = 13.7674 另一种算法: x=linspace(0,pi,50);v=trapz(x,pi*x.^2.*sin(x).^2) v = 13.7674

timg?image&quality=80&size=b9999_10000&sec=1608459922003&di=f65378406263db32a942a008a9bfe5c4&imgtype=0&src=http%3A%2F%2Fsba.nww158.com%2Finclude%2Fupload%2Fckeditor%2Fimages%2F%25e8%25bd%25ac%25e7%259b%2598%25e8%25bd%25b4%25e6%2589%25bf%25e5%25ba%2594%25e7%2594%25a8-%25e7%259b%25be%25e6%259e%2584%25e6%259c%25ba%25e8%25bd%25b4%25e6%2589%25bf%25e5%25ae%2589%25e8%25a3%2585%281%29.jpg

1、函数极小值的求法

能解释一下为什么要用模拟退火法吗? 这个函数的最小值直接观察就能看出来在x=y=0处,或者用fminunc也可以求解: x=fminunc(@(x)sin(x(1)*x(2))+x(1)^2+x(2)^2,[0 0]) 当然,用模拟退火算法也很简单,换一下函数即可: x=simulannealbnd(@(x)sin

timg?image&quality=80&size=b9999_10000&sec=1608459922003&di=dcb62bb8faba632b7ab3ba4ef077725d&imgtype=0&src=http%3A%2F%2Flittlehj.com%2Fimages%2Fmoreformats-wide.jpg

>> func=@(x)(sin(x)/x^2+x*cos(x));

这是当然的。。因为这个函数本来在0点就没有定义,不妨写个if语句 if x=0 f(x)=1; end 这样的话整个函数就要用m文件储存了 function z=f(x) if x=0 z=1; else z=sin(x)/x; end

timg?image&quality=80&size=b9999_10000&sec=1608459922003&di=104c8cc4a900af5f4ee23dc276bea5b8&imgtype=0&src=http%3A%2F%2Fimage.cn.made-in-china.com%2F2f0j01ncwawlmflduf%2F%25e5%25a4%259a%25e7%2594%25a8%25e9%2580%2594%25e7%25ae%25a1%25e6%259d%25bf%25e5%2580%2592%25e8%25a7%2592%25e6%259c%25ba.jpg

>> [x,f]=fminsearch(func,4)

f = @(x)(sin(1.006*x).^2);format long;m = [100,200,1000];for i=1:3 %区间分n段等长子区间 n = m(i); xn = (0:n-1)/n*pi; %xn(i)为第i段区间左端点值 d = pi/n; %子区间宽度 xnm = xn+d/2; %区间中点 ynm = f(xnm); %区间中点的函数值 S(i) =

timg?image&quality=80&size=b9999_10000&sec=1608459922003&di=717bf2c6b1a3e65acdbd7f23162ea5ae&imgtype=0&src=http%3A%2F%2Fdblab.xmu.edu.cn%2Fwp-content%2Fuploads%2F2015%2F03%2F%25e5%25a4%25a7%25e6%2595%25b0%25e6%258d%25ae%25e6%258a%2580%25e6%259c%25af%25e5%258e%259f%25e7%2590%2586%25e4%25b8%258e%25e5%25ba%2594%25e7%2594%25a8%25e7%25ac%25ac2%25e7%2589%2588%25e5%25b0%2581%25e9%259d%25a2%25e6%258f%258f%25e8%25be%25b9--485x680.jpg

x =

3.4427  %极小值点

syms x >> limit(sin(x)/x,x,0) %x趋于0时的极限

timg?image&quality=80&size=b9999_10000&sec=1608459922003&di=4a64660ea982f6cd11140edae977289f&imgtype=0&src=http%3A%2F%2Fbdcdn.4aqq.com%2Fttf%2Ffont_%25e4%25bc%259a%25e7%2594%259f%25e8%259b%258b%25e7%259a%2584%25e5%258a%25a8%25e7%2589%25a9_60_41_84.png

f =

-3.3128  %极小值

2、函数极大值的求法

>> func=@(x)-(sin(x)/x^2+x*cos(x));

>> [x,f,h]=fminsearch(func,4)

x =

6.4407  %极大值点

f =

-6.3647  %极大值

e75fee50344c24f4b44b1c6cbb419ef4.png

求连续复函数的极值和拐点制,必要条件就是2113f'(x)=0和f''(x)=0。由于f'(x)=0和f''(x)=0在指定区间5261都有多个根,难点就4102在1653于怎样求出所有的根。我找到一个利用切比雪夫多项式逼近来求解任意函数指定区间内的所有实根的程序,用于求解本问题比较有效(n需要取比较大),请参见附件。 求解的代码如下:syms xf=x*sin(x*cos(x));df=diff(f);figure(1)clfx0=FindRealRoots(eval(['@(x)' char(df)]),0,4*pi,100);ezplot(f,[0 4*pi])hold onplot(x0,subs(f,x0),'ro')d2f=diff(f,2);figure(2)clfsubplot 211x0=FindRealRoots(eval(['@(x)' char(d2f)]),0,4*pi,100);ezplot(f,[0 4*pi])hold onplot(x0,subs(f,x0),'g>')subplot 212ezplot(df,[0 4*pi])hold onplot(x0,subs(df,x0),'ro')axis tight,用fminsearch(fun,x0)求解,该函数适应求函数的最小值。对于求函数的最大值问题,只要把函数写成最小值问题,即-fun。运算结果,当x=1.09063时,有最大值g=0.5265内容来自www.mh456.com请勿采集。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值