Subscripted assignment dimension mismatch in linprog optimization

1 回表示 (過去 30 日間)
Stefano Di Vito
Stefano Di Vito 2018 年 3 月 29 日
回答済み: Alan Weiss 2018 年 4 月 2 日
Hello everybody! I get the following error while performing my linear program (in order to calculate the objective function value on 100 different points.) Here's the code:
T=size(X,1);
N=size(X,2);
M=2+N;
tau=zeros(N,P);
Xtau=zeros(P,T);
H=zeros(P,T+M);
for j=1:P % P is the number of portfolios
tau(:,j)=matpesi(:,j); % weights vector
Xtau(j,:)=(X*tau(:,j))'; %obj function variables Beta-coeff. row-vector
H(j,:)=[1 -1 zeros(1,N) -1/T*(Xtau(j,:))]; % each row of the matrix h contains the coefficients of objective function
Aeq=[ones(N,1) -ones(N,1) -eye(N) -1/T*(X')];
beq=zeros(N,1);
C=-eye(T,T);
for s=1:T-1
C(s,s+1)=1;
end
A=[zeros(T,M) C; -eye(M,T+M) ];
b=[-1/T*ones(T,1); zeros(M,1)];
end
x=zeros(T+M,P);
for c=1:P
f=H(c,:);
options = optimoptions('linprog','Algorithm','interior-point','Display','final','MaxIterations',10e5);
[x(:,c),fval(:,c),exitflag]=linprog(f,A,b,Aeq,beq)
fval(fval<1.0000e-6)=0.0;
end
end
Once i run the code i get the error written in the title. I'm facing problems at indexing the "f" coefficient vector. To be clearer, i should perform the LP for each of the 100 rows of matrix H( each row should be a "f"coeff. vector for the function linprog.) This means i should perform the test on each of the 100 portfolios. Literally, i should obtain a vector of fvals, as each one of its elements should tell me if the correspondant portfolio is efficient or not under second order stochastic dominance assumptions. Anyone could help me? Thank you in advance

回答 (1 件)

Alan Weiss
Alan Weiss 2018 年 4 月 2 日
I am suspicious of this line:
f=H(c,:);
It seems that you intended to write
f=H(C,:);
Alan Weiss
MATLAB mathematical toolbox documentation

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by