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!


