我试图在Matlab中解决一个函数:digamma(x)= C.

时间:2013-12-18 09:01:40

标签: matlab gamma-function

例如,C=0

solve('psi(x)=0')

ans =
-226.83295306016122662496413158295

psi(ans)

???Error using ==> psi
Input must be single or double.

我无法得到正确答案

1 个答案:

答案 0 :(得分:1)

有趣......这似乎是solve给我的一个错误...无论我试图解决什么价值,我总是会得到-227左右的奇怪值。即使我试图通过给出digamma的近似来欺骗MATLAB,我也会得到相同的结果或更糟:

>> solve('(gamma(x+0.01)-gamma(x))/0.01/gamma(x)=0')
ans = 
    matrix([[-226.83790783643886637282996154237]])

>> solve('(gammaln(x+0.01)-gammaln(x-0.01))/0.02 = 0')
??? Error using ==> mupadmex
Error in MuPAD command: cannot differentiate equation [numeric::fsolve]

以下数值方法有效:

%// value of the digamma to solve for
Y = -10; 

%// Solve using numerical scheme 
X = fsolve(@(x)psi(max(0,x)) - Y, exp(Y))

%// Check solution: psi(X) ≈ Y
psi(X)