Building the Matrix from the two matrices

조회 수: 2 (최근 30일)
surendra kumar Aralapura mariyappa
Hey, I am stuck in building the Matrix for my project "Thermal Network''. The problem is how to buid the Matrix from the two matrices of same dimensions.
Details goes here;
LA = [ 0 77 0 0; 77 0 15 0; 0 15 0 0; 0 0 0 0];
LB = [ 0 0 0 25; 0 0 0 28; 0 0 0 25; 25 28 25 0];
Now I need to build the matrix L like;
L= [LA(2,1)+LB(1,4) (-LA(1,2)) 0 (-(LB(1,4));
(-LA(2,1)) LA(2,1)+LA(2,3)+LB(2,4) (-LA(2,3)) (-LB(2,4));
0 (-LA(3,2)) LA(3,2)+LB(3,4) (-LB(3,4));
(-LB(4,1)) (-LB(4,2)) (-LB(4,3)) 0];
or else like this also fine:
L= [LA(1,2)+LB(4,1) (-LA(2,1)) 0 (-(LB(4,1));
(-LA(1,2)) LA(1,2)+LA(3,2)+LB(4,2) (-LA(3,2)) (-LB(4,2));
0 (-LA(2,3)) LA(2,3)+LB(4,3) (-LB(4,3));
(-LB(1,4)) (-LB(2,4)) (-LB(3,4)) 0];
May be it would be possible using for-loop. It is just sample model, If i change the martices dimensions, Matrix should be built automatically, that's why for-loop would be better option!
If you have any suggestions and your answers are most weclomed and appreciated as well
  댓글 수: 4
Jan
Jan 2019년 6월 5일
@surendra: You provide two definitions, in one the first element is LA(2,1)+LB(1,4), in the other it is LA(1,2)+LB(4,1). I cannot guess which one is wanted or what you want, if the dimensions of LA and LB are changed. Without giving a general definition how the output L is created, we cannot suggest the corresponding code.
surendra kumar Aralapura mariyappa
편집: surendra kumar Aralapura mariyappa 2019년 6월 5일
@Jan, I understood your concern, Here I am giving more information for the clarity
the dimensions of LA and LB are 4*4, and the matrices are like this:
LA = [ 0 77 0 0;
77 0 15 0;
0 15 0 0;
0 0 0 0];
LB = [ 0 0 0 25;
0 0 0 28;
0 0 0 25;
25 28 25 0];
Now I am changing the matrices size; 5*5
kindly see the similarity between the values in the matrices;
LA = [ 0 77 0 0 0;
77 0 15 0 0;
0 15 0 18 0;
0 0 18 0 0;
0 0 0 0 0];
LB = [ 0 0 0 0 25;
0 0 0 0 28;
0 0 0 0 25;
0 0 0 0 20;
25 28 25 20 0 ];
L = L= [LA(1,2)+LB(1,5) (-LA(1,2)) 0 0 (-(LB(1,5));
(-LA(2,1)) LA(2,1)+LA(2,3)+LB(2,5) (-LA(2,3)) 0 ( -LB(2,5));
0 (-LA(3,2)) LA(3,2)+LA(3,4)+LB(3,5) (-LA(3,4)) (-LB(3,5));
0 0 -(LA(4,3)) LA(4,3)+LB(4,5) (-LB(4,5));
(-LB(5,1)) (-LB(5,2)) (-LB(5,3)) (-LB(5,4)) 0];
Hope this explanation will be fine;
Same for 50*50 dimensions also

댓글을 달려면 로그인하십시오.

채택된 답변

Raghunandan V
Raghunandan V 2019년 6월 6일
Hi,
Please check the answer
LA = [ 0 77 0 0;
77 0 15 0;
0 15 0 0;
0 0 0 0];
LB = [ 0 0 0 25;
0 0 0 28;
0 0 0 25;
25 28 25 0];
[m,n ] = size(LB);
L = -LB;
L(1: m-1, 1:n-1) = -LA(1: m-1, 1:n-1);
for k = 1: m
L(k,k) = -(sum(L(k,:)));
end
L(m,m) = 0;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Vector Volume Data에 대해 자세히 알아보기

제품


릴리스

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by