Random Number generation with Total sum.
Show older comments
clear all ; clc Demand=300; N=10; D=3;
a(1:N,1)=100; b(1:N,1)=600; %bounds on variable 1
a(1:N,2)=100; b(1:N,2)=400; %bounds on variable 2
a(1:N,3)=50; b(1:N,3)=200; %bounds on variable 3
x=a+(b-a).*rand(N,D);
I want to generate random numbers whose sum is equal to Demand=300 and their bounds are specified. When I generate by this code their sum is not equal to Demand, Please tell me what to do ?
Note-> I have studied randfixedsum function in Matlab help but it doesn't help me.
2 Comments
Sean de Wolski
on 23 Dec 2014
Please don't start new questions for the same thing as an existing one.
Instead, answer my question that I posed to you:
WHY DOESN'T RANDFIXEDSUM HELP YOU?
John D'Errico
on 28 Dec 2014
Edited: John D'Errico
on 28 Dec 2014
Sean - randfixedsum assumes the points lie in a hyper-cube, not a hyper-rectangle. The question here has lower and upper limits that differ for each variable. The randfixedsum code assumes scalar a and b.
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
