Matrix dimensions must agree

1 view (last 30 days)
Meaghan
Meaghan on 17 Oct 2017
Answered: KSSV on 17 Oct 2017
Hi, I am having trouble with solving a system of linear equations. I am getting an error that the matrix dimensions must agree and i cannot divide a/b.
if true
x1=167.48;
x2 = 355.63;
x3 = 355.63;
x4=264.58;
x5=62.93;
x6=167.48;
a= 1000.*(6+.005.*x1)./1.1 ;
b= 1000.*(6+.005.*x2)./1.1 ;
c= 1000.*(6+.005.*x3)./1.1 ;
d= 1000.*(6+.005.*x4)./1.1 ;
e= 1000.*(6+.005.*x5)./1.1;
f= 1000.*(6+.005.*x6)./1.1;
g= (1000.*(6+.005.*x1)/1.1).^-1;
h= (1000.*(6+.005.*x2)/1.1).^-1;
i= (1000.*(6+.005.*x3)/1.1).^-1;
j=(1000.*(6+.005.*x4)/1.1).^-1 ;
k=(1000.*(6+.005.*x5)/1.1).^-1;
l=(1000.*(6+.005.*x6)/1.1).^-1 ;
r = -.0024
a = [1,0,0,0,0,0, 0,0,0,0,0,0, g,0,0,0,0,0 0,0,0,0,0,0;
0,1,0,0,0,0, 0,0,0,0,0,0, 0,h,0,0,0,0 0,0,0,0,0,0;
0,0,1,0,0,0, 0,0,0,0,0,0, 0,0,i,0,0,0 0,0,0,0,0,0;
0,0,0,1,0,0, 0,0,0,0,0,0, 0,0,0,j,0,0 0,0,0,0,0,0;
0,0,0,0,1,0, 0,0,0,0,0,0, 0,0,0,0,k,0 0,0,0,0,0,0;
0,0,0,0,0,1, 0,0,0,0,0,0, 0,0,0,0,0,l 0,0,0,0,0,0;
r,0,0,0,0,0 1,0,0,0,0,0 0,0,0,0,0,0 0,0,0,0,0,0;
0,r,0,0,0,0 0,1,0,0,0,0 0,0,0,0,0,0 0,0,0,0,0,0;
0,0,r,0,0,0 0,0,1,0,0,0 0,0,0,0,0,0 0,0,0,0,0,0;
0,0,0,r,0,0 0,0,0,1,0,0 0,0,0,0,0,0 0,0,0,0,0,0;
0,0,0,0,r,0 0,0,0,0,1,0 0,0,0,0,0,0 0,0,0,0,0,0;
0,0,0,0,0,r 0,0,0,0,0,1 0,0,0,0,0,0 0,0,0,0,0,0;
0,0,0,0,0,0 a,0,0,0,0,0 0,0,0,0,0,0 1,0,0,0,0,0;
0,0,0,0,0,0 0,b,0,0,0,0 0,0,0,0,0,0 0,1,0,0,0,0;
0,0,0,0,0,0 0,0,c,0,0,0 0,0,0,0,0,0 0,0,1,0,0,0;
0,0,0,0,0,0 0,0,0,d,0,0 0,0,0,0,0,0 0,0,0,1,0,0;
0,0,0,0,0,0 0,0,0,0,e,0 0,0,0,0,0,0 0,0,0,0,1,0;
0,0,0,0,0,0 0,0,0,0,0,f 0,0,0,0,0,0 0,0,0,0,0,1;
0,0,0,0,0,0 0,0,0,0,0,0 0,0,0,0,0,0 1,0,0,0,0,-1;
0,0,0,0,0,0 0,0,0,0,0,0 0,0,0,0,0,0 0,1,0,0,0,-1;
0,0,0,0,0,0 0,0,0,0,0,0 0,0,0,0,0,0 0,0,1,0,0,-1;
0,0,0,0,0,0 0,0,0,0,0,0 0,0,0,0,0,0 0,0,0,1,0,-1;
0,0,0,0,0,0 0,0,0,0,0,0 0,0,0,0,0,0 0,0,0,0,1,-1;
0,0,0,0,0,0 0,0,0,0,0,0 1,1,1,1,1,1 0,0,0,0,0,0;];
% 1 2 3 4 5 6 7 8 9 101112131415161718192021222324
b = [0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;];
x= size(a)
z = size(b)
y = a/b
end

Answers (1)

KSSV
KSSV on 17 Oct 2017
Replace:
y = a/b
with
y = a\b

Categories

Find more on Operating on Diagonal Matrices 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!