-
Notifications
You must be signed in to change notification settings - Fork 1
/
mlf.m
175 lines (157 loc) · 6.22 KB
/
mlf.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
function [e]=mlf(alf,bet,c,fi)
%
% MLF -- Mittag-Leffler function.
% MLF (alpha,beta,Z,P) is the Mittag-Leffler function E_{alpha,beta}(Z)
% evaluated with accuracy 10^(-P) for each element of Z.
% alpha and beta are scalars, P is integer, Z can be a vector or
% a two-dimensional array. The output is of the same size as Z.
% (C) 2001-2012 Igor Podlubny, Martin Kacenak
% Last update: 2012-09-07
[cRows, cCols] = size(c);
c=m2v(c);
if nargin<4 , fi=6; end
if nargin<3 || alf<=0 || fi<=0
else
[r,s]=size(c); [r1,s1]=size(alf); [r2,s2]=size(bet);
mx=max([r,s]); mx1=max([r1,s1]); mx2=max([r2,s2]);
if (r>1 && s>1) || (r1>1 && s1>1) || (r2>1 && s2>1) || (mx1>1 && mx2>1)
sprintf('wrong number of input parameters')
else
if mx1>mx2 , mxx=mx1; e=zeros(mx,mx1);
else mxx=mx2; e=zeros(mx,mx2);end;
for i1= 1:mx
for i2=1:mxx
if r>s , z=c(i1,1); else z=c(1,i1); end
if mx1>mx2 , if r1>s1 , alfa=alf(i2,1); else alfa=alf(1,i2);end, beta=bet;
else if r2>s2 ,beta=bet(i2,1); else beta=bet(1,i2); end, alfa=alf; end
if beta<0 , rc=(-2*log(10^(-fi)*pi/(6*(abs(beta)+2)*(2*abs(beta))^(abs(beta)))))^alfa;
else rc=(-2*log(10^(-fi)*pi/6))^alfa; end
r0=max([1,2*abs(z),rc]);
if (alfa==1 && beta==1)
e(i1,i2)=exp(z);
else
if (alfa<1 && abs(z)<=1) || ( (1<=alfa && alfa <2) && abs(z)<=floor(20/(2.1-alfa)^(5.5-2*alfa))) || (alfa>=2 && abs(z)<=50)
oldsum=0;
k=0;
while (alfa*k+beta)<=0
k=k+1;
end
newsum=z^k/gamma(alfa*k+beta);
while newsum~=oldsum
oldsum=newsum;
k=k+1;
term=z^k/gamma(alfa*k+beta);
newsum=newsum+term;
k=k+1;
term=z^k/gamma(alfa*k+beta);
newsum=newsum+term;
end
e(i1,i2)=newsum;
else
if (alfa<=1 && abs(z)<=fix(5*alfa+10))
if ((abs(angle(z))>pi*alfa) && (abs(abs(angle(z))-(pi*alfa))>10^(-fi)))
if beta<=1
e(i1,i2)=rombint('K',0,r0,fi,alfa,beta,z);
else
eps=1;
e(i1,i2)=rombint('K',eps,r0,fi,alfa,beta,z)+ ...
rombint('P',-pi*alfa,pi*alfa,fi,alfa,beta,z,eps);
end
elseif (abs(angle(z))<pi*alfa && abs(abs(angle(z))-(pi*alfa))>10^(-fi))
if beta<=1
e(i1,i2)=rombint('K',0,r0,fi,alfa,beta,z)+ ...
(z^((1-beta)/alfa))*(exp(z^(1/alfa))/alfa);
else
eps=abs(z)/2;
e(i1,i2)=rombint('K',eps,r0,fi,alfa,beta,z)+ ...
rombint('P',-pi*alfa,pi*alfa,fi,alfa,beta,z,eps)+ ...
(z^((1-beta)/alfa))*(exp(z^(1/alfa))/alfa);
end
else
eps=abs(z)+0.5;
e(i1,i2)=rombint('K',eps,r0,fi,alfa,beta,z)+ ...
rombint('P',-pi*alfa,pi*alfa,fi,alfa,beta,z,eps);
end
else
if alfa<=1
if (abs(angle(z))<(pi*alfa/2+min(pi,pi*alfa))/2)
% alfa
newsum=(z^((1-beta)/alfa))*exp(z^(1/alfa))/alfa;
for k=1:floor(fi/log10(abs(z)))
newsum=newsum-((z^(-k))/gamma(beta-alfa*k));
% k
end
e(i1,i2)=newsum;
else
newsum=0;
for k=1:floor(fi/log10(abs(z)))
newsum=newsum-((z^-k)/gamma(beta-alfa*k));
end
e(i1,i2)=newsum;
end
else
if alfa>=2
m=floor(alfa/2);
sum=0;
for h=0:m
zn=(z^(1/(m+1)))*exp((2*pi*1i*h)/(m+1));
sum=sum+mlf(alfa/(m+1),beta,zn,fi);
end
e(i1,i2)=(1/(m+1))*sum;
else
e(i1,i2)=(mlf(alfa/2,beta,z^(1/2),fi)+mlf(alfa/2,beta,-z^(1/2),fi))/2;
end
end
end
end
end
end
end
end
end
if isreal(c)
e = real(e);
end
e = v2m(e,cRows,cCols);
function [res]=rombint(funfcn,a,b,order,varargin)
if nargin<4 ,order=6; end
if nargin<3
Warning ('Error in input format')
else
rom=zeros(2,order);
h=b-a;
rom(1,1)=h*(feval(funfcn,a,varargin{:})+feval(funfcn,b,varargin{:}))/2;
ipower=1;
for i= 2:order
sum=0;
for j=1:ipower
sum=sum+feval(funfcn,(a+h*(j-0.5)),varargin{:});
end
rom(2,1)=(rom(1,1)+h*sum)/2;
for k=1:i-1
rom(2,k+1)=((4^k)*rom(2,k)-rom(1,k))/((4^k)-1);
end
for j=0:i-1
rom(1,j+1)=rom(2,j+1);
end
ipower=ipower*2;
h=h/2;
end
res=rom(1,order);
end
function res=K(r,alfa,beta,z)
res=r.^((1-beta)/alfa).*exp(-r.^(1/alfa)).*(r*sin(pi*(1-beta))-...
z*sin(pi*(1-beta+alfa)))/(pi*alfa*(r.^2-2*r*z*cos(pi*alfa)+z.^2));
function res=P(r,alfa,beta,z,eps)
w=(eps^(1/alfa))*sin(r/alfa)+r*(1+(1-beta)/alfa);
res=((eps^(1+(1-beta)/alfa))/(2*pi*alfa))*((exp((eps^(1/alfa))*cos(r/alfa)).*...
(cos(w)+1i*sin(w))))/(eps*exp(1i*r)-z);
function A = v2m(V, M, N)
if numel(V)==M*N,
A = reshape(V, [N, M]);
A = A' ;
else
warning('Wrong dimensions of the output in V2M.')
end
function V = m2v(A)
M = A'; V = M(:);