Hello,
I'm trying to use a continuous form of Erlang B formula in my code as a function. I also need to differentiate this function so I need to use a symbolic variable in it. I'm using the function in: https://www.mathworks.com/matlabcentral/fileexchange/37279-erlang-b-continuation?product=EL
However, gammainc does not accept symbolic variables, i've tried to use igamma(nu,z)/gamma(nu) for the incomplete gamma upper, the problem with this one is that once I use subs command and then vpa, it always outputs NaN,
I also try another function -> gamma_symbolic (which requires maple as symengine, now i'm using matlab R2015b that cannot change between mupad and maple anymore) https://nl.mathworks.com/matlabcentral/answers/96854-how-can-i-use-incomplete-gamma-function-gammainc-in-matlab-7-5-r2007b-to-accept-symbolic-input
Please help. I spent really a lot of time trying to fix this issue. But I still haven't solved it yet!
PS. Why does the first alternative always outputs NaN? I don't understand. For example, I do:
syms S
tes = igamma(sym(S),0.5)/gamma(sym(S))
diftes = diff(tes,S)
subs(diftes, S,6)
which outputs:
tes =
igamma(S, 1/2)/gamma(S)
diftes =
((1/2)^S*(hypergeom([S, S], [S + 1, S + 1], -1/2)/S^2 - (1/(1/2)^S*pi*(log(2) + psi(1 - S) - pi*cot(pi*(S - 1))))/(gamma(1 - S)*sin(pi*(S - 1)))) + (1/2)^S*log(1/2)*expint(1 - S, 1/2))/gamma(S) - (psi(S)*igamma(S, 1/2))/gamma(S)
ans =
NaN
Please help. It seems like I can never solve this!

댓글 수: 5

Torsten
Torsten 2016년 8월 5일
Plotting "diftes" should show why you can't evaluate it for S=6.
Best wishes
Torsten.
By the way:
I think you mean
tes=igamma(0.5,S)/gamma(0.5),
don't you ?
Best wishes
Torsten.
Hi Torsten,
Thanks for your message. I use sym(S) because I saw in the documentation that it is for a sym object. I did try using igamma(0.5,S)/gamma(0.5) first, but since it did output NaN, I thought this was the problem.
I tried to plot it but:
S = [0:50];
>> plot(S,diftes)
Error using plot
A numeric or double convertible argument is expected
I still don't get it. Is there something that I'm missing here?
Please exactly tell us whether you want to analyze
igamma(0.5,S)/gamma(0.5)
or
igamma(S,0.5)/gamma(S)
Best wishes
Torsten.
K_Kharis
K_Kharis 2016년 8월 5일
편집: K_Kharis 2016년 8월 5일
Sorry, I had a typo.
I originally need:
1/(gammainc(A,S,'upper')*x);
with A = 0.5 (given parameter). So I change it using gammainc(z, nu, 'upper') = igamma(nu, z)/gamma(nu). with:
igamma(S, 0.5)/gamma(S)
And I need S as a symbolic variable because I want to differentiate this function.
The differentiation always seems to work, but once I use subs it outputs NaN

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

답변 (0개)

질문:

2016년 8월 5일

편집:

2016년 8월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by