How can I improve the accuracy of cumtrapz
5 views (last 30 days)
Show older comments
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 Comments
dpb
on 4 Apr 2014
...value=0.99668259 (no accurate)...
followed by
...value=0.99668259 (very accurate)...
Look identical to me...???
Answers (0)
See Also
Categories
Find more on Function Creation 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!