
Need to find probability
조회 수: 15 (최근 30일)
이전 댓글 표시
Hello, my goal is to find the probability a piece of wood has a module of elasticity greater than 2.00e6. My code is below
%Equation and initialized variables
mean = 1930000;
standardDeviation= 64000;
fx = @(x) (1/(standardDeviation * sqrt(2 * pi))) * exp(-((x - mean).^2 / (2 * standardDeviation ^ 2)));
xmin = mean - 3*standardDeviation;
xmax = mean + 3*standardDeviation;
plot(xmin:xmax,fx(xmin:xmax),'o--b')
%Value of Normal PDF
y = pdf('Normal',xmin:xmax,mean,standardDeviation);
This code manages to yield a normal distribution plot. My goal is to try and find what percentage of these values in the plot are above the elasticty of 2.00e6. Thank you so much in advance!
댓글 수: 0
채택된 답변
Image Analyst
2022년 4월 27일
편집: Image Analyst
2022년 4월 27일
Try this:
% Equation and initialized variables
mean = 1930000;
standardDeviation= 64000;
fx = @(x) (1/(standardDeviation * sqrt(2 * pi))) * exp(-((x - mean).^2 / (2 * standardDeviation ^ 2)));
xmin = mean - 3*standardDeviation;
xmax = mean + 3*standardDeviation;
x = xmin:xmax;
subplot(2, 1, 1);
plot(x,fx(x),'b-', 'LineWidth', 3);
grid on;
xline(2e6, 'Color', 'r', 'LineWidth', 2);
%Value of Normal PDF
y = pdf('Normal',xmin:xmax,mean,standardDeviation);
cdf = cumsum(y);
% Normalize to 0-100%
cdf = 100 * cdf / cdf(end);
subplot(2, 1, 2);
plot(x, cdf, 'b-', 'LineWidth', 2);
xline(2e6, 'Color', 'r', 'LineWidth', 2);
yticks(0:10:100)
grid on;
% Find value where value is 2e6
index = find(x >= 2e6, 1, 'first')
prob = cdf(index)
yline(prob, 'Color', 'r', 'LineWidth', 2)
message = sprintf('The probability of 2e6 or less is %f %%.\n', prob)
title(message)
uiwait(helpdlg(message));

추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!