Error code: "Index in position 2 exceeds array bounds (must not exceed 1)." when running code for two-element spring system

I am using Matlab to code a two-element spring in FEA, based on Peter I. Kattan book's : MATLAB Guide to Finite Elements: An Interactive Approach. In it, there is an example numbered as Example 2.1, which includes codes as follows
Here is the example question:
And here is the stiffness matrix calculations:
Here is global stiffness matrix calculation
However, when I run K=SpringAssemble(K,k1,1,2), I get this error message
Can anyone help me out on this one? Thank you.

댓글 수: 1

For the last function you also need to pass y as the input value
function y = SpringElementForces(y,u)
%u.
y = y*u;
end

댓글을 달려면 로그인하십시오.

답변 (1개)

K(i,i) = K(i,i) + y(1,1);
K(i,j) = K(i,j) + y(1,2);

댓글 수: 2

k is scalar assigned to variable y defined inn the function
function y = SpringElementStiffness(k)
y = [k -k;-k k]
end
but you are trying to access the nonexistent elements by using
k(1,2)
You need to use y in place of k
Also pass the matrix y as input to the function
function y = SpringAssemble(K,y,i,j)

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Install Products에 대해 자세히 알아보기

제품

릴리스

R2019a

질문:

S.
2024년 3월 8일

댓글:

2024년 3월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by