generate a random number base on pdf function
Afficher commentaires plus anciens
I basically have the following PDF respectivley:
f(x)=1/2*x+0.5
range is -1 to 1
I would like to generate random numbers on matlab based on these equations.
thanks for your help.
3 commentaires
John D'Errico
le 25 Juin 2022
Modifié(e) : John D'Errico
le 25 Juin 2022
Stop posting the same homework question miltiple times.
Note that having answered your question, IF you make an effort, (perhaps show what you tried as a comment on my answer) I might be willing to help you more if I see it as a serious effort.
hong chenyao
le 25 Juin 2022
John D'Errico
le 25 Juin 2022
Modifié(e) : John D'Errico
le 25 Juin 2022
It does not matter if it is MATLAB homework, or homework for some other class. IT IS HOMEWORK. It is YOUR HOMEWORK. It was assigned to you. We are not a homework solving service. You have made no attempt to do your homework.
How about this as an option. Ask your teacher to contact me directly. Have them give me their direct agreement that it is OK if I do your homework assignments for you. I'll send the completed homework directly to your teacher. Of course, then I'll be the one who gets credit. Can I get yet another degree? Maybe. Do I want one? Nope.
Réponse acceptée
Plus de réponses (3)
Karan Kannoujiya
le 25 Juin 2022
Hi hong,
so your range is between -1 to 1 in that case your domain will be between -3 to 1
if you want to generate N random number between two number 'a' and 'b' then you can use the below syntax
In your case a=-3 and b=1
r = a + (b-a) .* rand(N,1)
2 commentaires
John D'Errico
le 25 Juin 2022
Modifié(e) : John D'Errico
le 25 Juin 2022
NO NO NO. You told the @hong chenyao how to generate a UNIFORM random number on a different interval. That was not remotely the question asked.
Karan Kannoujiya
le 25 Juin 2022
Ohh sorry, thanks for clearing
Image Analyst
le 25 Juin 2022
0 votes
You need to do "inverse transform sampling" so you need the CDF, as the esteemed @John D'Errico said.
I'm attaching an example I worked up for drawing samples from a Rayleigh distribution. Adapt as needed.

Shivam Lahoti
le 3 Juil 2022
0 votes
Tons of distributions are given here: http://www.mathworks.com/matlabcentral/fileexchange/7309-randraw
In general, you basically compute the CDF of your PDF function and invert it. Go here for a generally applicable explanation of how to do it: http://en.wikipedia.org/wiki/Inverse_transform_sampling
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


