Using the function solve, I manage to get conditions on parameter (u,v,w) for example. The issue is to draw randomly from the set of admissible parameters u,v,w to obtain (random) point solutions of x_{1},x_{2},x_{3}. Any idea?
Find random solutions of a system of inequalities
9 views (last 30 days)
Show older comments
Etienne Vaccaro-Grange
on 31 Mar 2021
Commented: Aditya Patil
on 6 Apr 2021
Hi everyone,
I am trying to find solutions of a system of inequalities, represented in matrix format by AX>0, where A is a known nxn matrix and X is an nx1 vector of unknown.
In a simple example where n=3, I would have:
a_{11}x_{1}+a_{12}x_{2}+a_{13}x_{3}>0
a_{21}x_{1}+a_{22}x_{2}+a_{23}x_{3}>0
a_{31}x_{1}+a_{32}x_{2}+a_{33}x_{3}>0
Now, I do not want to find all solutions as there are probably an infinity. I would like to randomly pick a solution that works from the set of all possible solutions, without having to find them all. I wondered whether this could be feasible.
I have read about how to convert this linear program in standard form and the use the simplex algorithm. But as far as I understand, this would only give me a particular solution (especially if I use Matlab function "linprog" for that). Using the function solve did not seem to be satisfying either (although I may be wrong). Instead I would like at best to be able to write:
x(1)=random(truncate(makedist('Normal','mu',0,'sigma',1),ub,db),1,1)
where I can find ub and db from the system of equations, potentially also randomly from the set of possible ub and db.
Is there any way to do that mathematically and on Matlab?
Many thanks in advance for your help!
Accepted Answer
Aditya Patil
on 5 Apr 2021
As the solutions are infinite, you can get solutions as a system of equations themselves. Then, you can either randomly put parameter values and verify the result, or you solve the system of equations by setting some of the parameters and solving for the other ones.
See the following code for example of randomly setting values.
syms x1 x2 x3;
A = [1 2 3; 4 5 6; 7 8 9];
eq1 = A(1, 1) * x1 + A(1, 2) * x2 + A(1, 3) * x3 > 0;
eq2 = A(1, 1) * x1 + A(1, 2) * x2 + A(1, 3) * x3 > 0;
eq3 = A(1, 1) * x1 + A(1, 2) * x2 + A(1, 3) * x3 > 0;
solutions = solve([eq1, eq2, eq3], [x1 x2 x3], 'ReturnConditions',true);
solutions.parameters
% select random parameters
inputs = randn(length(solutions.parameters), 1)';
% check if these inputs are valid
condWithValues = subs(solutions.conditions, solutions.parameters, inputs);
if isAlways(condWithValues)
subs(solutions.x1, solutions.parameters, inputs)
subs(solutions.x2, solutions.parameters, inputs)
subs(solutions.x3, solutions.parameters, inputs)
end
2 Comments
Aditya Patil
on 6 Apr 2021
Currently, there is no function to randomly sample points under constraints. However, you might find the following FileExchange submissions useful. https://www.mathworks.com/matlabcentral/fileexchange/31520-uniform-sampling-s-t-linear-constraints and https://www.mathworks.com/matlabcentral/fileexchange/36070-generate-random-points-in-multi-dimensional-space-subject-to-linear-constraints
More Answers (1)
Bruno Luong
on 5 Apr 2021
Edited: Bruno Luong
on 5 Apr 2021
For small dimensions, you might use existing tools in FEX to enumerate the vertexes of the polytopes.
If the domain is non bounded, you must bounded so it can give the vertexes that define the bounded domain.
clear
A = -magic(3);
% bounding box limits
lo = -1000;
up = 1000;
p = 1e5; % number of points
[m,n] = size(A);
AA = [-A; eye(n); -eye(n)];
b = [0;0;0];
BB = [b(:); up+zeros(n,1); -lo+zeros(n,1)];
% https://www.mathworks.com/matlabcentral/fileexchange/30892-analyze-n-dimensional-convex-polyhedra?s_tid=srchtitle
V=lcon2vert(AA,BB);
K = convhull(V);
% linear convex of the vertexes
W=-log(rand(p,size(V,1)));
W=W./sum(W,2);
X = W*V;
close all
plot3(X(:,1),X(:,2),X(:,3),'.');
hold on
for i=1:size(K,1)
xyz = V(K(i,:),:);
xyz = xyz([1 2 3; 2 3 1],:);
plot3(xyz(:,1),xyz(:,2),xyz(:,3),'-r');
end
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!