Regularizied hypergeometric function gives an error for z being greater than 1.

4 次查看(过去 30 天)
Hi,
I'm having truble with using the hypergeometric function used in frational derivtives of log(ax+b). Using the formula from Wolfram:
Where is the regularizied hypergeometric function in the first fraction (fraction1 in code). This is the function that gives me problems.
Since, hypergeom(c,d,z) function is the genral one to convert it to the regularized version I needed to divide it by gamma(d), according to This post.
function [result] = natural_log_frac_derivative(a,b,x,n)
fraction1 = ((a*x^(1-n)) * (hypergeom([1,1],[2-n],-a*x/b))/gamma([2-n]))/b;
fraction2 = floor((pi()-angle(b)-angle(1+(a*x)/b))/(2*pi()));
fraction3 = (x^(-n)*(2*j*pi()*fraction2+log10(b)))/gamma(1-n);
result = fraction1+fraction3;
end
The exact problem lies when I try to get a larger derivative than the first. n>1 gives an error.
natural_log_frac_derivative(1,1,2,1)
Gives a 1/3 result as expected.
natural_log_frac_derivative(1,1,2,2)
Gives the following error (line 5 is the second line in the code above):
Error using sym/hypergeom (line 43)
Invalid arguments.
Error in sym.useSymForNumeric (line 165)
res = cast(fn(args{:}),superiorfloat(varargin{:}));
Error in hypergeom (line 41)
h = sym.useSymForNumeric(@hypergeom,n,d,z);
Error in natural_log_frac_derivative (line 5)
fraction1 = ((a*x^(1-n)) * (hypergeom([1,1],[2-n],-a*x/b))/gamma([2-n]))/b;
Any ideas how to fix this so the function is not limited to n = 1?
Thank you in advanced.

采纳的回答

David Goodmanson
David Goodmanson 2020-7-22
编辑:David Goodmanson 2020-7-22
Hi Wojciech,
I am assuming that there is no problem when n is not an integer, only when n is a positive integer greater than 1. In that case there is an identity available in terms of a different F21, but at least there is no need for that when a and b are positive real, and probably also when a and b both have positive real part. When n is an integer, then straight differentiation shows that
dn/dxn log(ax+b) = (-)^(n-1)*(n-1)!*a^n/(ax+b)^n
  1 个评论
Wojciech Kalinowski
Hi David,
So just add a IF statment to check if z is a natural number or not, and if it is evaulated using that method?
That does indeed work. Thank you!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by