Creat a big matrix by adding elements from smaller matrices

4 次查看(过去 30 天)
I have created eight 14x14 submatices (a,b,c,.....) using for loop. I want to create a bigger matrix (K) as such that the first submatrix "a" is the first 14x14 of M, the second matrix "b" starts at (8,8) and the overlaped elements (8:14,8:14) are the sum of the two elements, "c" starts at (15,15) the overlaped elements (15:21,15:21), ...etc.
Thanks
  1 个评论
Emd Amin
Emd Amin 2020-7-1
编辑:Emd Amin 2020-7-1
syms Px Mz1 Mz2 Mz3 Mz4 Mz5 Qz1 Qz2 Qz3 Qz4 Qz5 My1 My2 My3 My4 My5 Qy1...
Qy2 Qy3 Qy4 Qy5 Mx1 Mx2 Mx3 Mx4 Mx5 mx1 mx2 B1 B2 B3 B4 B5...
Kb1 Kt1 Kb2 Kt2 Kb3 Kt3 Kb4 Kt4
Mz=[Mz1 Mz2 Mz3 Mz4 Mz5]; Qz=[Qz1 Qz2 Qz3 Qz4 Qz5];Px=[Px];
My=[My1 My2 My3 My4 My5]; Qy=[Qy1 Qy2 Qy3 Qy4 Qy5];
Mx=[Mx1 Mx2 Mx3 Mx4 Mx4];
B=[B1 B2 B3 B4 B5];
ez=0; ey=0; z=0; y=0; z0=0; y0=0;
beta_y= 1/Iy*(z^3*area
beta_z= 1/Iz*(y^3*area
beta_w= 1/Cw*omega_n*(y^2+z^2)*area; %(3.21)
C0= rp_sequare
Cy=ey; Cz=ez-z0; %(3.27)
d=sym(zeros(7,7));e=sym(zeros(7,7));f=sym(zeros(7,7));K=sym(zeros(35,35));
m=0;
for i=1:4
%i is the number of nodes
j=i+1 ;
if i<=2
mx=Mx(1,2);
else
mx=Mx(1,4);
end
%2.1- d Matrix
d(6,2)=-0.1*Px;
d(6,4)=-1.1*Px*Cz-0.55*(My(1,i)-My(1,j))-0.1*Qz(1,i)*l-0.45*Qz(1,j)*l;
d(6,6)=d(5,5);
d(7,2)=-0.1*Px*Cz-0.05*(My(1,i)-My(1,j))-0.05*Qz(1,j)*l;
d(7,3)=0.1*Px*Cy+0.05*(Mz(1,i)-Mz(1,j))+0.05*Qy(1,j)*l;
d(7,4)=-0.1*Px*C0-(0.05*(My(1,i)-My(1,j))+0.05*Qz(1,i)*l)*beta_y...
-(0.05*(Mz(1,i)-Mz(1,j))+0.05*Qy(1,i)*l)*beta_z...
d;
%2.2- e matrix:
e(5,4)=0.1*Px*Cy+0.05*(Mz(1,i)-Mz(1,j))-0.05*Qy(1,i)*l+0.1*Qy(1,j)*l;
e(5,7)=Px*Cy*l/30+(Mz(1,i)-Mz(1,j))*l/60+Qy(1,i)*l^2/60;
e(6,2)=d(6,2);
e(6,4)=-0.1*Px*Cz-0.05*(My(1,i)-My(1,j))+0.05*Qz(1,i)*l-0.1*Qz(1,j)*l;
e(7,6)=-Px*Cz*l/30-(My(1,i)-My(1,j))*l/60-Qz(1,j)*l^2/60;
e;
%2.33 - f matrix
f(1,1)=0;f(2,2)=d(2,2);f(3,3)=d(3,3);f(4,4)=d(4,4);f(5,5)=d(5,5);
f(6,6)=d(6,6);
f(7,7)=2*Px*C0*l/15+((My(1,i)-My(1,j))*l/15+Qz(1,i)*l^2/20+Qz(1,j)*l^2/60)...
*beta_y+((Mz(1,i)-Mz(1,j))*l/15+Qz(1,i)*l^2/20+Qz(1,j)*l^2/60)*beta_z...
+(Kb1*(B(1,i)-B(1,j))*l+Kt1*mx*l^2)*beta_w;
f(4,2)=-e(4,2);f(2,4)=f(4,2);f(4,3)=-e(4,3);f(3,4)=f(4,3);f(5,3)=-d(5,3);
f(3,5)=f(5,3);
f;
KG=[d e;e f];
Kt=KE+KG
K=
I downsized it to 4 submatrices thinking that it will be easier, K matrix should be constructed from Kt, the first Kt(i=1) is the first 14x14 element of the K then Kt(i=2) starts at K(8,8) the overlaped elements should be Kt(i=1)+Kt(i=2) and so on....

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2020-7-1
part1 = blkdiag(a,c,e,g, zeros(7,7));
part2 = blkdiag(zeros(7,7),b,d,f,h);
K = part1 + part2;
  3 个评论
Walter Roberson
Walter Roberson 2020-7-1
If you need to build incrementally:
existing_matrix = [];
for counter = 1 : 4
... calculate Kg
existing_matrix(end+7,end+7) = 0; %extend the matrix
existing_matrix(end-13:end,end-13:end) = existing_matrix(end-13:end,end-13:end) + Kg;
end
Emd Amin
Emd Amin 2020-7-2
编辑:Emd Amin 2020-7-2
Thanks Walter, I really appreciate your help. the above code nailed it.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by