Need to find probability

7 次查看(过去 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!

采纳的回答

Image Analyst
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!

Translated by