How to make Network/nodal analysis and value distribution in MATLAB?

조회 수: 7 (최근 30일)
Shemin Sagaria
Shemin Sagaria 2022년 6월 30일
댓글: Chunru 2022년 6월 30일
Hi,
I have 8 nodes, where each node is connected to 3 other nodes. Each node have a numerical value (positive or negative). The aim is to make negative nodes 0 by take positive values from connected nodes. (each nodes will be indicated by a variable, eg: a, b, c..... and values will be generated from a simulink model)
I found the solution as:
  • Positive and negatives nodes have to be seperated into array
  • Take the sum of all positive nodes coming to the negative node and sort it based on the differerence of negative node value to the sum
  • The negative node on the top take positive value from the connected node with highest positive number.
  • Update the nodal values
  • Now above step is repeated again.
I am not sure how to do this, and I need help with this. for checking, these are some reference values. I hope some experienced community members can help me.
Node connections are:
Node 1 - 2,3,8; Node 2 - 1,4,8 ; Node 3 - 1,5,8 ; Node 4 - 2,6,7 ; Node 5 - 3,7,6 ; Node 6 - 4,5,7 ; Nide 7 - 4,5,6 ; Node 8 - 1,2,3
Node values:
Node 1 = -8.95 ; Node 2 = 4.62 ; Node 3 = 14.07 ; Node 4 = -2.69 ; Node 5 = -9.14 ; Node 6 = -0.83 ; Node 7 = 2.2 ; Node 8 = 11.72

답변 (1개)

Chunru
Chunru 2022년 6월 30일
"graph" can be used for such problem.
Node connections are:
Node 1 - 2,3,8; Node 2 - 1,4,8 ; Node 3 - 1,5,8 ; Node 4 - 2,6,7 ; Node 5 - 3,7,6 ; Node 6 - 4,5,7 ; Nide 7 - 4,5,6 ; Node 8 - 1,2,3
s = [1 1 1 2 2 3 3 4 4 5 5 6 ]'; % undirected graph
t = [2 3 8 4 8 5 8 6 7 7 6 7 ]';
g = graph(s, t);
plot(g)
Node values:
Node 1 = -8.95 ; Node 2 = 4.62 ; Node 3 = 14.07 ; Node 4 = -2.69 ; Node 5 = -9.14 ; Node 6 = -0.83 ; Node 7 = 2.2 ; Node 8 = 11.72
v = [-8.95; 4.62; 14.07; -2.69; -9.14; -0.83; 2.2; 11.72]'
v = 1×8
-8.9500 4.6200 14.0700 -2.6900 -9.1400 -0.8300 2.2000 11.7200
Change values:
The following is a simple approach. Not sure if it always give a solution.
while any(v<0)
% find the minimum of v
[vmin, imin] = min(v);
% find the neighbors of imin
n = neighbors(g, imin);
% borrow values from the neighbor nodes with highest value
[vmax, imax] = max(v(n));
borrowvalue = min(-vmin, vmax);
v(imin) = v(imin) + borrowvalue;
v(n(imax)) = v(n(imax)) - borrowvalue;
fprintf("imin=%d imax=%d ", imin, n(imax))
fprintf("%8.2f ", v)
fprintf('\n')
end
imin=5 imax=3
-8.95 4.62 4.93 -2.69 0.00 -0.83 2.20 11.72
imin=1 imax=8
0.00 4.62 4.93 -2.69 0.00 -0.83 2.20 2.77
imin=4 imax=2
0.00 1.93 4.93 0.00 0.00 -0.83 2.20 2.77
imin=6 imax=7
0.00 1.93 4.93 0.00 0.00 0.00 1.37 2.77
  댓글 수: 2
Shemin Sagaria
Shemin Sagaria 2022년 6월 30일
Hi,
Thank you so much for your answer. Its helps a lot. However, this approach is not working for other values. I checked this with 4 nodes
s = [1 1 2 2 3 3 4 4]';
t = [2 3 1 4 1 4 2 3]';
a = -21.28;
b = 11.15;
c = -8.42;
d = 24.55;
v = [a;b;c;d]'
Chunru
Chunru 2022년 6월 30일
s = [1 1 2 3]'; % undirected graph
t = [2 3 4 4]';
g = graph(s, t);
plot(g)
v = [ -21.28; 11.15; -8.42; 24.55;]'
v = 1×4
-21.2800 11.1500 -8.4200 24.5500
sum(v)
ans = 6
k=1;
while any(v<0)
%k
% find the minimum of v
[vmin, imin] = min(v);
% find the neighbors of imin
n = neighbors(g, imin);
% To avoid dead lock
if all(v(n)<=0)
% randomly pick a neigbour
idx_n = n(randi([1 length(n)], 1));
% neighbour of neighbour
n_n = neighbors(g, idx_n);
[vmax, ii ] = max(v(n_n));
ib = n_n(ii);
v(idx_n) = v(idx_n) + v(ib);
v(ib) = 0;
end
% borrow values from the neighbor nodes with highest value
[vmax, imax] = max(v(n));
borrowvalue = min(-vmin, vmax);
v(imin) = v(imin) + borrowvalue;
v(n(imax)) = v(n(imax)) - borrowvalue;
fprintf("imin=%d imax=%d ", imin, n(imax))
fprintf("%8.2f ", v)
fprintf('\n')
k=k+1;
if k>100, break; end
end
imin=1 imax=2
-10.13 0.00 -8.42 24.55
imin=1 imax=2
0.00 14.42 -8.42 0.00
imin=3 imax=1
6.00 0.00 0.00 0.00

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

카테고리

Help CenterFile Exchange에서 Cardiology에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by