How can I improve the accuracy of cumtrapz

7 visualizaciones (últimos 30 días)
jo garoz
jo garoz el 4 de Abr. de 2014
Comentada: jo garoz el 8 de Abr. de 2014
I need to find the CDF of a non standard probability distribution function (pdf). So I run the integral using cumtrapz then I got the vector = CDF. My code works, however the output is very poor regarding accuracy. I also use the function "integral" which is very accurate but the output of that function is a scalar. Is there any way to get a precise vector as an output?
I use the Weibull distribution JUST FOR testing the accuracy of cumtrapz.
This is my code
%test for finding the cdf of the variable YBL6 which follows the Weibull distribution theta = 2.10604; tau = 1.21248; Z = (YBL6./theta).^tau; %YBL6 is a vector of losses, which is not linear so I can't use x:0:dx:10 c = exp(-(Z)); Wpdf = (tau./YBL6).*Z.*c; Wcdf = cumtrapz(YBL6,Wpdf); % the result is a vector, which shows at the right end point the value=0.99668259 (no accurate)
% test 2, this code returns the maximum value of the CDF, % integral reports the final result of integration at the right endpoint=b % which is ok BUT the code doesn't produce a vector theta = 2.10604; tau = 1.21248; a = 0; b = max(YBL6); Wpdf = @(YBL6,theta,tau)((tau./YBL6).*((YBL6./theta).^tau).*exp(-((YBL6./theta).^tau))); % a function handle cdf = integral(@(YBL6)Wpdf(YBL6,theta,tau),a,b,'ArrayValued',true,'AbsTol',1e-12,'RelTol',1e-10); % the result is a scalar, which shows just the right end point the value=0.99668259 (very accurate)
  2 comentarios
dpb
dpb el 4 de Abr. de 2014
...value=0.99668259 (no accurate)...
followed by
...value=0.99668259 (very accurate)...
Look identical to me...???
jo garoz
jo garoz el 8 de Abr. de 2014
Apologies for the typing error. 1. Cumtrapz output is a vector, which shows at the right end point the value=0.99668259 (no accurate) 2. Integral shows just the right end point the value=0.997814109577 (very accurate)
The technical support helped me and this is the answer to my problem:
a = 0; b = max(YBL6); Wpdf_handle = @(YBL6,theta,tau)((tau./YBL6).*((YBL6./theta).^tau).*exp(-((YBL6./theta).^tau))); % a function handle cdf_integral=zeros(size(YBL6)); for i=1:length(YBL6) cdf_integral(i) = integral(@(YBL6)Wpdf_handle(YBL6,theta,tau),a,YBL6(i),'AbsTol',1e-12,'RelTol',1e-10); end
So now I get a vector which is the CDF and it's very accurate

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Function Creation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by