matlab编程中出现问题,说是矩阵维度不一致 ,M文件主函数如下:function f=myobj(x)arf=linspace(0.0001,0.5233,100);K=1162;M=600;L=1650;t=281-x(1).*cos(arf+1.134);h=sqrt(x(2).^2-(x(1).*sin(1.134+arf)-x(3)).^2);s=t-h;f=abs(acot(cot(ar
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/23 07:46:52
matlab编程中出现问题,说是矩阵维度不一致 ,M文件主函数如下:function f=myobj(x)arf=linspace(0.0001,0.5233,100);K=1162;M=600;L=1650;t=281-x(1).*cos(arf+1.134);h=sqrt(x(2).^2-(x(1).*sin(1.134+arf)-x(3)).^2);s=t-h;f=abs(acot(cot(ar
matlab编程中出现问题,说是矩阵维度不一致 ,
M文件主函数如下:function f=myobj(x)
arf=linspace(0.0001,0.5233,100);
K=1162;M=600;L=1650;
t=281-x(1).*cos(arf+1.134);
h=sqrt(x(2).^2-(x(1).*sin(1.134+arf)-x(3)).^2);
s=t-h;
f=abs(acot(cot(arf)-K/L)-1.134+acos((x(1).^2+(562+s).^2+x(3).^2-x(2).^2)./(2.*x(1).*(562+s).^2+x(3).^2))-atan(2.*x(3)/(562+2.*s)));
然后命令窗口中运行出现问题了:>> A=[];b=[];Aeq=[];beq=[];
>> lb=[100,231,30]
lb =
100 231 30
>> ub=[148,258,107]
ub =
148 258 107
>> x0=[0 0 0 ]
x0 =
0 0 0
>> options=optimset('LargeScale','off','display','iter');
>> [x,fval,exitflag]=fmincon(@myobj,x0,A,b,[],[],lb,ub,@mycon,options)
Error using ==> fmincon
FMINCON cannot continue because user supplied objective function failed with the following error:
Error using ==> mrdivide
Matrix dimensions must agree.
>> [x,fval]=fmincon(@myobj,x0,A,b,[],[],lb,ub,@mycon,options)
Error using ==> fmincon
FMINCON cannot continue because user supplied objective function failed with the following error:
Error using ==> mrdivide
Matrix dimensions must agree.
matlab编程中出现问题,说是矩阵维度不一致 ,M文件主函数如下:function f=myobj(x)arf=linspace(0.0001,0.5233,100);K=1162;M=600;L=1650;t=281-x(1).*cos(arf+1.134);h=sqrt(x(2).^2-(x(1).*sin(1.134+arf)-x(3)).^2);s=t-h;f=abs(acot(cot(ar
这是最优化问题.
1 新建m文件把myobj函数贴进去,保存;
myobj函数中
atan(2.*x(3)/(562+2.*s))
改成
atan(2.*x(3)./(562+2.*s))
2 新建m文件把mycon函数贴进去,保存;
3 在command window里输入
>> A=[];b=[];Aeq=[];beq=[];
lb=[100;231;30];%%下界是列向量
ub=[148;258;107];%%上届同样是列向量
x0=[0;0;0];%%初值写成列向量形式
options=optimset('LargeScale','off','display','iter');
[x,fval,exitflag]=fmincon(@myobj,x0,A,b,[],[],lb,ub,@mycon,options)
myobj是目标函数,mycon是非线性约束条件.