matlab求非线性规划问题
目标函数:minW'HW,其中W为3行列向量,W‘为它的转置,H为3阶方阵,约数条件为:W’W=1,W>0用matlab怎么编程?我的是matlab2012a版本。我的源...
目标函数:minW'HW,其中W为3行列向量,W‘为它的转置,H为3阶方阵,约数条件为:W’W=1,W>0
用matlab怎么编程?我的是matlab2012a版本。
我的源代码如下:
function f=fun1(x);
f=-([x(1),x(2),x(3)]*[1 2 3;1 1 1;3 2 1]*[x(1);x(2);x(3)]);%创建目标函数
function [g,h]=fun2(x);
g=0;
h=[x(1),x(2),x(3)]*[x(1);x(2);x(3)]-1%创建约数函数
[x,y]fmincon('fun1',[0.1;0.1;0.1],[],[],[],[],[0.1;0.1;0.1],[],'fun2'...
,optimset)f%主程序
但运行失败,fun1和fun2可以成功创建,但主函数提示Error: Unexpected MATLAB expression.
哪位大侠可以帮帮我呢?谢谢了!
虽然我知道大侠们不稀罕悬赏,但如果对我有所帮助我可以再追加,真心感谢! 展开
用matlab怎么编程?我的是matlab2012a版本。
我的源代码如下:
function f=fun1(x);
f=-([x(1),x(2),x(3)]*[1 2 3;1 1 1;3 2 1]*[x(1);x(2);x(3)]);%创建目标函数
function [g,h]=fun2(x);
g=0;
h=[x(1),x(2),x(3)]*[x(1);x(2);x(3)]-1%创建约数函数
[x,y]fmincon('fun1',[0.1;0.1;0.1],[],[],[],[],[0.1;0.1;0.1],[],'fun2'...
,optimset)f%主程序
但运行失败,fun1和fun2可以成功创建,但主函数提示Error: Unexpected MATLAB expression.
哪位大侠可以帮帮我呢?谢谢了!
虽然我知道大侠们不稀罕悬赏,但如果对我有所帮助我可以再追加,真心感谢! 展开
2个回答
展开全部
可以运行,问题主要在于你书写格式不正确,而导致错误。
运行结果如下
>> [x,y]=fmincon('fun1',[0.1;0.1;0.1],[],[],[],[],[0.1;0.1;0.1],[],'fun2',optimset)
Warning: Trust-region-reflective algorithm does not solve this type of problem, using active-set algorithm.
You could also try the interior-point or sqp algorithms: set the Algorithm option to 'interior-point' or
'sqp' and rerun. For more help, see Choosing the Algorithm in the documentation.
> In fmincon at 472
Local minimum possible. Constraints satisfied.
fmincon stopped because the predicted change in the objective function
is less than the default value of the function tolerance and constraints
were satisfied to within the default value of the constraint tolerance.
<stopping criteria details>
Active inequalities (to within options.TolCon = 1e-006):
lower upper ineqlin ineqnonlin
1
x =
0.627962286552050
0.459703343062521
0.627961945396026
y =
-5.098076220590748
运行结果如下
>> [x,y]=fmincon('fun1',[0.1;0.1;0.1],[],[],[],[],[0.1;0.1;0.1],[],'fun2',optimset)
Warning: Trust-region-reflective algorithm does not solve this type of problem, using active-set algorithm.
You could also try the interior-point or sqp algorithms: set the Algorithm option to 'interior-point' or
'sqp' and rerun. For more help, see Choosing the Algorithm in the documentation.
> In fmincon at 472
Local minimum possible. Constraints satisfied.
fmincon stopped because the predicted change in the objective function
is less than the default value of the function tolerance and constraints
were satisfied to within the default value of the constraint tolerance.
<stopping criteria details>
Active inequalities (to within options.TolCon = 1e-006):
lower upper ineqlin ineqnonlin
1
x =
0.627962286552050
0.459703343062521
0.627961945396026
y =
-5.098076220590748
展开全部
function f=fun1(x)
f=-([x(1),x(2),x(3)]*[1 2 3;1 1 1;3 2 1]*[x(1);x(2);x(3)]); %创建目标函数
function [g,h]=fun2(x)
g=[];
h=[x(1),x(2),x(3)]*[x(1);x(2);x(3)]-1; %创建约数函数
% 主程序
% 2009a版以上,可用:
options=optimset('Algorithm','active-set','display','off','TolCon',1e-016,'TolFun',1e-016);
[x,y] = fmincon(@fun1,[0.1;0.1;0.1],[],[],[],[],[0;0;0],[],@fun2,options)
f=-([x(1),x(2),x(3)]*[1 2 3;1 1 1;3 2 1]*[x(1);x(2);x(3)]); %创建目标函数
function [g,h]=fun2(x)
g=[];
h=[x(1),x(2),x(3)]*[x(1);x(2);x(3)]-1; %创建约数函数
% 主程序
% 2009a版以上,可用:
options=optimset('Algorithm','active-set','display','off','TolCon',1e-016,'TolFun',1e-016);
[x,y] = fmincon(@fun1,[0.1;0.1;0.1],[],[],[],[],[0;0;0],[],@fun2,options)
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询