Hello guys, i need help for estimating FAR from this formula can review my code please

1 view (last 30 days)
mu = 3;
sd = 1;
x= linspace(0,10)
y1 = 1/(2*pi*sd)*exp(-(x-mu).^2/(2*sd^2))
plot(x1,y1);
hold on
mu = 5;
sd = 1;
x2 = linspace(0,10);
y2 = 1/(2*pi*sd)*exp(-(x2-mu).^2/(2*sd^2));
plot(x2,y2);
hold on
plot([1 1]*4, ylim, '--r') % Draw A Red Vertical Line At ‘x=5’
hold off
ylabel('q(x)and p(x)')
xlabel('x')
hold on
x1=linspace(4,10)
trapz(x1,y1)

Answers (1)

Yazan
Yazan on 16 Dec 2021
Have you noticed that the distributions defined in your codes are not Gaussian? See the demo below
mu = 3;
sigma = 1;
x = mu-6*sigma:0.05:mu+6*sigma;
dist = 1/sqrt(2*pi*sigma)*exp(-(x-mu).^2/(2*sigma^2));
figure, subplot(1,2,1), plot(x, dist);
x0 = 4;
hold on, xline(x0, 'LineStyle', '--', 'Color', 'r'); hold off
% If you have 'Statistics and Machine Learning Toolbox'
if license('test', 'Statistics_Toolbox')
y1 = 1 - cdf('Normal', 4, mu, sigma);
end
% Otherwise:
x2 = 4:0.05:mu+6*sigma;
dist2 = 1/sqrt(2*pi*sigma)*exp(-(x2-mu).^2/(2*sigma^2));
subplot(1,2,2), plot(x2, dist2);
y2 = trapz(x2, dist2);
if license('test', 'Statistics_Toolbox')
fprintf('Result using the function "cdf" is %g, and using "trapz" is %g', y1, y2)
else
fprintf('Result using the function "trapz" is %g', y2)
end
Result using the function "cdf" is 0.158655, and using "trapz" is 0.158706

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!