Borrar filtros
Borrar filtros

How to get rid of the error: Error using horzcat. Dimensions of matrices being concatenated are not consistent.

1 visualización (últimos 30 días)
Hi
When i solve a second order differential equation with constant coefficients, i obtained a solution. But when i change these coefficients by the matrix form i have obtained this error:
Error using horzcat. Dimensions of matrices being concatenated are not consistent.
And my new code is a function :
function xdot = equadif(t,x)
% Function file for mass with spring and damping.
% Position is first variable, velocity is second variable.
F=[12;23:0];
M=[1,0,0;1,3,0;0,0,2];
cp = 1.38*10^-9;
K = [5,-6,1;-6,2,20;4,2,5];
TETA = [1,1,0;2,0,0;1,0,0];
C =[2,10,0;5,4,0;1,5,0];
R = 10*10^3;
A = [zeros(3,3), eye(3,3), zeros(3,1); -K*M^-1, -C*M^-1, TETA*M^-1; zeros(3,3), TETA/cp, -1/(R*cp)];
B = [0; M^-1 ; 0];
xdot = A*x+B*F;
end
[t,x]=ode45(@equadif,[0,0.01,0.03],[0,1,0]);
plot(t,x(:,1),'b',t,x(:,2),'r',t,x(:,3),'--')

Respuesta aceptada

Roger Stafford
Roger Stafford el 7 de Abr. de 2016
Editada: Roger Stafford el 7 de Abr. de 2016
Both the expressions for A and B are invalid. In A the three quantities
zeros(3,3), eye(3,3), zeros(3,1)
have a total of 7 columns, whereas
-K*M^-1, -C*M^-1, TETA*M^-1
have a total of 9 columns. These are incompatible. Also
zeros(3,3), TETA/cp, -1/(R*cp)
have only 7 columns. Moreover zeros(3,3) and TETA/cp have 3 rows whereas -1/(R*cp) has only one row.
In B, the three quantities have 1 column, 3 columns, and 1 column, respectively. These don't match.
Try laying out these various quantities with little dots and you will see that they don't combine in a rectangular pattern.
  1 comentario
Mallouli Marwa
Mallouli Marwa el 7 de Abr. de 2016
I have changed the matrix A in the right form: TETA = [1;2;1]; A = [zeros(3,3), eye(3,3), zeros(3,1); -M^-1*K, -M^-1*C, -M^-1*TETA; (-1/R)*TETA', zeros(1,3), -1/(R*cp)]; But ther is still an error in B: B = [zeros(3,1); M^-1 ; zeros(1,3)]; How can i change it ??

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB Mobile Fundamentals en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by