generate a random number base on pdf function
显示 更早的评论
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 个评论
John D'Errico
2022-6-25
编辑:John D'Errico
2022-6-25
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
2022-6-25
John D'Errico
2022-6-25
编辑:John D'Errico
2022-6-25
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.
采纳的回答
更多回答(3 个)
Karan Kannoujiya
2022-6-25
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 个评论
John D'Errico
2022-6-25
编辑:John D'Errico
2022-6-25
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
2022-6-25
Ohh sorry, thanks for clearing
Image Analyst
2022-6-25
0 个投票
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
2022-7-3
0 个投票
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
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


