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 件のコメント
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 Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!