完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
为什么运行有错?谢谢!出现好像是找不到定义的函数问题;出现以下:???function [x,minf] = minSimSearch(f,x,alpha,sita,gama,beta,var,eps) 代码如下:| Error: Function definitions are not permitted at the prompt or in scripts. function [x,minf] = minSimSearch(f,x,alpha,sita,gama,beta,var,eps) format long; if nargin ==7 eps = 1.0e-6; end N = size(X); n = N(2); FX = zeros(1,n); while 1 for i=1:n FX(i) = Funval(f,var,X(:,i)); end [XS,IX] = sort(FX); Xsorted = X(:,IX); px = sum(Xsorted(:,1:(n-1)),2)/(n-1); Fpx = Funval(f,var,px); SumF = 0; for i=1:n SumF = SumF + (FX(IX(I))-Fpx)^2; end SumF = sqrt(SumF/n); if SumF <= eps x = Xsorted(:,1); break; else x2 = px + alpha*(px - Xsorted(:,n)); fx2 = Funval(f,var,x2); if fx2 < XS(1) x3 = px + gama*(x2 - px); fx3 = Funval(f,var,x3); if fx3 < XS(1) Xsorted(:,n) = x3; X = Xsorted; continue; else Xsorted(:,n) = x2; X = Xsorted; continue; end else if fx2 < XS(N-1) Xsorted(:,n) = x2; X = Xsorted; continue; else if fx2 < XS(n) Xsorted(:,n) = x2; end x4 = px + beta*(Xsorted(:,n) - px); fx4 = Funval(f,var,x4); FNnew = Funval(f,var,Xsorted(:,n)); if fx4 < FNnew Xsorted(:,n) = x4; X = Xsorted; continue; else x0 = Xsorted(:,1); for i=1:n Xsorted(:,j) = x0 + sita*(Xsorted(:,j) - x0); end end end end end X = Xsorted; end minf = Funval(f,var,x); format short; syms t s; f = 3*t^2+s^2-t*s+3*s-5; X=[-10 1 8;-10 4 8]; [x,mf] = minSimpSearch(f,x1.2,0.5,2,0.3,[t s])
|
|
相关推荐
2个回答
|
|
虽然我刚学matlab不懂怎么解决,但是你发帖求助一定要说明程序的作用,错在哪里,不然没人会看的
|
|
|
|
哦,谢谢啦,我也是才开始跟着课本学,老是出错 |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1391 浏览 1 评论
200圆!求助大佬给一份VSG并网和离网模式的simulink仿真
1692 浏览 0 评论
MATLAB(3)--矩阵的引用(sub2ind、ind2sub、reshape函数使用)
2503 浏览 0 评论
2841 浏览 0 评论
4086 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-17 20:12 , Processed in 0.606038 second(s), Total 79, Slave 60 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号