Info

此问题已关闭。 请重新打开它进行编辑或回答。

index exceeds array bounds

1 次查看(过去 30 天)
Kuatra Patil
Kuatra Patil 2019-4-13
关闭: MATLAB Answer Bot 2021-8-20
I have no problem with 3x3 but i get index exceeds array bounds error in 6*6 matrices. please help me.
% Gauss-Seidel Method
clc,clear,clear all
E1 = 181*10^9; E2 = 10.3*10^9; E3 = 10.3*10^9;
G12 = 7.17*10^9; G23 = 3*10^9; G31=7*10^9;
v12 = 0.28; v23 = 0.60; v13 = 0.27;
v21=(E2/E1)*(v12); v32=(E3/E2)*(v23); v31=(E3/E1)*(v13);
delta = (1-v12*v21-v23*v32-v13*v31-2*v21*v32*v13)/(E1*E2*E3);
Q11 = 120*10^6; Q22 = 40*10^6; Q33=0;
T23 = 0; T13 = 0; T12 = 0;
l1=1000; l2=500; l3=40;
%6*6 coefficient matrix
A=[(1-v23*v32)/(E2*E3*delta) (v21+v23*v31)/(E2*E3*delta) (v31+v21*v32)/(E2*E3*delta) 0 0 0; (v21+v23*v31)/(E2*E3*delta) (1-v13*v31)/(E1*E3*delta) (v32+v12*v31)/(E1*E3*delta) 0 0 0; (v31+v21*v32)/(E2*E3*delta) (v32+v12*v31)/(E1*E3*delta) (1-v12*v21)/(E1*E2*delta) 0 0 0; 0 0 0 G23 0 0; 0 0 0 0 G31 0; 0 0 0 0 0 G12] %coeff matrix
b=[Q11 ; Q22 ; Q33]; %RBS vector
[m,n]=size(A);
if(m~=n)
error('matrix A must be square')
end
C=A;
e11=0; e22=0; e33=0; y23=0; y13=0; y12=0;
for i=1:n
C(i,i)=0;
x(i)=0;
end
x=x'; %convert vector matrix
for i=1:n
C(i,1:n)=C(i,1:n)/A(i,i);
end
for i=1:n
d(i)=b(i)/A(i,i);
end
iter=0;
ea=100*ones(n,1); es=1.0;
fprintf('Iteration x(1) x(2) x(3) ea(1) ea(2) ea(3)\n')
while(max(ea)>es)
xold=x;
for i=1:n
x(i)=d(i)-C(i,:)*x;
ea(i)=abs((x(i)-xold(i))/x(i))*100;
end
iter=iter+1;
fprintf('%d %8.6f %8.6f %8.6f ',iter,x(1),x(2),x(3));
fprintf(' %4.3f %4.3f %4.3f\n',ea(1),ea(2),ea(3));
end

回答(1 个)

Walter Roberson
Walter Roberson 2019-4-13
Your A matrix is 6 x 6. Your b matrix is 3 x 1. You loop i = 1 to number of rows in A, so i = 1 : 6, and try to access A(i,i) and b(i), but with b only being length 3, A(4,4) is valid but b(4) is not.

标签

Community Treasure Hunt

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

Start Hunting!

Translated by