How to perform recursive integration
이전 댓글 표시
Hi,
I am trying to evaluate a function defined by a recursive integral (the math relates to renewal theory. The function is the cumulative probability density function for the ith failure in a renewal process - using a Weibull distribution in the example code).
The recursive series of functions are defined by:

Here is a code example (I want to evaluate F2(0.5) for a weibull distribution with shape = 2 and scale = 1):
wb = @(x) wblpdf(x,2,1);
cdfn(wb,2,0.5)
function y = cdfn(f,i,t)
if i==0
y=1;
else
fun = @(x) f(x)*cdfn(f,i-1,t-x);
y = integral(fun,0,t);
end
end
Edit: I have attached a piece of code that does the job (at least for values of Shape > 1) using 'brute force' integration (= treating it as a discrete sum). The final output is the renewal function:
답변 (1개)
syms a b x t positive
syms F0
f(x) = b/a*(x/a)^(b-1)*exp(-(x/a)^b);
F0(t) = 1;
F1(t) = int(f(x)*F0(t-x),x,0,t)
F2(t,x) = f(x)*F1(t-x)
vpaintegral(subs(F2(t,x),[a b t],[1 0.2 0.5]),x,0,0.5)
댓글 수: 9
Dyuman Joshi
2023년 11월 8일
Note - requires Symbolic Math Toolbox.
Ronnie Vang
2023년 11월 8일
편집: Ronnie Vang
2023년 11월 8일
As I read the code, it is not actually a recursive solution, correct? It is a hard coded version only working for i=2?
You wrote you want F2(0.5). So no need for a recursive solution.
In my application, I will be looping through i values (with a condition that F(i,1) is larger than some defined error. The value of i can go to 50 or even higher values.
I don't understand "F(i,1) is larger than some defined error". You mean "smaller" ?
I made it work using 'brute force' integration (treating it as discrete sums), but I would like to take advantage of the MatLab integration function.
I doubt you can make work a 50-fold convolution integral reliably.
Ronnie Vang
2023년 11월 8일
And do you get the result from above (F2(0.5) ~ 0.32976) with your code ? And 1 in the limit as t -> Inf for larger values of i ?
This code should work in the general case, but it will become slow very soon:
a = 1;
b = 0.2;
f = @(x)b/a*(x./a).^(b-1).*exp(-(x/a).^b);
F{1} = @(t) ones(size(t));
for i = 2:3
F{i} = @(t) integral(@(x)f(x).*F{i-1}(t-x),0,t,'ArrayValued',true);
end
F{3}(0.5)
F{3}(1000)
Ronnie Vang
2023년 11월 8일
편집: Ronnie Vang
2023년 11월 8일
Maybe of interest for you:
Thus a FORTRAN code seems to exist to solve your problem efficiently.
카테고리
도움말 센터 및 File Exchange에서 Code Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


