Trying to calculate a function with several integrals
Show older comments
Hi,
I'm trying to calculate the difference between two random variables which are following different disribution laws. Then, I try to calculate the probability that the difference is superior to 0. Here is the code :
syms x y z f(x) g(y) a(y,z) c(z)
sigmaR = 10 ; sigmaC = 25 ; muR = 450 ; muC = 390 ; % paramètres des lois normales
k = 40 ; lambda = 479.6; teta = 0; %paramètre de la loi de Weibull
AR = 1/(sigmaR*sqrt(2*pi()));
AC = 1/(sigmaC*sqrt(2*pi()));
f(x) = AC .* exp((-1/2).*((x-muC)./sigmaC).^2) ; % Loi normale 1
g(y) = AR .* exp((-1/2).*((y-muR)./sigmaR).^2) ; % Loi normale 2
%g(y) = (k/lambda) * (y/lambda)^(k-1) * exp(-(y/lambda)^k); % Loi de Weibull
a(y,z) = f(z+y)*g(y);
c(z) = int(a,y,[-Inf +Inf]); %Densité de probabilité de X-Y
double(c(1))
P = (int(c,z,[0 +Inf])) %Probabilité que C soit > 0
hold on
grid on
fplot(f,[200 600])
fplot(g,[200 600])
fplot(c,[-30 30])
% u=[-200:1:30];
% d=u;
% for i=1:length(u)
% d(i)=c(u(i));
% end
% plot(u,d);
hold off
When i'm executing the code with g(y) being the normal law 2, it works well. But, when I try with g(y) = weibull law, it doesn't work :
- the function c(z) computes well because the code line "double(C(1))" gives a coherent value,
- The P variable doesn't gives a value but a function,
- The curve fplot(c,[-30 30]) is completely false (it does not match the result of plot(u,d) which is in commentary
I've tried to transform the code to use "function_handle" instead of symbolic but without success.
I hope that someone will find how to resolve this issue. Thank you in advance.
Accepted Answer
More Answers (0)
Categories
Find more on Exploration and Visualization 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!