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

9 次查看(过去 30 天)
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 个)

VBBV
VBBV 2024-3-8
K(i,i) = K(i,i) + y(1,1);
K(i,j) = K(i,j) + y(1,2);
  2 个评论
VBBV
VBBV 2024-3-8
编辑:VBBV 2024-3-8
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Install Products 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by