How can I improve the accuracy of cumtrapz

조회 수: 7 (최근 30일)
jo garoz
jo garoz 2014년 4월 4일
댓글: jo garoz 2014년 4월 8일
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
dpb
dpb 2014년 4월 4일
...value=0.99668259 (no accurate)...
followed by
...value=0.99668259 (very accurate)...
Look identical to me...???
jo garoz
jo garoz 2014년 4월 8일
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

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by