工作中需要用到polylog方程。但是在matlab里面没有这个方程的定义。找了很久,只发现有polylog的二阶定义
dilog。相比之下,mathematics里面有polylog的函数,应用起来很方便。因为自己用matlab比较顺手,所以还是希望能有polylog函数在matlab里面的定义。后来在另一个同事中找到一个matlab的近似定义,我比较了2阶情况。最大误差在1e-3。或许对其他人也有帮助。
%This function will calculate the polylog g_s(z) for -inf
%given that z is a real number. The cutoff for switching to the
%asymptotic expansion limits the precision to 1e-4 in this regime.
%The desired precision for -1
function out = polylog(z,s,error)
if s>1
%perform piece-wise calculation of polylog g_s(z) with spec'd error
j = 1; %vector index
maxj = length(z); %input vector length
g = zeros(size(z)); %initialize output
while j<=maxj
if abs(z(j))<=1 %series definition
zn = 1; %z^n term
epsilon = 1;