my question is how to use fmincon in for loop?

조회 수: 1 (최근 30일)
azam ghamari
azam ghamari 2018년 12월 25일
댓글: Image Analyst 2018년 12월 25일
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