How can I simulate and display data that satisfies several constrains?
Show older comments
Hi there, I confess I am quite new to MatLab so the following might sound very ammateur... I need to simulate uniformly data (two values: x and y) that obey a constrain/condition. I was able to use the function rand but I cannot get an easy solution to my problem.... Here it goes...Suppose I have the following 28 constrains:
1) x+2y=100 2) x+3y=100 3) 2x+y=100 4) 2x+3y=100 5) 3x+y=100 6) x+y=100 7) 3x+2y=100 8) x+2y=40 9) x+3y=40 10) 2x+y=40 11) 2x+3y=40 12) 3x+y=40 13) x+y=40 14) 3x+2y=40 15) x+2y=80 16) x+3y=80 17) 2x+y=80 18) 2x+3y=80 19) 3x+y=80 20) x+y=80 21) 3x+2y=80 22) x+2y=60 23) x+3y=60 24) 2x+y=60 25) 2x+3y=60 26) 3x+y=60 27) x+y=60 28) 3x+2y=60
The above constrains can be generalized in the form: A.x+B.y=M . Now I need to generate 100 simulated values (i.e. 100 pairs of x and y) for EACH of these constrains. Using rand and previous solution from Matt Tearle I was able to do the following in MatLab:
function [y,x]=simula(B,A,M,n)
y=M/B*rand(n,1);
x=M/A -(B/A)*y;
solution=[y,x];
save solution solution
end
The above only gives me 100 pairs (n=100) of x and y for ONE constrain, so I need to do it for all of them and I need the solution in a user friendly layout. This means I need it in a matrix/table with the following 3 columns (and 2800 rows): i) column 1: the simulation number, which will be the same for 28 rows ( i.e. the 28 ordered constrains); ii) column 2: values for x (ordered according to the respective constrains); iii) column 3: values for y (ordered according to the respective constrains).
Many many thanks in advance. Kind regards, Paulo
2 Comments
Walter Roberson
on 10 Jan 2013
Are the values generated required to solve all of the constraints simultaneously? Or you want 100 that satisfy #1, andother 100 that satisfy #2, and so on?
Paulo
on 11 Jan 2013
Accepted Answer
More Answers (0)
Categories
Find more on Resampling Techniques 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!