Generate random numbers with a constraint

I want to generate several numbers that meet a constraint. The constraint may be kind of complex, nonlinearity for example.
It occurs to me that there are also constraint input in the optimization toolbox. In some intelligent algorithm like ga, i guess the toolbox can generate input parameters according to the constraint. I want to know how it works and implement this function in my own script.

3 comentarios

KSSV
KSSV el 11 de Oct. de 2022
What are the constraints?
Xiaobo Dong
Xiaobo Dong el 11 de Oct. de 2022
It doesn't matter what the constraint is, I just want to know how to solve this kind of problem.
Indeed, there are some tricks for some certain simple constraints, which are not my expectations.
Rik
Rik el 11 de Oct. de 2022
It does matter what the contstraints are if you want an efficient implementation.

Iniciar sesión para comentar.

 Respuesta aceptada

Jiri Hajek
Jiri Hajek el 11 de Oct. de 2022

0 votos

A general answer to your general question is inverse transform sampling, which makes it possible to generate sample random data from any probability distribution.

6 comentarios

Xiaobo Dong
Xiaobo Dong el 11 de Oct. de 2022
Thanks, but what I want is not distribution, but specific constraints of equations and inequalities.
Jiri Hajek
Jiri Hajek el 11 de Oct. de 2022
This is, I believe, just a problem of reformulating your constraints into a specific probability distrbution definition. Can you give an example of what you need?
Xiaobo Dong
Xiaobo Dong el 11 de Oct. de 2022
I want to generate two vectors, v and t, which both have 5 elements with . should be integer and .
Jiri Hajek
Jiri Hajek el 11 de Oct. de 2022
OK, I see, this is fairly simple. Your condition translates into a problem with 9 segrees of freedom, so in fact you can choose 9 of the 10 numbers arbitrarily (or random, if you like) and solution of your equation will provide the value of the 10th number...
Xiaobo Dong
Xiaobo Dong el 11 de Oct. de 2022
OK, thanks. But I think this method is not general. What if there are other inequalities in the problem?
Jiri Hajek
Jiri Hajek el 11 de Oct. de 2022
Editada: Jiri Hajek el 11 de Oct. de 2022
Well, it seems that if you still have some concerns, than your problem statement was probably not complete... There's really no problem to e.g. generate random numbers that are integer and positive or e.g. random numbers constrained by a nonlinear inequality (like coodrinates from an area constrained by some curve). Here I agree with Rik that you can get an answer only to a properly defined question.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Random Number Generation en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 11 de Oct. de 2022

Editada:

el 11 de Oct. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by