How to make Network/nodal analysis and value distribution in MATLAB?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (1)
Chunru
am 30 Jun. 2022
"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]'
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
2 Kommentare
Chunru
am 30 Jun. 2022
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;]'
sum(v)
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
Siehe auch
Kategorien
Mehr zu Cardiology finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

