MATLAB Answers

Having trouble getting a for loop to create similar matrices (error "Index in position 1 exceeds array bounds (must not exceed 1).")

Alexander Rinn 님이 질문을 제출함. 20 Sep 2019
최근 활동 thoughtGarden 님이 편집함. 20 Sep 2019
I am solving a system of arrays in matlab for a finite element analysis class. I am using a for loop to create L arrays that after looped will be changed based on the "Element" number that is being presented. The array is created properly the first time through the loop but the second time through it fails on line 7 each time with the error "Index in position 1 exceeds array bounds (must not exceed 1)." The first L array that is created is L=[1 0;0 1;0 0;0 0;0 0]; the second array should be L=[0 0;1 0;0 1;0 0;0 0]; Can anyone figure out how I am getting this error? Also I have used the exact same code before to make 4x5 matrices for L and it worked fine. Below is the function I use to construct the L with some other calculations. The second set of code is the inputs to the function.
function [KG,U] = Stiffness1(Elements,Nodes,E,A,L,BC,F)
KG=zeros(length(Nodes));
for i=1:length(Elements)
k(i)=(E*A(i))/L;
ke=k(i)*[1 -1;-1 1];
L0=zeros(length(Nodes),2);
L0(Elements(i,1),1)=1;
L0(Elements(i,2),2)=1;
Lt=transpose(L0);
ki=L0*ke*Lt;
KG=KG+ki;
end
end
E=10.4e6;
L=2.5;
A=[1 2 3 4];
Elements=[1 2,2 3,3 4,4 5];
Nodes=[0 0;0 2.5;0 5;0 7.5;0 10];
BC=[1 0;2 1;3 1;4 1;5 0];
F=[0 0 0 0 -1000]; %Maybe Divide by A?????
[KG,U] = Stiffness1(Elements,Nodes,E,A,L,BC,F);

  댓글 수: 0

로그인 to comment.

답변 수: 1

thoughtGarden 님의 답변 20 Sep 2019
thoughtGarden 님이 편집함. 20 Sep 2019

The issue stems from: L0(Elements(i,1),1)=1; Elements is a single row vector and thus when i iterates to 2, it fails. I'd guessing you intended to access a different index.

  댓글 수: 0

로그인 to comment.



Translated by