matlab程序不能运行

来源:百度知道 编辑:UC知道 时间:2024/06/05 21:20:58
这个程序总是出问题,那位看看是怎么回事。
clear;
n=1500;m=100;
c1=2;c2=2;
vmax=[10,10];alph=0.5;w=1;
x=800*rand(m,2)-400;
v=zeros(m,2);
fun=inline('-0.5+((sin(sqrt(x(:,1).^2+x(:,2).^2))).^2-0.5)./((1+0.01.*(x(:,1).^2+x(:,2).^2)).^2)','x');
p=x;i=1;
[ft,it]=min(fun(x));pg=x(it,:);
while i<=n
ftemp=fun(x);
vt=w*v+c1*rand*(p-x)+c2*rand*([pg(1)-x(:,1),pg(2)-x(:,2)]);
v=[(vt(:,1) < vmax(1)). * vt(:,1) + (vt(:,1) > = vmax(1)) * vmax(1),(vt(:,2) < vmax(2)). * vt(:,2) + (vt(:,2) > = vmax(2)) * vmax(2)];
x=x+alph*v;
lit=find(fun(x)-ftemp<0);
[ftemp,it]=min(fun(x));pgtemp=x(it,:);
pg=(ft<ftemp)*pg+(ft>ftemp)*pgtemp;
p(lit,:)=x(iit,:);
i=i+1;
end
x=pg,f=ftemp
显示??? Error: File: C:\MATLAB7\work\liziqun_1.m Line: 13 Column: 27
Missing variable or function.

clear;
n=1500;m=100;
c1=2;c2=2;
vmax=[10,10];alph=0.5;w=1;
x=800*rand(m,2)-400;
v=zeros(m,2);
fun=inline('-0.5+((sin(sqrt(x(:,1).^2+x(:,2).^2))).^2-0.5)./((1+0.01.*(x(:,1).^2+x(:,2).^2)).^2)','x');
p=x;i=1;
[ft,it]=min(fun(x));pg=x(it,:);
while i<=n
ftemp=fun(x);
vt=w*v+c1*rand*(p-x)+c2*rand*([pg(1)-x(:,1),pg(2)-x(:,2)]);
v=[(vt(:,1) < vmax(1)).* vt(:,1) + (vt(:,1) >= vmax(1)) * vmax(1),(vt(:,2) < vmax(2)).* vt(:,2) + (vt(:,2) >= vmax(2)) * vmax(2)];
x=x+alph*v;
lit=find(fun(x)-ftemp<0);
[ftemp,it]=min(fun(x));pgtemp=x(it,:);
pg=(ft<ftemp)*pg+(ft>ftemp)*pgtemp;
p(lit,:)=x(lit,:);
i=i+1;
end
x=pg,f=ftemp

变量定义错误

变量定义错误