# Matrix dimensions must agree.(error en la linea 133) por favor

1 view (last 30 days)
Milton Chila on 5 Jun 2022
Edited: DGM on 5 Jun 2022
%programa que calcula reaccones en los soportes, desplazamiento y fuerzas
%internas en los elementos de una armadura
clear;
clc;
k=zeros(6);
l=1;
disp('----------Datos para el analisis');
----------Datos para el analisis
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Vector de cargas conocidas%
Unable to open file 'Datos Armadura.xlsx'.
%Vectores de desplazamientos conoccidos%
KT=zeros(GL);
%Numero de elementos%
%Numero de desplazamientos desconocidos%
%Numero de cargas conocidas%
dceros=zeros(l,GL-d);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp('Lectura de datos del elemento 1---------');
%Longitud%
%Modulo de elasticidas%
%Area de la seccion transversal
%Cosenos Directores(lambda x, lambda y, lambda z)%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp('calculo de la matriz de rigidez global del elemento---------');
for n=1:i
fprintf('Elemento %i.\n\n',n)
disp('------------------------')
k(1,1)=((Lx(n,1)^2)*(A(n,1)*E(n,1)))/L(n,1);
k(1,2)=((Lx(n,1)*Ly(n,1))*(A(n,1)*E(n,1)))/L(n,1);
k(1,3)=((Lx(n,1)*Lz(n,1))*(A(n,1)*E(n,1)))/L(n,1);
k(1,4)=-(((Lx(n,1))^2*(A(n,1)*E(n,1)))/L(n,1));
k(1,5)=-(((Lx(n,1))*Ly(n,1)*(A(n,1)*E(n,1)))/L(n,1));
k(1,6)=-((Lx(n,1)*Lz(n,1))*(A(n,1)*E(n,1)))/L(n,1);
k(2,1)=((Lx(n,1)*Ly(n,1))*(A(n,1)*E(n,1)))/L(n,1);
k(2,2)=((Ly(n,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(n,1))=k(4,6);
K(Fy(n,1),Nx(n,1))=k(5,1);
K(Fy(n,1),Ny(n,1))=k(5,2);
K(Fy(n,1),Nz(n,1))=k(5,3);
K(Fy(n,1),Fx(n,1))=k(5,4);
K(Fy(n,1),Fy(n,1))=k(5,5);
K(Fy(n,1),Fz(n,1))=k(5,6);
K(Fz(n,1),Nx(n,1))=k(6,1);
K(Fz(n,1),Ny(n,1))=k(6,2);
K(Fz(n,1),Nz(n,1))=k(6,3);
K(Fz(n,1),Fx(n,1))=k(6,4);
K(Fz(n,1),Fy(n,1))=k(6,5);
K(Fz(n,1),Fz(n,1))=k(6,6);
KT=K+KT; aqui es el error
end
disp('------------Matriz de rigidez de ls estructura------');
KT
disp('----------------------------');
disp('------------submatriz k11------');
K11=KT(1:d,1:d)
disp('------------submatriz k12------');
K12=KT(1:d,d+1:GL)
disp('------------submatriz k21------');
K21=KT(d+1:GL,1:d)
disp('------------submatriz k12------');
K22=KT(d+1:GL,d+1:GL)
disp('------------Solucion del Problema------');
disp('---------------------------------------');
disp('------------Vector de Cargas Conocidas------');
CC
disp('------------------------------------------');
disp('------------Solucion del Subsistema 1------');
disp('------------Desplazamientos desconocidos------');
DD=(inv(K11))*(CC-(K12*DC))
desplazamientos=[DD;DC];
disp('------------------------------------------');
disp('------------Solucion del Subsistema 2----');
disp('------------Cargas Desconocidas------');
CD=(K21*DD)+(K22*DC)
disp('------------------------------------------');
disp('------------Fuerzas Internas----');
disp('------------O Fuerzas en los elementos------');
for m=1:n
fprintf('Elemento %i.\n\n',m)
dp=[desplazamientos(Nx(m,1),1);desplazamientos(Ny(m,1),1);desplazamientos(Nz(m,1),1)]
Fbar=((A(m,1)*E(m,1))/L(m,1))*[-Lx(m,1) -Ly(m,1) -Lz(m,1) Lx(m,1) Ly(m,1) Lz(m,1)];
Fb(1,m)=Fbar(1);
disp('------------------------------------------');
end
disp('-----------------Fuerzas en los Elementos-------------------');
fba=[[1:1:n]',fb']
disp('------------------------------------------');
disp('------------La siguiente tabla muestra----------');
disp('------------Las cargas y los desplazamientos----');
disp('--------------En los nodos de la armadura-----------------');
fuerzas=[CC;CD];
TABLA=[[1:1:GL]',fuerzas,desplazamientos]
format long
disp('------------------------------------------');
disp('------------Final----');
Image Analyst on 5 Jun 2022

DGM on 5 Jun 2022
Edited: DGM on 5 Jun 2022
If the data in Nx, Ny, Nz, and Fx, Fy, Fz are not in the range of [1 GL], then K will end up getting expanded. At that point K and KT won't be the same size. I don't see anything in this code that safeguards against that. You'll have to decide what it means when those indices exceed GL and take the appropriate steps. That might mean clipping those points, or discarding them. That might mean expanding KT. I don't know anything about the data or the task at hand. I'm just looking at this in a decontextualized manner.