how to make random vector with a certain profile

Well, im looking for a way to produce a random vector that behave like the profile in the picture.
It needs to start from let's say around 2, then climbs up to a max value not higher than 20, and then drops to zero.
That is the general idea, the distribution doesnt have to be exactly like in the graph.
does anyone have a good idea how to make that happened?

2 comentarios

Do you happen to have the data for that plot available? Rather than us having to read it off the graph and enter the values by hand.
samuel
samuel el 21 de Jul. de 2020
the data is random, it is just an example.
the profile is what matter. do you still need the data? i will send it

Iniciar sesión para comentar.

Respuestas (2)

Bruno Luong
Bruno Luong el 21 de Jul. de 2020
Editada: Bruno Luong el 21 de Jul. de 2020
r=linspace(0,1.5);
fv=(1.5-r).*(2+10*exp(-((r-1)./0.3).^2)); % whatever unnormaized pdf
% NOTE: This method assumes r is an equidistance vector
% otherwise you need to multiply fv by dr before cumulative sum
c = cumsum(fv);
c=(c-c(1))/(c(end)-c(1));
[cu,loc] = unique(c);
rs=r(loc);
x=interp1(cu, rs, rand(1,1e6)); % your random vector
% Check
subplot(2,1,1);
plot(r,fv);
subplot(2,1,2);
hist(x,100)

5 comentarios

What is c?
Bruno Luong
Bruno Luong el 21 de Jul. de 2020
just edit with c calculation
samuel
samuel el 21 de Jul. de 2020
that's good, but how can i get a different output every time im running the code?
the reason is that im using different fv everytime, to build a library of results using this random fv.
Bruno Luong
Bruno Luong el 21 de Jul. de 2020
If you want change for different pdf fv then change it, it in the line #1 & 2 of my code example.
samuel
samuel el 21 de Jul. de 2020
actualy r is given and constant. that i can not change.
for fv (#2 line), if i play with numbers, wont it mess up the profile?

Iniciar sesión para comentar.

Bruno Luong
Bruno Luong el 21 de Jul. de 2020
Editada: Bruno Luong el 21 de Jul. de 2020
Modified code in case r is not equidistance (but monotonic)
rmid = 0.5*(r(1:end-1) + r(2:end));
dr = r(2:end)-r(1:end-1);
fvfun = @(r)(1.5-r).^3.*(2+50*exp(-((r-1)./0.3).^2)); % whatever
fv = fvfun(rmid);
c = cumsum(fv.*dr);
c = [0, c]/c(end);
[cu, loc] = unique(c);
x = interp1(cu, r(loc), rand(1,1e6));

Categorías

Más información sobre Parallel Computing Toolbox en Centro de ayuda y File Exchange.

Productos

Versión

R2019b

Preguntada:

el 21 de Jul. de 2020

Comentada:

el 21 de Jul. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by