Hello, I am trying to solve the system below, but I get the error message "In an assignment A(I) = B, the number of elements in B and I must be the same.". I am not sure why this is happening since I am providing 2 equations to solve for 2 variables. I didn't put here the meanbl_i and covmatbl_i equations into the fcns(1) and fcns(2) equations just for you to better visualize the problem, but I get the error message above either way. Thank you very much for the help. Best wishes. Alexandre
function omeg()
guessomega_i=0;
guesslambda_i=4.2786;
guessom=[guessomega_i;guesslambda_i];
omresult=fsolve(@om,guessom);
omega_i=omresult(1)
lambda_i=omresult(2)
end
function fcns=om(x)
omega_i=x(1);
lambda_i=x(2);
meanbl_i=req+tau*covmat*P_i'*(tau*P_i*covmat*P_i'+omega_i)^(-1)*(v_i-P_i*req);
covmatbl_i=(1+tau)*covmat-tau^(2)*covmat*P_i'*(tau*P_i*covmat*P_i'+omega_i)^(-1)*P_i*covmat;
fcns(1)=lambda_i^(-1)*covmatbl_i^(-1)*(meanbl_i-(vec1'*covmatbl_i^(-1)*vec1)^(-1)*(vec1'*covmatbl_i^(-1)*meanbl_i-lambda_i)*vec1)-w_i;
fcns(2)=w_i'*meanbl_i+phimkt*sqrt(w_i'*covmatbl_i*w_i)-Hmkt;
end
WHERE:
req=[0.0332;0.0337;0.0312;0.0335;0.0298;0.0310;0.0286;0.0285;0.0270;0.0281;0.0281;0.0288];
tau=0.0167;
v_i=0;
P_i=[0,0,0,0,0,0,0,0,0,1,-1,0];
vec1=[1;1;1;1;1;1;1;1;1;1;1;1];
w_i=[0.3552;0.0521;0.0370;0.0538;0.0184;0.0094;0.0059;0.0072;0.0050;0.2372;0.1973;0.0215];
Hmkt=-0.0093;
phimkt=-1.2816;
covmat=[0.0026,0.0028,0.0019,0.0025,0.0012,0.0016,0.0007,0.0007,0.0001,0.0005,0.0005,0.0007; 0.0028,0.0033,0.0021,0.0028,0.0014,0.0017,0.0007,0.0008,0.0002,0.0005,0.0004,0.0007; 0.0019,0.0021,0.0022,0.0016,0.0010,0.0010,0.0005,0.0005,0.0001,0.0003,0.0002,0.0004; 0.0025,0.0028,0.0016,0.0030,0.0013,0.0019,0.0009,0.0008,0.0003,0.0006,0.0006,0.0009; 0.0012,0.0014,0.0010,0.0013,0.0010,0.0008,0.0005,0.0006,0.0002,0.0003,0.0002,0.0004; 0.0016,0.0017,0.0010,0.0019,0.0008,0.0015,0.0007,0.0006,0.0003,0.0005,0.0005,0.0006; 0.0007,0.0007,0.0005,0.0009,0.0005,0.0007,0.0005,0.0004,0.0002,0.0003,0.0003,0.0003; 0.0007,0.0008,0.0005,0.0008,0.0006,0.0006,0.0004,0.0004,0.0002,0.0002,0.0002,0.0003; 0.0001,0.0002,0.0001,0.0003,0.0002,0.0003,0.0002,0.0002,0.0002,0.0001,0.0001,0.0002; 0.0005,0.0005,0.0003,0.0006,0.0003,0.0005,0.0003,0.0002,0.0001,0.0002,0.0002,0.0003; 0.0005,0.0004,0.0002,0.0006,0.0002,0.0005,0.0003,0.0002,0.0001,0.0002,0.0004,0.0003; 0.0007,0.0007,0.0004,0.0009,0.0004,0.0006,0.0003,0.0003,0.0002,0.0003,0.0003,0.0005];
Best Answer