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