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
2024 年 3 月 8 日
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 件)
VBBV
2024 年 3 月 8 日
K(i,i) = K(i,i) + y(1,1);
K(i,j) = K(i,j) + y(1,2);
2 件のコメント
VBBV
2024 年 3 月 8 日
Also pass the matrix y as input to the function
function y = SpringAssemble(K,y,i,j)
参考
カテゴリ
Help Center および File Exchange で Install Products についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!