Error using sub2ind out of range subscript
7 views (last 30 days)
Show older comments
clear all ;
global theta sigma tau rho
theta =0.9563E0 ; sigma = 1.0243E0 ; tau =0.05803E0 ; rho= -0.04266E0 ;
n_star1=zeros(3,1); n_star2= zeros(3,1); b_star1=zeros(3,1);
b_star2=zeros(3,1);m_star1=zeros(3,1);m_star2=zeros(1,3);
a_star1=zeros(3,1);a_star2=zeros(3,1);kappa_1=1;kappa_2=-1;
U1(1,1)= theta ; U1(1,2)= rho ;U1(1,3)= rho; U1(2,1)=U1(1,2);
U1(2,2)= sigma ; U1(2,3) = tau; U1(3,1)=U1(1,3);
U1(3,2)=U1(2,3); U1(3,3)= sigma;
U2(1,1)= theta; U2(1,2)= -rho; U2(1,3)= -rho; U2(2,1)=U2(1,2);
U2(2,2)= sigma ; U2(2,3) = tau; U2(3,1)=U2(1,3);
U2(3,2)=U2(2,3); U2(3,3)= sigma;
U3(1,1)= theta; U3(1,2)= -rho; U3(1,3)= rho; U3(2,1)=U3(1,2);
U3(2,2)= sigma ; U3(2,3) = -tau; U3(3,1)=U3(1,3);
U3(3,2)=U3(2,3); U3(3,3)= sigma;
U4(1,1)= theta; U4(1,2)= rho; U4(1,3)= -rho; U4(2,1)=U4(1,2);
U4(2,2)= sigma ; U4(2,3) = -tau; U4(3,1)=U4(1,3);
U4(3,2)=U4(2,3); U4(3,3)= sigma;
U5(1,1)= sigma; U5(1,2)= rho; U5(1,3)= tau; U5(2,1)=U5(1,2);
U5(2,2)= theta ; U5(2,3) = rho; U5(3,1)=U5(1,3);
U5(3,2)=U5(2,3); U5(3,3)= sigma;
U6(1,1)= sigma; U6(1,2)= -rho; U6(1,3)= tau; U6(2,1)=U6(1,2);
U6(2,2)= theta ; U6(2,3) = -rho; U6(3,1)=U6(1,3);
U6(3,2)=U6(2,3); U6(3,3)= sigma;
U7(1,1)= sigma; U7(1,2)= -rho; U7(1,3)= -tau; U7(2,1)=U7(1,2);
U7(2,2)= theta ; U7(2,3) = rho; U7(3,1)=U7(1,3);
U7(3,2)=U7(2,3); U7(3,3)= sigma;
U8(1,1)= sigma; U8(1,2)= rho; U8(1,3)= -tau; U8(2,1)=U8(1,2);
U8(2,2)= theta ; U8(2,3) = -rho; U8(3,1)=U8(1,3);
U8(3,2)=U8(2,3); U8(3,3)= sigma;
U9(1,1)= sigma; U9(1,2)= tau; U9(1,3)= rho; U9(2,1)=U9(1,2);
U9(2,2)= sigma ; U9(2,3) = rho; U9(3,1)=U9(1,3);
U9(3,2)=U9(2,3); U9(3,3)= theta;
U10(1,1)= sigma; U10(1,2)= tau; U10(1,3)= -rho; U10(2,1)=U10(1,2);
U10(2,2)= sigma ; U10(2,3) = -rho; U10(3,1)=U10(1,3);
U10(3,2)=U10(2,3); U10(3,3)= theta;
U11(1,1)= sigma; U11(1,2)= -tau; U11(1,3)= rho; U11(2,1)=U11(1,2);
U11(2,2)= sigma ; U11(2,3) = -rho; U11(3,1)=U11(1,3);
U11(3,2)=U11(2,3); U11(3,3)= theta;
U12(1,1)= sigma; U12(1,2)= -tau; U12(1,3)= -rho; U12(2,1)=U12(1,2);
U12(2,2)= sigma ; U12(2,3) = rho; U12(3,1)=U12(1,3);
U12(3,2)=U12(2,3); U12(3,3)= theta;
C1= inv(U1)*U3*U3*inv(U1);
[V, N]=eig(C1);
lambda_3= N(1,1);lambda_2= N(2,2); lambda_1= N(3,3); *% Error was being shown in this line*
e3 = V(1:3,1) ;e2=V(1:3,2) ;e1=V(1:3,3);
Also, explain me the meaning of this error :
Error in sym/subsref (line 766) R_tilde = sub2ind(size(L), Idx.subs{:});
0 Comments
Answers (2)
Ced
on 26 Mar 2016
Your code runs without error for me.
Why do you have the variables declared as global? This is something to avoid whenever possible (aka always), and I don't see a reason to have global variables here.
Also, the error seems to come from a symbolic call, but I don't see any symbolic variables in that code?
Try to copy the script to some other location ( to check if you have overshadowing functions that could cause the problem ), and remove the global declaration, and try running the code again.
0 Comments
dpb
on 26 Mar 2016
Edited: dpb
on 26 Mar 2016
Ugleee code to the extreme... :(
Format your code; don't use run-on continuation lines wildly.
One way to build the initial matrices that is at least a little bit more readable and simpler to debug if nothing else would be
>> U1=diag([theta sigma sigma],0) + ...
diag([rho tau],-1) + ...
diag(rho,-2); % load lower triagonal
>> U1=U1+tril(U1,-1).' % load upper triagonal from lower transpose
U1 =
0.9563 -0.0427 -0.0427
-0.0427 1.0243 0.0580
-0.0427 0.0580 1.0243
>>
There is no indexing problem on the line marked; the ind2sub message is from a symbolic toolbox function call and there's no symbolic in sight in the above code snippet.
0 Comments
See Also
Categories
Find more on Function Creation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!