scenario generation using pdf
Show older comments
Hi,
I want to make some scenario using a probability distribution function and calculate the probability of each scenario(I need the probability for other executions) but I don't know how exactly. would you please give me some help or suggestions?
Answers (1)
Hi Reza,
I understand that you want to generate scenarios using a probability distribution function and calculate the probability of each scenario for further executions.
You can follow the below steps to acheive the same:
- Choose a Probability Distribution: Select a probability distribution function (PDF) for your scenario. For example, let's use a normal distribution.
mu = 0; % Mean of the normal distribution
sigma = 1; % Standard deviation of the normal distribution
pd = makedist('Normal', 'mu', mu, 'sigma', sigma);
- Generate Random Scenarios: Use the "random" function to generate random scenarios based on the chosen distribution.
numScenarios = 1000; % Number of scenarios
scenarios = random(pd, numScenarios, 1);
- Calculate Probability of Each Scenario: Use the probability density function to calculate the probability of each generated scenario.
probabilities = pdf(pd, scenarios);
- Normalize Probabilities: Normalize the probabilities so that their sum equals 1, which is useful for comparing probabilities across different executions.
probabilities = probabilities / sum(probabilities);
- Visualize Scenarios and Probabilities: Plot the scenarios and their corresponding probabilities to visualize the distribution.
Sample output for the above example:

References:
- Refer to the documentation of "makedist" for creating probability distribution objects: https://www.mathworks.com/help/stats/makedist.html
- Refer to the documentation of "random" for generating random numbers: https://www.mathworks.com/help/stats/prob.normaldistribution.random.html
- Refer to the documentation of "pdf" for evaluating the probability density function: https://www.mathworks.com/help/stats/prob.normaldistribution.pdf.html
Hope this helps!
Categories
Find more on Rayleigh Distribution in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!