필터 지우기
필터 지우기

How to divide a constant value (input) to several parts and find average of the output

조회 수: 2 (최근 30일)
Hello, I have a problem and need help.
Equation 1 and 2 works fine when z (e.g. 2000) is applied as a constant value. But since there is an exponential decay in p; I will like to divide z into several parts (e.g. 0, 100, 200 .... 2000), for each part calculate D, then find average D. Sum of z (z1, z2, ... zn) is equal to the constant value.
How can I divide z into equal parts, such that I can determine average D? I have tried different models but it doesn't work.
for i1=1:n
p=(phi0)*(exp(-c*z)); ------- 1
D=((p)*(rW))+((1-p)*(rSG)); ------- 2
end

답변 (1개)

Walter Roberson
Walter Roberson 2019년 5월 27일
Zn = floor(z/n) * ones(1,n);
left_over = z - sum(Zn);
enlarge_at = randperm(n, left_over);
Zn(enlarge_at) = Zn(enlarge_at) + 1;
Now sum(Zn) = z and Zn is the sizes of each partition. You might want to use
offsets = cumsum([0, Zn]);
Then D(offsets(k):offsets(k)-1) is the k'th section.
The partitions will not generally be exactly the same sizes through-out, because z will not generally be exactly divisible by n . This code randomly distributes an additional length of 1 to make sure that the total comes out correctly.
It would also be possible to distribute the extras semi-regularly. You could consider linspace(1,z,n+1) and then round() or floor() or ceil() to create the offsets.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by