Why is this assignment displaying an error?

1 回表示 (過去 30 日間)
Robert  Flores
Robert Flores 2018 年 4 月 25 日
回答済み: Star Strider 2018 年 4 月 25 日
Hello,
I am wondering why I am getting this display error. I have written another script using the same matrix, it's just a smaller square matrix. Can anyone help me in having this script run correctly. In the attachments is a snip picture of what I am seeing in the command window.
%%If 10 elements are used
E = 30*10^6;
L_0 = 6;
F = 300;
SLOPE = -1/12;
D = @(x) (SLOPE*x)+1; % This is the function of Diameter
A = @(x) (pi/4)*(D(x)^2); % This is the function of Area
L_10 = L_0/10;
k1 = (A(L_10)*E)/L_10;
k2 = (A(2*L_10)*E)/L_10;
k3 = (A(3*L_10)*E)/L_10;
k4 = (A(4*L_10)*E)/L_10;
k5 = (A(5*L_10)*E)/L_10;
k6 = (A(6*L_10)*E)/L_10;
k7 = (A(7*L_10)*E)/L_10;
% This is the Global Stiffness Matrix
K = [k1, -k1, 0, 0, 0, 0, 0, 0, 0, 0, 0;
-k1, k1+k2, -k2, 0, 0, 0, 0, 0, 0, 0, 0;
0, -k2, k2+k3, -k3, 0, 0, 0, 0, 0, 0, 0;
0, 0, -k3, k3+k4, -k4, 0, 0, 0, 0, 0, 0;
0, 0, 0, -k4, k4+k5, -k5, 0, 0, 0, 0, 0;
0, 0, 0, 0, -k5, k5+k6, -k6, 0, 0, 0, 0;
0, 0, 0, 0, 0, -k6, k6+k7, -k7, 0, 0, 0;
0, 0, 0, 0, 0, 0, -k7, k7+k8, -k8, 0, 0;
0, 0, 0, 0, 0, 0, 0, -k8, k8+k9, -k9, 0;
0, 0, 0, 0, 0, 0, 0, 0, -k9, k9+k10, -k10;
0, 0, 0, 0, 0, 0, 0, 0, 0, -k10, k10;
% This is the Global Stiffness Matrix
Stiffness = [ k1+k2, -k2, 0, 0, 0, 0, 0, 0, 0, 0;
-k2, k2+k3, -k3, 0, 0, 0, 0, 0, 0, 0;
0, -k3, k3+k4, -k4, 0, 0, 0, 0, 0, 0;
0, 0, -k4, k4+k5, -k5, 0, 0, 0, 0, 0;
0, 0, 0, -k5, k5+k6, -k6, 0, 0, 0, 0;
0, 0, 0, 0, -k6, k6+k7, -k7, 0, 0, 0;
0, 0, 0, 0, 0, -k7, k7+k8, -k8, 0, 0;
0, 0, 0, 0, 0, 0, -k8, k8+k9, -k9, 0;
0, 0, 0, 0, 0, 0, 0, -k9, k9+k10, -k10;
0, 0, 0, 0, 0, 0, 0, 0, -k10, k10;
F = [0;0;0;0;0;0;0;0;0;300];
U = inv(K2)*F

採用された回答

Star Strider
Star Strider 2018 年 4 月 25 日
You did not terminate the ‘K’ matrix with a square bracket.
Do this:
0, 0, 0, 0, 0, 0, 0, 0, 0, -k10, k10];
and the error no longer appears.
You also have to do that with the last line of ‘Stiffness’.
Also, definitions of ‘k8’, ‘k9’, and ‘k10’ are missing.
For best results, use mldivide,\ (link) to calculate ‘U’, not inv:
U = K2\F
Correct those errors and your code should work.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by