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!