Why is this assignment displaying an error?
2 views (last 30 days)
Show older comments
Robert Flores
on 25 Apr 2018
Answered: Star Strider
on 25 Apr 2018
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
0 Comments
Accepted Answer
Star Strider
on 25 Apr 2018
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.
U = K2\F
Correct those errors and your code should work.
0 Comments
More Answers (0)
See Also
Categories
Find more on Operators and Elementary Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!