Matrix dimensions must agree
16 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (2)
Gautam
am 23 Okt. 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
0 Kommentare
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!