Matrix dimensions must agree

1 visualización (últimos 30 días)
Meaghan
Meaghan el 17 de Oct. de 2017
Respondida: Gautam el 23 de Oct. de 2024
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

Respuestas (2)

KSSV
KSSV el 17 de Oct. de 2017
Replace:
y = a/b
with
y = a\b

Gautam
Gautam el 23 de Oct. de 2024
Hello Meaghan,
The reason you get this error is because you cannot divide two matrices the way you divide two scalars.
To find the solution to a system of linear equations, use the “\” operation instead of “/”. Like, “y = a\b
Hope this helps

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by