Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#1 |
初级会员
注册日期: 2009-05-22
年龄: 41
帖子: 10
声望力: 16 ![]() |
![]()
在编写一个模拟退火算法时,有一个函数调用时报错如下"??? Attempt to execute SCRIPT an11 as a function.
Error in ==> sa_0930 at 6 f1=an11(x1);" 两函数如下: 这是an11.m函数 functon y=aneal_f1(x) y=100*(x(1)^2-x(2))^2+(1-x(1))^2; 下面是主函数 x1=[1 1]; T=10000; a=0.9; N=1; while T>1 f1=an11(x1); x2(1)=x1(1)+0.2*(rand-0.5); x2(2)=x1(2)+0.2*(rand-0.5); f2=an11(x2); if f2-f1<0 T=T*a; x1=x2; cc(N)=f2; N=N+1; elseif exp((f1-f2)/T)>rand T=T*a; x1=x2; cc(N)=f2; N=N+1; end end f1=an11(x1); disp('The result are:') disp('x(1) x(2)') disp(x1) disp('The objective fuction is:') disp(f1) tt=1:N-1; plot(tt,cc) time1=datestr(now) mm=1; while mm<=1000 aneal_f1; opf(mm)=f1; mm=mm+1; end time2=datestr(now) min(opf) max(opf) mean(opf) |
![]() |
![]() |
![]() |
#2 |
高级会员
注册日期: 2007-06-24
年龄: 70
帖子: 188
声望力: 21 ![]() |
![]()
在an11.m中,function 写错了!
|
![]() |
![]() |
![]() |
#3 |
初级会员
注册日期: 2009-05-22
年龄: 41
帖子: 10
声望力: 16 ![]() |
![]()
很感谢,的确是自己粗心了,没想到会是这个问题,得教训了
![]() |
![]() |
![]() |