MATLAB Answers

Error "Index in position 1 exceeds array bounds (must not exceed 1)" for a matrix that has a size of 2000x11

10 views (last 30 days)
Swayam Shree
Swayam Shree on 9 Jul 2020
Commented: Swayam Shree on 10 Jul 2020
I am trying to write a code for generating the strain in a marticualr material. However as I am running the code I am getting the error as listed in the title for line 68 C(i,j)=(-lamda(i,j)+4*A(i,j)/3)/(Kl+4*G(i,j)/3); of the following code:
P.S timenode=2000 and spacenode =11. These are values this code is pulling from another matlab file in the same directory.
clc;
G=zeros(timenode,spacenode);
epsilonzz=zeros(timenode,spacenode);
epsilonxx=zeros(timenode,spacenode);
A=zeros(timenode,spacenode);
B=zeros(timenode,spacenode);
C=zeros(timenode,spacenode);
lamda=zeros(timenode,spacenode);
sigmaxx=zeros(timenode,spacenode);
Kl=3.5e9;
Kg=2.3e9;
syms q
q=zeros(50,1);
for j=1:spacenode
for i=1:timenode
if(T(i,j)<Tg)
q(j,1)=i;
break
end
end
end
E=2.1e9;
nu=0.38;
g=E/(2*(1+nu));
t1=0.1;
t2=100;
t3=100000;
g1=0.9944*g;
g2=0.0036*g;
g3=0.0020*g;
G=zeros(timenode,spacenode);
for j=1:spacenode
for i=2:timenode
xmin=ksi(i-1,j);
temp=ksi(i,j);
xmax=ksi(i,j);
fun1=@(x) g1*exp(-(temp-x)/t1);
fun2=@(x) g2*exp(-(temp-x)/t2);
fun3=@(x) g3*exp(-(temp-x)/t3);
val_1=integral(fun1,xmin,xmax);
val_2=integral(fun2,xmin,xmax);
val_3=integral(fun3,xmin,xmax);
G(i,j)=(val_1+val_2+val_3)/(xmax-xmin);
end
end
for i=2:timenode
for j=1:spacenode
if (i==2)
A(i,j)=-G(i,j)*(epsilonzz(i-1,j)-epsilonxx(i-1,j));
elseif (i==3)
A(i,j)=(-G(i,j)*(epsilonzz(i-1,j)-epsilonxx(i-1,j)))+(G(2,j)*(epsilonzz(2,j)-epsilonzz(1,j)-epsilonxx(2,j)+epsilonxx(i,j)));
else
tempvalue=0;
tempcounter=i-1;
for p=2:tempcounter
value=G(p,j)*(epsilonzz(p,j)-epsilonzz(p-1,j)-epsilonxx(p,j)+epsilonxx(p-1,j));
tempvalue=tempvalue+value;
end
A=(-G(i,j)*(epsilonzz(i-1,j)-epsilonxx(i-1,j)))+tempvalue;
end
B(i,j)=-(2*Kl-4*G(i,j)/3)/(Kl+4*G(i,j)/3);
if(T(i,j)>Tg)
lamda(i,j)=-3*epsilon(i,j)*Kl;
else
f=q(j,1);
lamda(i,j)=-3*Kg*epsilon(i,j)-(Kg-Kl)*(epsilonxx(f,j)+2*epsilonzz(f,j)-3*epsilon(f,j));
end
C(i,j)=(-lamda(i,j)+4*A(i,j)/3)/(Kl+4*G(i,j)/3);
end
end

  0 Comments

Sign in to comment.

Accepted Answer

More Answers (1)

Matt J
Matt J on 10 Jul 2020
Edited: Matt J on 10 Jul 2020
I am getting the error as listed in the title for line 68 C(i,j)=(-lamda(i,j)+4*A(i,j)/3)/(Kl+4*G(i,j)/3); of the following code:
You should pause the code at that line when the error occurs and examine the state of the variables there. What is the size of all the variables on the RHS? And what are the values of i and j?

  0 Comments

Sign in to comment.

Products


Release

R2020a