MATLAB: Is this assignment displaying an error

errormatrix

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

Best Answer

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.