Professional Documents
Culture Documents
Fraktionale Differentialgleichungen
Seite 20/31
v
u n
u1 X
RM SE = t
e2 ,
n
t=1
Matlab Function:
1
2
3
4
5
6
7
8
10
11
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%INPUT
%----% - f : The required function. f must be defined for [t0,t0+T]
% - T
: period of the function
% - M
: number of frequencies (default: 50)
%-------------------------------------------------------------------------function .
[ReturnedValue1,ReturnedValue2,ReturnedValue6,ReturnedValue3,ReturnedValue4,
...
ReturnedValue7,ReturnedValue5] = .
Fractional_Derivative_Fourier_Series_Complete ...
(FunctionToBeDerivedInStringX, Beginning_Point, End_Point, .
RequiredDerivative)
%--------------------------------------------------------------------------
12
13
14
15
16
17
18
19
20
21
22
The code of this function was inspired/excerpted/modified by/from both Guilherme Coco fourier_coeff Beltramini and George Papazafeiropoulos fourier_diffint
Diskussion
Fraktionale Differentialgleichungen
Seite 21/31
23
24
25
26
27
28
29
A0_New = 1/T*quadl(fun,t0,t0+T);
30
31
32
coeff_New(2*M+1,1) = 0;
coeff_New(1) = A0_New;
% Initialization
33
34
35
36
37
38
39
40
41
42
43
44
45
%--------------------------------------------------------------------------
46
47
48
49
50
51
52
53
54
55
56
Fourier_Series = zeros(N,2*M+1);
% Initialization
Fourier_Series(:,1) = 1;
for m=2:M+1
Fourier_Series(:,m) = cos(w0*(m-1)*t);
Fourier_Series(:,m+M) = sin(w0*(m-1)*t);
end
Function_Reconstructed = Fourier_Series*reshape(coeff_New,2*M+1,1);
ReturnedValue1 = Function_Reconstructed;
57
58
59
60
61
62
63
64
65
66
for i = 1 : length(t)
67
68
69
end
70
71
72
73
74
Function_Reconstructed_filtered = Function_Reconstructed;
Indecies1 = find(ErrorVector_Method2 > Error_Method2/2);
Function_Reconstructed_filtered(Indecies1) = U(Indecies1);
75
76
77
Diskussion
78
Fraktionale Differentialgleichungen
Seite 22/31
ReturnedValue6 = ErrorVector_Method2;
79
80
81
82
83
84
85
86
87
88
89
A0_New_filtered = Fourier_Series_Method2(1);
An_New_filtered = Fourier_Series_Method2(2 : M+1);
Bn_New_filtered = Fourier_Series_Method2(M+2 : 2*M+1);
coeff_New_filtered = [A0_New_filtered ; An_New_filtered ; Bn_New_filtered];
90
91
92
93
94
95
96
97
98
99
Fourier_Series_filtered = zeros(N,2*M+1);
% Initialization
Fourier_Series_filtered(:,1) = 1;
for m=2:M+1
Fourier_Series_filtered(:,m) = cos(w0*(m-1)*t);
Fourier_Series_filtered(:,m+M) = sin(w0*(m-1)*t);
end
100
101
102
Function_Reconstructed_filtered_reconstruct = .
Fourier_Series_filtered*reshape(coeff_New_filtered,2*M+1,1);
ReturnedValue3 = Function_Reconstructed_filtered_reconstruct;
103
104
105
106
for i = 1 : length(t)
107
ErrorVector_Method_Reconstructed(i) = .
sqrt((Function_Reconstructed_filtered_reconstruct(i) - U(i)).^2);
108
109
end
110
111
112
113
Reconstruction_Error_Method2 = .
sqrt(mean((Function_Reconstructed_filtered_reconstruct - U).^2));
ReturnedValue4 = Reconstruction_Error_Method2;
ReturnedValue7 = ErrorVector_Method_Reconstructed;
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
n = length(An_New_filtered);
KK = (1:n) * w0;
ZZ = (q * pi)/2;
% replicate data appropriately
eval_t = t(:,ones(1,n));
eval_n = KK(:,ones(1,length(t)));
eval_An = An_New_filtered(:,ones(1,length(t)));
eval_Bn = Bn_New_filtered(:,ones(1,length(t)));
Diskussion
130
131
Fraktionale Differentialgleichungen
Seite 23/31
% differintegral
Y2_Der = A0_Fourier .* (t + eps).^(-q) + sum((eval_n + .
eps).^(q).*(eval_An.*cos(eval_n.*eval_t + ZZ) + eval_Bn.*sin(eval_n.*eval_t
+ ZZ)),2);
132
133
134
ReturnedValue5 = Y2_Der;
%--------------------------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This example applies the modified Fourier Series and Then derives it
3
4
5
6
7
8
9
10
11
12
clear all;clc;
figure
t = linspace(0,2*pi,100);
InputFunction = sin(x);
fun = inline(InputFunction,x);
U = fun(t);
alphaX = -10 : 1 : 10;
cc = jet(length(alphaX));
N = 0;
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
set(gca,xTick,0:pi/2:2*pi)
set(gca,xTickLabel,{0,\pi/2,\pi,3\pi/2,2\pi})
35
36
37
38
xlabel(x,fontsize,14,Interpreter,latex);
ylabel($ y = d^{\alpha} f(x) / d .
x^{\alpha}$,fontsize,14,Interpreter,latex);
title(Fractional derivatives of $f(x) = sin(x)$ of order $\alpha = 0, 0.1,
..., 0.2, 1.0$,fontsize,14,Interpreter,latex)
39
40
41
Diskussion
Fraktionale Differentialgleichungen
Seite 24/31
42
43
44
45
46
47
text(1.57,-0.4,$y = .
cos(x)$,fontsize,14,color,cc(10+11,:),Interpreter,latex)
text(3.35,0.8,$y = .
-cos(x)$,fontsize,14,color,cc(-10+11,:),Interpreter,latex)
text(3.35,0.2,$y = .
sin(x)$,fontsize,14,color,cc(0+11,:),Interpreter,latex)
48
49
50
51
52
53
54
55
figure;
plot(t,U,LineWidth,2)
hold on
plot(t,Y3,r.,LineWidth,2)
grid on
set(gca,xTick,0:pi/2:2*pi)
set(gca,xTickLabel,{0,\pi/2,\pi,3\pi/2,2\pi})
56
57
58
59
60
61
xlabel(x,fontsize,14,Interpreter,latex);
ylabel($ y = sin(x)$,fontsize,14,Interpreter,latex);
title(Fourier Series approximation of $f(x) = sin(x)$, Extreme values are
filtered,fontsize,14,Interpreter,latex)
h2 = legend($Original$, $Approximation$);
set(h2,Interpreter,latex);
62
63
64
65
66
67
figure;
plot(t,Error_Filted_And_Original_Vector,LineWidth,2)
hold on
plot(t,Error_Recons_Signal_After_Filterat_And_Original_Vector,r.,LineWidth,2)
grid on
68
69
70
71
72
73
xlabel(x,fontsize,14,Interpreter,latex);
ylabel($\sqrt{\frac{1}{n}\sum_{t=1}^{n}e_t^2}$,fontsize,14,Interpreter,latex);
title(Root mean squared Error between Original signal and Fourier Series .
approximation,fontsize,14,Interpreter,latex)
h3 = legend($Before Filtration$, $After Filtration$);
set(h3,Interpreter,latex);
Fraktionale Differentialgleichungen
Diskussion
1.5
y = d f (x)/dx
Seite 25/31
= 1
= 0.9
= 0.8
= 0.7
= 0.6
= 0.5
= 0.4
= 0.3
= 0.2
= 0.1
=0
= 0.1
= 0.2
= 0.3
= 0.4
= 0.5
= 0.6
= 0.7
= 0.8
= 0.9
=1
y = cos(x)
0.5
y = sin(x)
0
0.5
y = cos(x)
1
1.5
3
2
Abbildung 7: Fractional Derivative Calculation using modified Fourier Series. Very powerful method, works for all R. Works perfectly for periodic functions, however, within non periodic
functions Gibbs phenomenon will make the result little poor!
Fourier Series approximation of f (x) = sin(x), Extreme values are filtered
Root mean
squared Error between Original signal and Fourier Series approximation
109
1.8
1
Original
Fourier Series Approximation
0.8
Before Filtration
After Filtration
1.6
0.6
1.4
0.4
2
t=1 et
0.8
q P
n
1
y = sin(x)
1.2
0.2
0
0.2
0.6
0.4
0.4
0.6
0.2
0.8
1
3
2
3
2
Abbildung 8: Modified Fourier Series approximation of f (x) = sin(x) where the extreme values
are filtered based on Root Mean Squared Error threshold.
Fraktionale Differentialgleichungen
Diskussion
Seite 26/31
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This example applies the modified Fourier Series and Then derives it
3
4
5
6
7
8
9
10
11
12
clear all;clc;
figure
t = linspace(0,2*pi,100);
InputFunction = x.*(x - pi).*(x - 2*pi);
fun = inline(InputFunction,x);
U = fun(t);
alphaX = -10 : 1 : 10;
cc = jet(length(alphaX));
N = 0;
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
%%
for alpha = -10 : 1 : 10
[Y1,Error_Between_Filted_And_Original,Error_Filted_And_Original_Vector, ...
Y3,Error_Recons_Signal_After_Filterat_And_Original, ...
Error_Recons_Signal_After_Filterat_And_Original_Vector,Y5, ...
Threshold] = Fractional_Derivative_Fourier_Series_Complete ...
(InputFunction, 0, 2*pi, alpha/10);
if(length(Y5) == 1)
Y5(1:length(t)) = Y5(length(Y5));
else
%do nothing
end
if(alpha == -10 || alpha == 0 || alpha == 10)
N = 2.5;
else
N = 1.5;
end
plot(t,Y5,LineWidth,N,color,cc(alpha+11,:));hold on
end
%%
set(gca,xTick,0:pi/2:2*pi)
set(gca,xTickLabel,{0,\pi/2,\pi,3\pi/2,2\pi})
36
37
38
39
40
xlabel(x,fontsize,14,Interpreter,latex);
ylabel($ y = d^{\alpha} f(x) / d x^{\alpha}$,fontsize,14,Interpreter, ...
latex);
title(Fractional derivatives of $f(x) = x*(x - pi)*(x - 2*pi)$ of order .
$\alpha = -1, -0.9, ..., 0.9, 1.0$,fontsize,14,Interpreter,latex)
41
42
43
44
45
46
47
% text(1.57,-0.4,$y =
.
.
Diskussion
Fraktionale Differentialgleichungen
Seite 27/31
cos(x)$,fontsize,14,color,cc(10+11,:),Interpreter,latex)
% text(3.35,0.8,$y = .
-cos(x)$,fontsize,14,color,cc(-10+11,:),Interpreter,latex)
% text(3.35,0.2,$y = .
sin(x)$,fontsize,14,color,cc(0+11,:),Interpreter,latex)
48
49
50
51
52
53
54
55
56
57
figure;
plot(t,U,LineWidth,1.5)
hold on
plot(t,Y3,r.,LineWidth,1)
grid on
set(gca,xTick,0:pi/2:2*pi)
set(gca,xTickLabel,{0,\pi/2,\pi,3\pi/2,2\pi})
58
59
60
61
62
63
xlabel(x,fontsize,14,Interpreter,latex);
ylabel($ f(x) = x*(x - pi)*(x - 2*pi)$,fontsize,14,Interpreter,latex);
title(Fourier Series approximation. Extreme values are .
filtered,fontsize,14,Interpreter,latex)
h2 = legend($Original$, $Approximation$);
set(h2,Interpreter,latex);
64
65
66
67
68
69
70
71
figure;
plot(t,Error_Filted_And_Original_Vector,LineWidth,1.5)
hold on
plot(t,Error_Recons_Signal_After_Filterat_And_Original_Vector,r.,LineWidth,1)
hold on
Threshold(1:length(t)) = Threshold(length(Threshold));
plot(t,Threshold,g-,LineWidth,1);grid on
72
73
74
75
76
77
1
2
3
4
xlabel(x,fontsize,14,Interpreter,latex);
ylabel($\sqrt{\frac{1}{n}\sum_{t=1}^{n}e_t^2}$,fontsize,14,Interpreter,latex);
title(Root mean squared Error between Original signal and Fourier Series .
approximation,fontsize,14,Interpreter,latex)
h3 = legend($Before Filtration$, $After Filtration$);
set(h3,Interpreter,latex);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
syms x;
Y = x.*(x - pi).*(x - 2*pi);
t = linspace(0,2*pi,100); % As defined in the fractional calculus function
5
6
7
8
9
10
11
12
13
14
15
16
17
18
%----- alpha = -1, -1st fractional derivative / normal integration -------RR = int(Y,x);
RR_X = subs(RR,x,t);
plot(t,RR_X,r.); grid on
Fraktionale Differentialgleichungen
Diskussion
Seite 28/31
Fractional derivatives of f (x) = x (x pi) (x 2 pi) of order = 1, 0.9, ..., 0.9, 1.0
25
= 1
= 0.9
= 0.8
= 0.7
= 0.6
= 0.5
= 0.4
= 0.3
= 0.2
= 0.1
=0
= 0.1
= 0.2
= 0.3
= 0.4
= 0.5
= 0.6
= 0.7
= 0.8
= 0.9
=1
20
Seems to be
shifted above!
y = d f (x)/dx
15
10
0
5
10
15
3
2
Root mean
squared Error between Original signal and Fourier Series approximation
103
1
15
Original
Fourier Series Approximation
Before Filtration
After Filtration
Threshold
10
0.8
0.7
2
t=1 et
0.6
q P
n
1
0.5
0.9
0.4
0.3
0.2
10
15
0.1
0
3
2
3
2
Abbildung 10: Modified Fourier Series approximation of f (x) = x (x pi) (x 2 pi) where
the extreme values are filtered based on Root Mean Squared Error threshold.
Diskussion
Fraktionale Differentialgleichungen
Seite 29/31
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%% My Fourier Series Function With Enhancement & Filteration %%%%%%%
3
4
% This example applies the modified Fourier Series and Then derives it
5
6
7
8
9
10
11
12
13
14
15
tic
clear all;clc;
figure
t = linspace(0,2*pi,100);
InputFunction = x;
fun = inline(InputFunction,x);
U = fun(t);
alphaX = -10 : 1 : 10;
cc = jet(length(alphaX));
N = 0;
16
17
18
19
20
21
22
23
%%
for alpha = -10 : 1 : 10
[Y1,Error_Between_Filted_And_Original,Error_Filted_And_Original_Vector, ...
Y3,Error_Recons_Signal_After_Filterat_And_Original, ...
Error_Recons_Signal_After_Filterat_And_Original_Vector,Y5, ...
Threshold] = Fractional_Derivative_Fourier_Series_Complete ...
(InputFunction, 0, 2*pi, alpha/10);
24
if(length(Y5) == 1)
Y5(1:length(t)) = Y5(length(Y5));
else
%do nothing
end
if(alpha == -10 || alpha == 0 || alpha == 10)
N = 2.5;
else
N = 1.5;
end
plot(t,Y5,LineWidth,N,color,cc(alpha+11,:));hold on
25
26
27
28
29
30
31
32
33
34
35
36
37
end
%%
38
39
40
set(gca,xTick,0:pi/2:2*pi)
set(gca,xTickLabel,{0,\pi/2,\pi,3\pi/2,2\pi})
41
42
43
44
xlabel(x,fontsize,14,Interpreter,latex);
ylabel($ y = d^{\alpha} f(x) / d .
x^{\alpha}$,fontsize,14,Interpreter,latex);
title(Fractional derivatives of $f(x) = x$ of order $\alpha = -1, -0.9, ...,
0.9, 1.0$,fontsize,14,Interpreter,latex)
45
46
47
48
.
.
Diskussion
Fraktionale Differentialgleichungen
Seite 30/31
49
50
51
% text(1.57,-0.4,$y = .
cos(x)$,fontsize,14,color,cc(10+11,:),Interpreter,latex)
% text(3.35,0.8,$y = .
-cos(x)$,fontsize,14,color,cc(-10+11,:),Interpreter,latex)
% text(3.35,0.2,$y = .
sin(x)$,fontsize,14,color,cc(0+11,:),Interpreter,latex)
52
53
54
55
56
57
58
59
60
61
figure;
plot(t,U,LineWidth,1.5)
hold on
plot(t,Y3,r.,LineWidth,1)
grid on
set(gca,xTick,0:pi/2:2*pi)
set(gca,xTickLabel,{0,\pi/2,\pi,3\pi/2,2\pi})
62
63
64
65
66
67
xlabel(x,fontsize,14,Interpreter,latex);
ylabel($ f(x) = x$,fontsize,14,Interpreter,latex);
title(Fourier Series approximation. Extreme values are .
filtered,fontsize,14,Interpreter,latex)
h2 = legend($Original$, $Approximation$);
set(h2,Interpreter,latex);
68
69
70
71
72
73
74
75
figure;
plot(t,Error_Filted_And_Original_Vector,LineWidth,1.5)
hold on
plot(t,Error_Recons_Signal_After_Filterat_And_Original_Vector,r.,LineWidth,1)
hold on
Threshold(1:length(t)) = Threshold(length(Threshold));
plot(t,Threshold,g-,LineWidth,1);grid on
76
77
78
79
80
81
82
xlabel(x,fontsize,14,Interpreter,latex);
ylabel($\sqrt{\frac{1}{n}\sum_{t=1}^{n}e_t^2}$,fontsize,14,Interpreter,latex);
title(Root mean squared Error between Original signal and Fourier Series .
approximation,fontsize,14,Interpreter,latex)
h3 = legend($Before Filtration$, $After Filtration$);
set(h3,Interpreter,latex);
toc
Fraktionale Differentialgleichungen
Diskussion
Seite 31/31
25
= 1
= 0.9
= 0.8
= 0.7
= 0.6
= 0.5
= 0.4
= 0.3
= 0.2
= 0.1
=0
= 0.1
= 0.2
= 0.3
= 0.4
= 0.5
= 0.6
= 0.7
= 0.8
= 0.9
=1
20
y = d f (x)/dx
15
10
0
5
10
15
3
2
Abbildung 11: Fractional Derivative Calculation using modified Fourier Series. Modification still
does not work as required!
Root mean squared Error between Original signal and Fourier Series approximation
3.5
7
Original
Approximation
Before Filtration
After Filtration
1.5
0.5
2
t=1 et
2.5
q P
n
1
f (x) = x
3
2
3
2
Abbildung 12: Modified Fourier Series approximation of f (x) = x where the extreme values are
filtered based on Root Mean Squared Error threshold.