MATLAB运行程序后出现??? Undefined command/function 'a'...急急急。。急急急。。
是要解决一个数学模型具体代码如下:目标函数m文件fun5.mfunctionf=fun5(x);f=x(1)+x(2)+x(3)+x(4)+x(5)+x(6)约束函数m文...
是要解决一个数学模型
具体代码如下:
目标函数m文件 fun5.m
function f=fun5(x);
f=x(1)+x(2)+x(3)+x(4)+x(5)+x(6)
约束函数m文件 mcon.m
function [g,ceq]=mcon(x)
g=[a(1,2)^2-(b0(1,2)+x(1)/2+x(2)/2)^2;a(1,3)^2-(b0(1,3)+x(1)/2+x(3)/2)^2;a(1,4)^2-(b0(1,4)+x(1)/2+x(4)/2)^2;a(1,5)^2-(b0(1,5)+x(1)/2+x(5)/2)^2;a(1,6)^2-(b0(1,6)+x(1)/2+x(6)/2)^2;a(2,3)^2-(b0(2,3)+x(2)/2+x(3)/2)^2;a(2,4)^2-(b0(2,4)+x(2)/2+x(4)/2)^2;a(2,5)^2-(b0(2,5)+x(2)/2+x(5)/2)^2;a(2,6)^2-(b0(2,6)+x(2)/2+x(6)/2)^2;a(3,4)^2-(b0(3,4)+x(3)/2+x(4)/2)^2;a(3,5)^2-(b0(3,5)+x(3)/2+x(5)/2)^2;a(3,6)^2-(b0(3,6)+x(3)/2+x(6)/2)^2;a(4,5)^2-(b0(4,5)+x(4)/2+x(5)/2)^2;a(4,6)^2-(b0(4,6)+x(4)/2+x(6)/2)^2;a(5,6)^2-(b0(5,6)+x(5)/2+x(6)/2)^2];
主程序m文件 you3.m
clear;clc
x0=[150 85 150 145 130 0];
y0=[140 85 155 50 150 0];
q=[243 236 220.5 159 230 52];
xy1=x0+i*y0;
xy2=exp(i*q*pi/180);
for m=1:6
for n=1:6
if n~=m
b0(m,n)=angle((xy2(n)-xy2(m))/(xy1(m)-xy1(n)));
d1=(x0(m)-x0(n)).^2;
d2=(y0(m)-y0(n)).^2;
d=d1+d2;
r(m,n)=sqrt(d);
a(m,n)=asin(8/r(m,n));
end
end
end
deltaini=zeros(1,6);
vlb=-pi*ones(1,6)/6;vub=pi*ones(1,6)/6;
dt=fmincon('fun5',deltaini,[],[],[],[],vlb,vub,'mcon');
d1=dt*180/pi
提示错误是:??? Error using ==> fmincon
FMINCON cannot continue because user supplied nonlinear constraint function
failed with the following error:
Undefined command/function 'a'.
Error in ==> you3 at 29
dt=fmincon('fun5',deltaini,[],[],[],[],vlb,vub,'mcon');
怎么会出现'a'呢。。我都没用到这个函数或命令。。请各位帮帮忙解答一下。。谢谢。。感激不尽。。 展开
具体代码如下:
目标函数m文件 fun5.m
function f=fun5(x);
f=x(1)+x(2)+x(3)+x(4)+x(5)+x(6)
约束函数m文件 mcon.m
function [g,ceq]=mcon(x)
g=[a(1,2)^2-(b0(1,2)+x(1)/2+x(2)/2)^2;a(1,3)^2-(b0(1,3)+x(1)/2+x(3)/2)^2;a(1,4)^2-(b0(1,4)+x(1)/2+x(4)/2)^2;a(1,5)^2-(b0(1,5)+x(1)/2+x(5)/2)^2;a(1,6)^2-(b0(1,6)+x(1)/2+x(6)/2)^2;a(2,3)^2-(b0(2,3)+x(2)/2+x(3)/2)^2;a(2,4)^2-(b0(2,4)+x(2)/2+x(4)/2)^2;a(2,5)^2-(b0(2,5)+x(2)/2+x(5)/2)^2;a(2,6)^2-(b0(2,6)+x(2)/2+x(6)/2)^2;a(3,4)^2-(b0(3,4)+x(3)/2+x(4)/2)^2;a(3,5)^2-(b0(3,5)+x(3)/2+x(5)/2)^2;a(3,6)^2-(b0(3,6)+x(3)/2+x(6)/2)^2;a(4,5)^2-(b0(4,5)+x(4)/2+x(5)/2)^2;a(4,6)^2-(b0(4,6)+x(4)/2+x(6)/2)^2;a(5,6)^2-(b0(5,6)+x(5)/2+x(6)/2)^2];
主程序m文件 you3.m
clear;clc
x0=[150 85 150 145 130 0];
y0=[140 85 155 50 150 0];
q=[243 236 220.5 159 230 52];
xy1=x0+i*y0;
xy2=exp(i*q*pi/180);
for m=1:6
for n=1:6
if n~=m
b0(m,n)=angle((xy2(n)-xy2(m))/(xy1(m)-xy1(n)));
d1=(x0(m)-x0(n)).^2;
d2=(y0(m)-y0(n)).^2;
d=d1+d2;
r(m,n)=sqrt(d);
a(m,n)=asin(8/r(m,n));
end
end
end
deltaini=zeros(1,6);
vlb=-pi*ones(1,6)/6;vub=pi*ones(1,6)/6;
dt=fmincon('fun5',deltaini,[],[],[],[],vlb,vub,'mcon');
d1=dt*180/pi
提示错误是:??? Error using ==> fmincon
FMINCON cannot continue because user supplied nonlinear constraint function
failed with the following error:
Undefined command/function 'a'.
Error in ==> you3 at 29
dt=fmincon('fun5',deltaini,[],[],[],[],vlb,vub,'mcon');
怎么会出现'a'呢。。我都没用到这个函数或命令。。请各位帮帮忙解答一下。。谢谢。。感激不尽。。 展开
3个回答
展开全部
非线性约束条件修改:
function [c,ceq]=mcon(x)
x0=[150 85 150 145 130 0];
y0=[140 85 155 50 150 0];
q=[243 236 220.5 159 230 52];
xy1=x0+i*y0;
xy2=exp(i*q*pi/180);
for m=1:6
for n=1:6
if n~=m
b0(m,n)=angle((xy2(n)-xy2(m))/(xy1(m)-xy1(n)));
d1=(x0(m)-x0(n)).^2;
d2=(y0(m)-y0(n)).^2;
d=d1+d2;
r(m,n)=sqrt(d);
a(m,n)=asin(8/r(m,n));
end
end
end
c=[a(1,2)^2-(b0(1,2)+x(1)/2+x(2)/2)^2;
a(1,3)^2-(b0(1,3)+x(1)/2+x(3)/2)^2;
a(1,4)^2-(b0(1,4)+x(1)/2+x(4)/2)^2;
a(1,5)^2-(b0(1,5)+x(1)/2+x(5)/2)^2;
a(1,6)^2-(b0(1,6)+x(1)/2+x(6)/2)^2;
a(2,3)^2-(b0(2,3)+x(2)/2+x(3)/2)^2;
a(2,4)^2-(b0(2,4)+x(2)/2+x(4)/2)^2;
a(2,5)^2-(b0(2,5)+x(2)/2+x(5)/2)^2;
a(2,6)^2-(b0(2,6)+x(2)/2+x(6)/2)^2;
a(3,4)^2-(b0(3,4)+x(3)/2+x(4)/2)^2;
a(3,5)^2-(b0(3,5)+x(3)/2+x(5)/2)^2;
a(3,6)^2-(b0(3,6)+x(3)/2+x(6)/2)^2;
a(4,5)^2-(b0(4,5)+x(4)/2+x(5)/2)^2;
a(4,6)^2-(b0(4,6)+x(4)/2+x(6)/2)^2;
a(5,6)^2-(b0(5,6)+x(5)/2+x(6)/2)^2];
ceq=[];
%%%%保存
>> deltaini=zeros(1,6)';%%列向量
vlb=(-pi*ones(1,6)/6)';vub=(pi*ones(1,6)/6)';%%同样也是列向量
options=optimset('LargeScale','off');
[dt,fval]=fmincon('fun5',deltaini,[],[],[],[],vlb,vub,'mcon',options)
Optimization terminated: first-order optimality measure less
than options.TolFun and maximum constraint violation is less
than options.TolCon.
Active inequalities (to within options.TolCon = 1e-006):
lower upper ineqlin ineqnonlin
1 3
9
12
13
14
dt =
-0.5236
-0.3424
-0.0981
-0.1427
0.0927
0.1614
fval =
-0.8526
function [c,ceq]=mcon(x)
x0=[150 85 150 145 130 0];
y0=[140 85 155 50 150 0];
q=[243 236 220.5 159 230 52];
xy1=x0+i*y0;
xy2=exp(i*q*pi/180);
for m=1:6
for n=1:6
if n~=m
b0(m,n)=angle((xy2(n)-xy2(m))/(xy1(m)-xy1(n)));
d1=(x0(m)-x0(n)).^2;
d2=(y0(m)-y0(n)).^2;
d=d1+d2;
r(m,n)=sqrt(d);
a(m,n)=asin(8/r(m,n));
end
end
end
c=[a(1,2)^2-(b0(1,2)+x(1)/2+x(2)/2)^2;
a(1,3)^2-(b0(1,3)+x(1)/2+x(3)/2)^2;
a(1,4)^2-(b0(1,4)+x(1)/2+x(4)/2)^2;
a(1,5)^2-(b0(1,5)+x(1)/2+x(5)/2)^2;
a(1,6)^2-(b0(1,6)+x(1)/2+x(6)/2)^2;
a(2,3)^2-(b0(2,3)+x(2)/2+x(3)/2)^2;
a(2,4)^2-(b0(2,4)+x(2)/2+x(4)/2)^2;
a(2,5)^2-(b0(2,5)+x(2)/2+x(5)/2)^2;
a(2,6)^2-(b0(2,6)+x(2)/2+x(6)/2)^2;
a(3,4)^2-(b0(3,4)+x(3)/2+x(4)/2)^2;
a(3,5)^2-(b0(3,5)+x(3)/2+x(5)/2)^2;
a(3,6)^2-(b0(3,6)+x(3)/2+x(6)/2)^2;
a(4,5)^2-(b0(4,5)+x(4)/2+x(5)/2)^2;
a(4,6)^2-(b0(4,6)+x(4)/2+x(6)/2)^2;
a(5,6)^2-(b0(5,6)+x(5)/2+x(6)/2)^2];
ceq=[];
%%%%保存
>> deltaini=zeros(1,6)';%%列向量
vlb=(-pi*ones(1,6)/6)';vub=(pi*ones(1,6)/6)';%%同样也是列向量
options=optimset('LargeScale','off');
[dt,fval]=fmincon('fun5',deltaini,[],[],[],[],vlb,vub,'mcon',options)
Optimization terminated: first-order optimality measure less
than options.TolFun and maximum constraint violation is less
than options.TolCon.
Active inequalities (to within options.TolCon = 1e-006):
lower upper ineqlin ineqnonlin
1 3
9
12
13
14
dt =
-0.5236
-0.3424
-0.0981
-0.1427
0.0927
0.1614
fval =
-0.8526
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
leadc是你自定的函数吧,有没有放在你的workspace里面?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询