How to plot a pdf and cdf for my code
Réponses (1)
8 commentaires
The cdf for this can be computed using the pdf.
norm_cdf = cumsum(norm)./sum(norm); %make sure your variable "sum" is cleared before doing this operation... figure; plot(x,norm_cdf,'-k')
If you run the code that I typed above, you will get the same results as shown in your images (with the only difference being in the resolution along the x-axis). Except the image has the pdf and cdf reversed.
Yes, if you compute area under the pdf over a specified interval, then this is equal to the probability of the event occurring in that interval (i.e., P(f|t1<t<t2) = int_{t1}^{t2} pdf(t)dt). The total area under the pdf, however, will always equal 1.
The idea that this is the probability of failure does not make sense when you use a normal distribution because a normal distribution always has a greater than zero probability at negative values. This implies that a component or system could fail in negative time, which is nonsensical. Most of the time in reliability engineering/analysis, the Weibull distribution is used (also the log-normal is used occasionally).
The plot that you showed in Capture2.JPG looks exactly like the Figure 9.6 shown in Capture1.JPG, except that the resolution along the x-axis is higher.
You typed this code in your OP:
sum = 0; for i = 1:trials y1(i) = x1(i)*sigma1 + mu1; % transform the normally distributed randon numbers for input 1 y2(i) = x2(i)*sigma2 + mu2; % transform the normally distributed randon numbers for input 2 Y(i) = (3-((4*1000000)/(30000000*2*4))*(sqrt((y2(i)./16)^2+(y1(i)./4)^2))); % The output, where "failure" is defined as y2 is less than y1 if Y(i) < 0 sum = sum + 1; end end
In this code, you have a variable called "sum". I suggested that you use the following code to form your cdf:
norm_cdf = cumsum(norm)./sum(norm); %make sure your variable "sum" is cleared before doing this operation...
You must clear your variable "sum" before you use the Matlab command sum().
Honestly, without seeing any of the data that went into producing that plot, I can't say for sure what the difference is. The pdf should always integrate to 1, and when I integrate the pdf I produce, the value is 1.
sum(norm.*mean(diff(x))) ans = 0.9999
Perhaps they used a different method of normalization.
Catégories
En savoir plus sur Lognormal Distribution 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!