이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
solution for algorithm to link status?
조회 수: 2 (최근 30일)
이전 댓글 표시
ankanna
2021년 3월 17일
nodes = 3; m = 0.7
for i = 1:nodes
for j = i+1:nodes
test = unifrnd(0,1)
if ni = 1
nj = 1:nodes
if (test<=m/ni=1/nj=1)
li,j = 1
else
li,j = 0
end
lj,i = li,j
end
L = li,j;lj,i
end
please to generate this
채택된 답변
Walter Roberson
2021년 3월 17일
편집: Walter Roberson
2021년 3월 17일
nodes = 3; m = 0.7;
for i = 1:nodes
for j = i+1:nodes
test = unifrnd(0,1);
if ni == 1
nj = 1:nodes;
if (test<=m/ni==1./nj==1)
l(i,j) = 1;
else
l(i,j) = 0;
end
l(j,i) = l(i,j);
end
L = [l(i,j);l(j,i)];
end
end
However, we can prove that the if (test<=m/ni==1./nj==1) will be false except when nodes = 1 (in which case the code is just rather strange but could be true sometimes.)
댓글 수: 31
Walter Roberson
2021년 3월 17일
Yes, that is to be expected. Your code uses ni twice but does not define it at all. You need to define it as something appropriate to the situation.
I would, however, point out that if ni is not either 1 or a vector of all 1's, then the if ni = 1 would fail, and your code would not construct l(i,j) or l(j,i) . That would suggest that for all the interesting cases, ni = 1 would have to be in effect.
ankanna
2021년 3월 17일
for i = 1,2,...,n
for j = i+1,...,n
test - select random number from uniform distribution between (0,1)
if (test<=;λ∩ni = 1∩nj = 1) then Li,j = 1
else; Li,j = 0
Lj,i = Li,j
L - load Li,j and Lj,i into the matrix L
this is the question actual
Walter Roberson
2021년 3월 17일
Sorry, I looked at the document but it uses notation that I do not understand. I think that the authors would need to be asked for the meaning of part of it. In particular, I do not understand the semi-colon between the less-than-or-equal-to and the lambda.
Walter Roberson
2021년 3월 17일
편집: Walter Roberson
2021년 4월 7일
nodes = 3; lambda = 0.7;
r = rand(1, nodes) * 0.3 + 0.7; %reliability
%4.2.1.1
%no loop needed in MATLAB
n = rand(1,nodes) <= r;
%4.2.1.2
%no loop needed in MATLAB
test = squareform(rand(1,nodes*(nodes-1)/2));
test(1:nodes+1:end) = 0; %node to itself is fully reliable
L = double(test <= lambda & n & n.');
L(1:nodes+1:end) = nan; %but algorithm leaves node to itself undefined
L
L = 3×3
NaN 1 1
1 NaN 0
1 0 NaN
ankanna
2021년 3월 21일
probability of existence of a topology is given by
P(alfak=1) = lamda^nl*(1-lamda)^nu
Where
lamda = probability of link existence = 0.7
nl = linked nodes and
nu = unlinked nodes
now we take 0 0 0
p(alfak=1) =(0.7)^0*(1-0.7)^3
=0.027
0 0 1
p(alfak=1)=(0.7)^1*(1-0.7)^2
= 0.063
0 1 0 and 1 0 0 also sme because only one linked
p(alfak=1)=(0.7)^1*(1-0.7)^2
= 0.063
0 11, 1 0 1, 1 1 0
p(alfak=1)=(0.7)^2*(1-0.7)^1
= 0.147
1 1 1
p(alfak=1)=(0.7)^3*(1-0.7)^0
= 0.343
output will
L12 L13 L23 p(alfak=1)
___ ___ ___ _______
0 0 0 0.027
0 0 1 0.063
0 1 0 0.063
0 1 1 0.147
1 0 0 0.063
1 0 1 0.147
1 1 0 0.147
1 1 1 0.343
i need to generate above matrix
please help me to generate the code
Walter Roberson
2021년 3월 21일
format long g
nodes = 10;
lamda = 0.7;
bits = dec2bin(0:2^nodes-1)-'0';
nl = sum(bits,2);
nu = nodes-nl;
P = lamda.^nl .* (1-lamda).^nu;
P(1:20)
ans = 20×1
5.90490000000001e-06
1.37781e-05
1.37781e-05
3.21489e-05
1.37781e-05
3.21489e-05
3.21489e-05
7.50141000000001e-05
1.37781e-05
3.21489e-05
[minP, minidx] = min(P)
minP =
5.90490000000001e-06
minidx =
1
bits(minidx,:)
ans = 1×10
0 0 0 0 0 0 0 0 0 0
[maxP, maxidx] = max(P)
maxP =
0.0282475249
maxidx =
1024
bits(maxidx,:)
ans = 1×10
1 1 1 1 1 1 1 1 1 1
histogram(P)
ankanna
2021년 3월 21일
how to take 3 by matrix in the order NN will
NN = 1 2 3
1
2
3
for example,
0 0 1
in the matrix
[ 0 1 1
1 0 0
1 0 0 ]
how to generate these type of matrix
Walter Roberson
2021년 3월 21일
I do not understand the question. You want each matrix to have 3 rows and NN columns ? What should be in the columns?
ankanna
2021년 3월 22일
columns will be in logic 123
and row logic should also 123
we take
001
1 2 3
1 0 1 1
2 1 0 0
3 1 0 0
here 1 2 3 are three nodes n =3
number of links will be 8 (000 to 111)
how to generate above logic matrix ?
Walter Roberson
2021년 3월 22일
I have no idea what you are asking, if you are not asking something that I solved for you days ago.
ankanna
2021년 4월 7일
for i = 1,2,...,n
for j = i+1,...,n
test - select random number from uniform distribution between (0,1)
if (test<=;λ∩ni = 1∩nj = 1) then Li,j = 1
else; Li,j = 0
Lj,i = Li,j
L - load Li,j and Lj,i into the matrix L
this is the actual procedure to generate link status
Walter Roberson
2021년 4월 7일
that code have an error. the error is undefined variable l
Please post the URL of the code that I posted that had the undefined variable l ?
Walter Roberson
2021년 4월 7일
this is the actual procedure to generate link status
Sorry, I looked at the document but it uses notation that I do not understand. I think that the authors would need to be asked for the meaning of part of it. In particular, I do not understand the semi-colon between the less-than-or-equal-to and the lambda.
If the semi-colon were not there, then the test
if (test<=;λ∩ni = 1∩nj = 1) then Li,j = 1
else; Li,j = 0
would translate as
L(i,j) = test <= lambda && ni == 1 && nj == 1;
However it is not clear in the document whether ni and nj are intended to be distinct variables or are intended to be a vector n indexed at locations i and j -- but that would be a problem because n occurs as a limit in the for statement, implying that it is a scalar.
When I looked at the paper, it seemed most likely that the equation was wrong, that the operator in the test should be ∪ instead of ∩
Walter Roberson
2021년 4월 8일
You seem to be referring to the earlier posting,
nodes = 3; m = 0.7;
for i = 1:nodes
for j = i+1:nodes
test = unifrnd(0,1);
if ni == 1
nj = 1:nodes;
if (test<=m/ni==1./nj==1)
l(i,j) = 1;
else
l(i,j) = 0;
end
l(j,i) = l(i,j);
end
L = [l(i,j);l(j,i)];
end
end
Unrecognized function or variable 'ni'.
No undefined variable l because it never gets that far due to ni and nj being undefined.
Walter Roberson
2021년 4월 8일
So what happens if we define them?
ni = randi([0 1])
ni = 0
nj = randi([0 1])
nj = 0
nodes = 3; m = 0.7;
for i = 1:nodes
for j = i+1:nodes
test = unifrnd(0,1);
if ni == 1
nj = 1:nodes;
if (test<=m/ni==1./nj==1)
l(i,j) = 1;
else
l(i,j) = 0;
end
l(j,i) = l(i,j);
end
L = [l(i,j);l(j,i)]
end
end
Unrecognized function or variable 'l'.
Okay, that starts to make sense. You only assign to l if ni == 1 . So, we will have to initialize l
Walter Roberson
2021년 4월 8일
ni = randi([0 1])
ni = 0
nj = randi([0 1])
nj = 0
nodes = 3; m = 0.7;
l = zeros(nodes, nodes);
for i = 1:nodes
for j = i+1:nodes
test = unifrnd(0,1);
if ni == 1
nj = 1:nodes;
if (test<=m/ni==1./nj==1)
l(i,j) = 1;
else
l(i,j) = 0;
end
l(j,i) = l(i,j);
end
L = [l(i,j);l(j,i)]
end
end
L = 2×1
0
0
L = 2×1
0
0
L = 2×1
0
0
l
l = 3×3
0 0 0
0 0 0
0 0 0
ankanna
2021년 4월 8일
nodes=3; ri=0.9, lamda=0.7;
l = zeros(nodes, nodes);
for i=1: nodes
test=unifrnd (0,1)
if test<=ri
ni=1
else
ni=0
end
ns(i)=[ni]
end
for i=1:nodes
for j=i+3:nodes
test=unifrnd (0,1)
if test<=(lamda/ns(i)==1/ns(j)==1)
l(i,j)=1
else
l(i,j)=0
end
l(j,i) = l(i,j)
end
L = [l(i,j);l(j,i)]
end
this will be generated but the output is
L[ ]
Walter Roberson
2021년 4월 8일
You cannot get that output with that algorithm. The paper published the wrong algorithm.
ankanna
2021년 4월 8일
please to generate link status i.e., the output will be contain this matrix. how to generate this code
0 1 1
1 0 1
1 1 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)