my question is how to use fmincon in for loop?

1 Ansicht (letzte 30 Tage)
azam ghamari
azam ghamari am 25 Dez. 2018
Kommentiert: Image Analyst am 25 Dez. 2018
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 Kommentare
madhan ravi
madhan ravi am 25 Dez. 2018
upload u T B x all the undefined parameters and your full code
Image Analyst
Image Analyst am 25 Dez. 2018
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

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by