my question is how to use fmincon in for loop?

1 次查看(过去 30 天)
Hi every body, I write a code in fmincone , it gives me this error :
Index exceeds matrix dimensions.
Error in test>@(u)2*norm(u(z))^2+3*norm(y{1})^2
Error in fmincon (line 536)
initVals.f = feval(funfcn{3},X,varargin{:});
Error in test (line 47)
u(z)=fmincon(fun,u,[],[],B,T{k_max-z}-A*x{z},-2,2)
Caused by:
Failure in initial objective function
evaluation. FMINCON cannot continue.
My code is:
for z=1:10
fun = @(u(z))2*norm(u(z))^2+3*norm(y{1})^2
u(z)=fmincon(fun,u(1),[],[],B,T{10-z}-A*x{z},-2,2)
end
where T{10-z}-A*x{z}, y{z} are defined before.
  2 个评论
madhan ravi
madhan ravi 2018-12-25
upload u T B x all the undefined parameters and your full code
Image Analyst
Image Analyst 2018-12-25
Azam's "Answer" moved here since it's not an answer to the original question:
A=[0.8 0;0 0.7]
B=[1;1];
C=[1.2 1];
D=0;
x{1}=[1;1];
k_max=10;
for i=1:k_max
p(i,:)=[i/20 -i/30];
K(i,:)=place(A,B,p(i,:));
end
for k=1:k_max
u(k,:)=-K(k,:)*x{k};
x{k+1}=A*x{k}+B*u(k,:);
y{k}=C*x{k};
end
T{1}=x{k_max}
for j=2:10
T{j}= T{j-1}+x{k_max+1-j};
end

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

产品


版本

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by