-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpluto_fourier_series.jl
2253 lines (1880 loc) · 63.2 KB
/
pluto_fourier_series.jl
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
### A Pluto.jl notebook ###
# v0.19.46
using Markdown
using InteractiveUtils
# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).
macro bind(def, element)
quote
local iv = try Base.loaded_modules[Base.PkgId(Base.UUID("6e696c72-6542-2067-7265-42206c756150"), "AbstractPlutoDingetjes")].Bonds.initial_value catch; b -> missing; end
local el = $(esc(element))
global $(esc(def)) = Core.applicable(Base.get, el) ? Base.get(el) : iv(el)
el
end
end
# ╔═╡ 581f8ff0-d1fc-11ec-3cab-5f335ec587ad
begin
using PlutoUI
using Plots
using Colors
using LaTeXStrings
# Small patch to make images look more crisp:
# https://github.com/JuliaImages/ImageShow.jl/pull/50
Base.showable(::MIME"text/html", ::AbstractMatrix{<:Colorant}) = false
nbsp = html" "
end
# ╔═╡ 79521e83-f32a-48aa-bdf1-27f3f95ecb9e
md"""
## Fourier Series
"""
# ╔═╡ c299148e-4b85-4bf3-a514-20d1dff0dc59
md"""
#### 1. Definition of Fourier Series
Throughout this note we consider piecewise continuous $1$-periodic functions $f(x)$ on $\mathbb{R}$, that is,
- $f(x+1)=f(x)$ for all $x\in\mathbb{R}$.
- There exist numbers $0=a_0<a_1<\dotsb<a_m=1$ such that $f(x)$ is continuous on each open interval $(a_{j-1},a_j$, $j=1,\dotsc,m$, and limits exist:
$f(a_0+0), \quad f(a_1-0), \quad f(a_1+0), \quad \dotsc \quad f(a_m-0).$
We remark that if we restrict $f(x)$ on each closed interval $[a_{j-1}+k,a_{j}+k]$ for $j=1,\dotsc,m$ and $k\in\mathbb{Z}$, $f(x)$ can be regarded as a continuous function. We denote by $\mathcal{L}$ the set of all piecewise continuous $1$-periodic functions on $\mathbb{R}$.
All the $e^{2\pi i nx}$, $n\in\mathbb{Z}$ are $1$-periodic smooth functions. In the spirit of Joseph Fourier (1768-1830), we consider whether $f(x)\in\mathcal{L}$ can be expressed by a trigonometric series of the form
$\sum_{n=-\infty}^{\infty}c_ne^{2\pi i nx}.$
If $f(x)=\displaystyle\sum_{n=-\infty}^{\infty}c_ne^{2\pi i nx}$ holds, then we have by formal computation
$\begin{aligned}
\int_0^1
f(x)
e^{-2\pi i mx}
dx
& =
\int_0^1
\sum_{n=-\infty}^{\infty}
c_n
e^{2\pi i (n-m)x}
dx
\\
& =
\sum_{n=-\infty}^{\infty}
c_n
\int_0^1
e^{2\pi i (n-m)x}
dx
\\
& =
\sum_{n=-\infty}^{\infty}
c_n
\delta_{mn}
=
c_m.
\end{aligned}$
Note that the condition $f(x)\in\mathcal{L}$ guarantees the existence of the left hand side of the above. The formal trigonometric series defined by
$\sum_{n=-\infty}^{\infty}c_ne^{2\pi i nx},
\quad
c_n=\int_0^1f(x)e^{-2\pi i nx}dx$
is said to be the Fourier series of $f(x)$, and we denote this by
$f(x)\sim\sum_{n=-\infty}^{\infty}c_ne^{2\pi i nx}.$
$c_n$ is called the $n$-th Fourier coefficient of $f(x)$.
"""
# ╔═╡ 6f6479b6-265a-4474-8a90-3df0ff98cfac
md"""
#### 2. Real Form of the Fourier Series
If $f(x)$ is real valued, then the Fourier series can be written by the real-valued trigonometric series. In this case $\overline{c_n}=c_{-n}$ holds, and $c_0$ is a real number. If we set for $n=0,1,2,\dotsc$
$\overline{c_n}=c_{-n}=\frac{a_n+ib_n}{2},$
$a_n
=
2
\int_0^1
f(x)
\cos(2\pi nx)
dx,$
$b_n
=
2
\int_0^1
f(x)
\sin(2\pi nx)
dx.$
then $b_0=0$, and
$f(x)
\sim
\frac{a_0}{2}
+
\sum_{n=1}^\infty
\bigl(
a_n\cos(2\pi nx)
+
b_n\sin(2\pi n x)
\bigr).$
It is convenient to compute
$\frac{a_0}{2}
=
c_0
=
\int_0^1
f(x)
dx,$
$a_n+ib_n
=
2c_{-n}
=
2
\int_0^1
f(x)
e^{2\pi i nx}
dx,
\quad
n=1,2,3,\dotsc.$
For $\lambda=\mu+\nu\in\mathbb{C}$, $\mu,\nu\in\mathbb{R}$, we have
$\begin{aligned}
e^{\lambda x}
& =
e^{\mu x + i\nu x}
=
e^{\mu x}
\{\cos(\nu x) + i\sin(\nu x)\},
\\
\frac{d}{dx}
e^{\lambda x}
& =
\mu
e^{\mu x}
\{\cos(\nu x) + i\sin(\nu x)\}
+
\nu
e^{\mu x}
\{-\sin(\nu x) + i\cos(\nu x)\}
\\
& =
\mu
e^{\mu x}
\{\cos(\nu x) + i\sin(\nu x)\}
+
i\nu
e^{\mu x}
\{i\sin(\nu x) + \cos(\nu x)\}
\\
& =
(\mu+i\nu)
e^{\mu x}
\{\cos(\nu x) + i\sin(\nu x)\}
=
\lambda
e^{\lambda x},
\end{aligned}$
which is useful for computing Fourier coefficients.
"""
# ╔═╡ fd9270b6-bcb1-444a-b2e8-bc07efee3a24
md"""
#### 3. Example of Fourier Series
Let $f(x)$ be a function defined by
$f(x):=\min\{x-[x],1-x-[1-x]\}, \quad x\in\mathbb{R},$
$[s]:=\max\{m\in\mathbb{Z} : m \leqq s\}, \quad x\in\mathbb{R}.$
In other words, $f(x)$ is a $1$-periodic Lipshitz continuous function such that
$f(x)
=
\begin{cases}
x, &\ x\in[0,1/2),
\\
1-x, &\ x\in[1/2,1).
\end{cases}$
We shall confirm that the Fourier series of $f(x)$ is
$f(x)
\sim
\frac{1}{4}
-
\sum_{k=1}^\infty
\frac{2}{(2k-1)^2\pi^2}
\cos\bigl(2(2k-1)\pi x\bigr).$
Indeed
$\frac{a_0}{2}
=
\int_0^{1/2}xdx+\int_{1/2}^1(1-x)dx
=
\frac{2}{2^3}
=
\frac{1}{4},$
and for $n=1,2,3,\dotsc$,
$\begin{aligned}
a_n+ib_n
& =
2
\int_0^{1/2}xe^{2\pi i nx}dx
+
2
\int_{1/2}^1(1-x)e^{2\pi i nx}dx
\\
& =
\left[
\frac{xe^{2\pi i nx}}{n\pi i}
\right]_0^{1/2}
+
\left[
\frac{(1-x)e^{2\pi i nx}}{n\pi i}
\right]_{1/2}^1
-
\int_0^{1/2}
\frac{e^{2\pi i nx}}{n\pi i}
dx
+
\int_{1/2}^1
\frac{e^{2\pi i nx}}{n\pi i}
dx
\\
& =
0
-
\left[
\frac{e^{2\pi i nx}}{2(n\pi i)^2}
\right]_0^{1/2}
+
\left[
\frac{e^{2\pi i nx}}{2(n\pi i)^2}
\right]_{1/2}^1
\\
& =
\frac{e^{\pi i n}-1-1+e^{\pi i n}}{2n^2\pi^2}
=
\frac{\cos(\pi n)-1}{n^2\pi^2}
=
-
\frac{1-(-1)^n}{n^2\pi^2}
\\
& =
\begin{cases}
-
\dfrac{2}{(2k-1)^2\pi^2},
&\ n=2k-1,
\\
0
&\ n=2k,
\end{cases}
\quad
k=1,2,3,\dotsc.
\end{aligned}$
"""
# ╔═╡ a94cb318-c3e9-4285-af58-154d6955f2d5
md"""
#### 4. Dirichelet Kernel
Suppose $f(x)\in\mathcal{L}$ and $f(x)\sim\displaystyle\sum_{n=-\infty}^\infty c_ne^{2\pi i nx}$. Our basic problems are the following.
- Q1. Does the formal series $\displaystyle\sum_{n=-\infty}^\infty c_ne^{2\pi i nx}$ converge?
- Q2. If the formal series $\displaystyle\sum_{n=-\infty}^\infty c_ne^{2\pi i nx}$ converges, $f(x)=\displaystyle\sum_{n=-\infty}^\infty c_ne^{2\pi i nx}$ holds?
We introduce the partial $N$-the sum of the series
$S_N(s):=\sum_{n=-N}^{n=N}c_ne^{2\pi i nx}.$
We have
$S_N(x)
=
\int_0^1D_N(x-y)f(y)dy
=
\int_{-1/2}^{1/2}D_N(t)f(x+t)dt,$
$D_N(t)
=
\sum_{n=-N}^{n=N}
e^{2\pi i nt}
=
1+
2\sum_{n=1}^N
\cos(2\pi n x)$
by the definition of the Fourier coefficients. $D_N(t)$ is called the $N$-th Dirichelet kernel. $D_N(t)$ is $1$-periodic smooth function and
$\int_0^1D_N(t)dt=1.$
Moreover we obtain
$D_N(t)
=
\begin{cases}
\dfrac{\sin\bigl(\pi(2N+1)t\bigr)}{\sin(\pi t)},
&\ t\not\in\mathbb{Z},
\\
2N+1,
&\ t\in\mathbb{Z}.
\end{cases}$
This expression is useful to study the convergence and divergence of Fourier series. Here we observe the behavior of the Dirichelet kernel in a one-period interval $[-1/2,1/2]$. Roughly speaking
- The mass is concentrating on an interval $I_N:=[-1/(2N+1),1/(2N+1)]$ as $N\rightarrow\infty$.
- $D_N(t)$ oscillates more violently in $[-1/2,1/2]\setminus{I_N}=[-1/2,-1/(2N+1))\cup(1/(2N+1),1/2]$ as $N\rightarrow\infty$.
"""
# ╔═╡ 3edf319a-48e4-48f0-82ab-f81e5f2c581c
begin
M0=100;
t = range(-0.6, 0.6, length = 301);
S0 = ones(M0+1,301);
for m=2:M0+1
for k=1:301
S0[m,k]=S0[m-1,k]+2*cos(2*pi*(m-1)*t[k]);
end
end
end
# ╔═╡ a1aa2ce7-db42-44d2-a9d8-4ae67976f76f
md"""
$N$ = $(@bind N0 Slider(0:M0, show_value=true))
"""
# ╔═╡ cceffb37-cb1f-4436-aab6-17f325504276
begin
plot(t,S0[N0+1,:],
grid=false,
linewidth=2,
ylim=(-M0/2,2*M0+M0/10),
title="Dirichelet Kernel \$D_N(t)\$",
xticks = ([-0.5 0 0.5;], [-0.5,0,0.5]),
yticks = ([0 100 200;], [0 100 200]),
xlabel="t",
label=false,
legend=:false)
end
# ╔═╡ 897a6954-9e77-41d8-a88d-d43b4c9902c6
md"""
#### 5. Fourier Series of Periodic Continuous Functions
We have the following results on the convergence and divergence of the Fourier series of continuous function.
1. Suppose that $f(x)$ is $1$-periodic Hoelder continuous of degree $\alpha\in(0,1]$, that is, there exists a constant $L>0$ such that $\lvert{f(x)-f(y)}\rvert \leqq L\lvert{x-y}\rvert^\alpha$ for any $x,y\in\mathbb{R}$. Then
$\max_{x\in[0,1]}\lvert{S_N(x)-f(x)}\rvert \rightarrow 0 \quad (N\rightarrow\infty).$
2. Moreover if $\alpha>1/2$, then
$\sum_{n=-\infty}^\infty\lvert{c_n}\rvert<\infty.$
3. There exists a is -periodic continuous function $f(x)$ such that
$S_N(0) \rightarrow \infty \quad (N\rightarrow\infty).$
Here we have some remarks on Hoelder continuity. The condition $\lvert{f(x)-f(y)}\rvert \leqq L\lvert{x-y}\rvert^\alpha$ is a restriction only for small $\lvert{x-y}\rvert$ since the absolute value of a periodic continuous function has a maximum. Roughly speaking, the exponent $\alpha$ expresses that $f(x)$ is differentiable of order $\alpha$. When $\alpha=1$, the Hoelder continuity is said to be the Lipshitz continuity. The Rademach theorem shows that the Lipshitz continuous function is differentiable almost everywhere with respect to the Lebesgue measure on $\mathbb{R}$. Roughly speaking, Part 1 and Part 3 assert that if $f(x)$ is a little bit smoother than continuous functions, its Fourier series uniformly converges to , and otherwise, its Fourier series does not necessarily converge even pointwisely.
We show the outline of the proof of Part 1. Note that $S_N(x)-f(x)$ can be written as
$S_N(x)-f(x)
=
\int_{-1/2}^{1/2}
D_N(t)\{f(x+t)-f(x)\}
dt.$
The Hoelder condition implies that for any small $\delta>0$
$S_N(x)-f(x)
=
\int_{\lvert{t}\rvert<\delta}
\mathcal{O}(\lvert{t}\rvert^{-1+\alpha})
dt
+
\int_{\delta<\lvert{t}\rvert<1/2}
\sin\bigl(\pi(2N+1)t\bigr)
\times\dotsb
dt.$
The second term of the right hand side is vanishing as $N\rightarrow\infty$ due to the oscillation and $\displaystyle\int_0^1\sin(2\pi t)dt=0$. Indeed for any $\varphi(t) \in C^1[0,1]$,
$\begin{aligned}
\int_0^1\sin(2\pi Nt)\varphi(t)dt
& =
\left[-\frac{\cos(2\pi Nt)\varphi(t)}{2\pi N}\right]_0^1
+
\int_0^1\frac{\cos(2\pi Nt)\varphi^\prime(t)}{2\pi N}dt
\\
& =
\mathcal{O}(N^{-1})
\quad
(N\rightarrow\infty).
\end{aligned}$
The differentiability of is not required for this. In fact one can also prove
$\int_0^1\sin(2\pi Nt)\varphi(t)dt \rightarrow 0 \quad (N\rightarrow\infty)$
for $\varphi(t) \in C[0,1]$ by using the uniform continuity of $\varphi(t)$ and $\displaystyle\int_0^1\sin(2\pi t)dt=0$. So we have for any small $\delta>0$
$S_N(x)-f(x)
=\mathcal{O}(\delta^\alpha)+o(1)
\quad
(N\rightarrow\infty).$
"""
# ╔═╡ e956146c-d9f1-4c0f-8422-32c29e6d5b69
md"""
#### 6. Fourier Series of Triangular Function
Consider a $1$-periodic function defined by
$f(x)
:=
\begin{cases}
x, &\ x\in[0,1/2),
\\
1-x, &\ x\in[1/2,1).
\end{cases}$
This is the same as the example in Section 3. Here we observe the uniform convergence of the Fourier series of $f(x)$, which is
$\begin{aligned}
f(x)
& =
\frac{1}{4}
-
\sum_{k=1}^\infty
\frac{2}{(2k-1)^2\pi^2}
\cos\bigl(2(2k-1)\pi x\bigr),
\\
S_{2K-1}[f](x)
& =
\frac{1}{4}
-
\sum_{k=1}^K
\frac{2}{(2k-1)^2\pi^2}
\cos\bigl(2(2k-1)\pi x\bigr).
\end{aligned}$
"""
# ╔═╡ b13742b2-45ca-42ee-bdcd-649b036da15f
begin
M1=20;
x = range(-0.1, 1.1, length = 481);
f = zeros(481);
for l=1:481
f[l] = min(x[l]-Float64(floor(x[l])),1-x[l]-Float64(floor(1-x[l])));
end
S1=ones(M1+1,481)/4;
for k=2:M1+1
for l=1:481
S1[k,l]=S1[k-1,l]-2*cos(2*(2*k-3)*pi*x[l])/(2*k-3)^2/pi^2;
end
end
end
# ╔═╡ c05b1f88-2750-4f76-8af0-10091651289a
md"""
$K$ = $(@bind N1 Slider(0:M1, show_value=true))
"""
# ╔═╡ cb7d861a-8d69-4e08-a69d-7638de638e3f
begin
plot(x,S1[N1+1,:],
grid=false,
linewidth=2,
xlim=(-0.15,1.15),
ylim=(-1/16,9/16),
title="Triangular Function and its Fourier Series",
xticks = ([0 1/2 1;], [0,1/2,1]),
yticks = ([0 1/2;], [0,1/2]),
xlabel="\$x\$",
label="\$S_{2K-1}[f](x)\$",
legend=:topright,
legendfont=font(12))
plot!(x,f,
linewidth=2,
label="\$f(x)\$")
end
# ╔═╡ 729497d1-2a1e-4fd3-bef4-fd3280ffd673
md"""
#### 7. A continuous funtion whose fourier series does not converges even pointwisely.
Define a function
$f(x)
=
\sum_{k=1}^\infty
\frac{2}{3^k}
\sin\{2\pi(2k+1)n(k)x\}
\sum_{l=1}^{n(k)}
\frac{\sin(2\pi lx)}{l},$
$n(k)=3^{3^k},
\quad\text{i.e.,}\quad
\log{n(k)}=3^k\log{3},$
which converges uniformly on $\mathbb{R}$, and is a $1$-periodic continuous function.
Consider its Fourier series and the patrial sum
$f(x) \sim \sum_{n=-\infty}^\infty C_ne^{2\pi nx},
\quad
S_N(x):=\sum_{n=-N}^N C_ne^{2\pi nx}.$
It is well-known that the sequence $\{S_N(0)\}$ does not converge, more precisely, we have
$S_{(2k+1)n(k)}(0)-S_{2kn(k)}(0)
=
\frac{1}{3^k}\sum_{j=1}^{n(k)-1}\frac{1}{j}
>
\log{3}.$
We tried to see the graph of $f$ by using
$f_K(x)
:=
\sum_{k=1}^K
\frac{2}{3^k}
\sin\{2\pi(2k+1)n(k)x\}
\sum_{l=1}^{n(k)}
\frac{\sin(2\pi lx)}{l}.$
Unfortunately, we could not do it well since
$n(1)=9, \quad n(2)=19683, \quad n(3)=7625597484987.$
We could compute $f_2$, and not $f_3$, and show the graph of $f_2$ below.
"""
# ╔═╡ adf3292f-4b05-4779-a316-dfe9662c055a
begin
x5 = range(-0.6, 0.6, length = 101);
f5=zeros(length(x5))
for p=1:length(x5)
for k=1:2
g5=zeros(length(x5),3^(3^k))
for l=1:3^(3^k)
g5[p,l] += sin(2*pi*l*x5[p])
end
f5[p] += 2/3^k*sin(2*pi*(2*k+1)*3^(3^k)*x5[p])*g5[p,3^(3^k)]
end
end
end
# ╔═╡ 9956a3d2-9ae9-4ef4-9f1c-55064001a025
begin
plot(x5,f5,
grid=false,
linewidth=2,
xlim=(-0.6,0.6),
title="The continuous function \$f_2\$",
xticks = ([-0.5 0 0.5;], [-0.5,0,0.5]),
yticks = ([-1/2 0 1/2;], [-1/2,0,1/2]),
xlabel="\$x\$",
legend=false,
legendfont=font(12))
end
# ╔═╡ 596f1b0f-7a83-4f48-9316-17ef15d88cbe
md"""
#### 8. Step Function and Sawtooth Function
Let $Y(x)$ be the heaviside function, that is,
$Y(x)
=
\begin{cases}
1, &\ x\geqq0,
\\
0, &\ x<0.
\end{cases}$
The value $Y(0)=1$ does not matter essentially, and is not needed to be defined. Consider a step function $g(x)$ and a sawtooth function $h(x)$ defined by
$g(x)
:=
\sum_{n=-\infty}^\infty
Y(x+n) \times Y(1/2-x-n),
\quad
h(x):=x-[x].$
They are $1$-periodic function such that for $x\in[0,1)$
$g(x)
=
\begin{cases}
1, &\ x\in[0,1/2],
\\
0, &\ x\in(1/2,1),
\end{cases}
\quad
h(x)=x.$
Their Fourier series are
$\begin{aligned}
g(x)
& \sim
\frac{1}{2}
+
\sum_{k=1}^\infty
\frac{2}{(2k-1)\pi}
\sin\bigl(2(2k-1)\pi x\bigr),
\\
S_{2K-1}[g](x)
& =
\frac{1}{2}
+
\sum_{k=1}^K
\frac{2}{(2k-1)\pi}
\sin\bigl(2(2k-1)\pi x\bigr),
\\
h(x)
& \sim
\frac{1}{2}
-
\sum_{n=1}^\infty
\frac{1}{n\pi}
\sin(2\pi nx),
\\
S_N[h](x)
& =
\frac{1}{2}
-
\sum_{n=1}^N
\frac{1}{n\pi}
\sin(2\pi nx).
\end{aligned}$
On one hand, at the discontinuous points
$\begin{aligned}
S_{2K-1}[g](k)
=
\frac{1}{2}
& \rightarrow
\frac{1}{2}
=
\frac{g(k-0)+g(k+0)}{2}
\quad
(K\rightarrow\infty),
\\
S_{2K-1}[g](k+1/2)
=
\frac{1}{2}
& \rightarrow
\frac{1}{2}
=
\frac{g(k+1/2-0)+g(k+1/2+0)}{2}
\quad
(K\rightarrow\infty),
\\
S_N[h](k)
=
\frac{1}{2}
& \rightarrow
\frac{1}{2}
=
\frac{h(k-0)+g(h+0)}{2}
\quad
(N\rightarrow\infty)
\end{aligned}$
for all $k\in\mathbb{Z}$. On the other hand, we can prove that for any small $\delta>0$
$\begin{aligned}
\max_{x\in[\delta,1/2-\delta]\cup[1/2+\delta,1-\delta]}
\lvert{S_{2K-1}[g](x)-g(x)}\rvert
& \rightarrow
0
\quad
(K\rightarrow\infty),
\\
\max_{x\in[\delta,1-\delta]}
\lvert{S_N[h](x)-h(x)}\rvert
& \rightarrow
0
\quad
(N\rightarrow\infty).
\end{aligned}$
The partial sums oscillate violately as $N$ increases near the discontinuous points. This is called the Gibbs Phenomenon.
"""
# ╔═╡ 1bdd1071-c4a0-474a-a394-cd5ff77d5481
begin
M2=80;
g = zeros(481)
for l=41:241
g[l] = 1;
end
for l=441:481
g[l]=1;
end
S2=ones(M2+1,481)/2;
for k=2:M2+1
for l=1:481
S2[k,l]=S2[k-1,l]+2*sin(2*(2*k-3)*pi*x[l])/(2*k-3)/pi;
end
end
end
# ╔═╡ e4f95f78-cd34-4ce6-96f4-65c0151c55cc
md"""
$K$ = $(@bind N2 Slider(0:M2, show_value=true))
"""
# ╔═╡ 2c0a572e-1da4-40cb-a5d4-ff510175d7fb
begin
plot(x,S2[N2+1,:],
grid=false,
linewidth=2,
xlim=(-0.15,1.15),
ylim=(-1/8,9/8),
title="Step Function and its Fourier Series",
xticks = ([0 1/2 1;], [0,1/2,1]),
yticks = ([0 1/2 1;], [0,1/2,1]),
xlabel="\$x\$",
label="\$S_{2K-1}[g](x)\$",
legend=:topright,
legendfont=font(12))
plot!(x,g,
linewidth=2,
label="\$g(x)\$")
end
# ╔═╡ 83ee20aa-e518-442b-af61-d1473d2d3d1a
begin
h = zeros(481);
for l=1:481
h[l]=x[l]-Float64(floor(x[l]));
end
S3=ones(M2+1,481)/2;
for k=2:M2+1
for l=1:481
S3[k,l]=S3[k-1,l]-sin(2*(k-1)*pi*x[l])/(k-1)/pi;
end
end
end
# ╔═╡ 7cabd643-b904-416f-9382-7a4703e19b22
md"""
$N$= $(@bind N3 Slider(0:M2, show_value=true))
"""
# ╔═╡ 36c46073-1425-43fc-93e8-fea1b2e1f192
begin
plot(x,S3[N3+1,:],
grid=false,
linewidth=2,
xlim=(-0.15,1.15),
ylim=(-1/8,9/8),
title="Sawtooth Function and its Fourier Series",
xticks = ([0 1/2 1;], [0,1/2,1]),
yticks = ([0 1/2 1;], [0,1/2,1]),
xlabel="\$x\$",
label="\$S_N[h](x)\$",
legend=:top,
legendfont=font(12))
plot!(x,h,
linewidth=2,
label="\$h(x)\$")
end
# ╔═╡ 47454abd-5b71-465e-bb2a-a4e3c544d350
md"""
#### 9. Decomposition of Piecewise Smooth Functions
Finally we consider piecewise smooth $1$-periodic functions $f(x)$ on $\mathbb{R}$, that is,
- $f(x+1)=f(x)$ for all $x\in\mathbb{R}$.
- There exist numbers $0=a_0<a_1<\dotsb<a_m=1$ such that $f(x)$ is continuously differentiable on each open interval $(a_{j-1},a_j$, $j=1,\dotsc,m$, and limits exist:
$f(a_0+0), \quad f(a_1-0), \quad f(a_1+0), \quad \dotsc \quad f(a_m-0),$
$f^\prime(a_0+0), \quad f^\prime(a_1-0), \quad f^\prime(a_1+0), \quad \dotsc \quad f^\prime(a_m-0).$
We remark that if we restrict on each closed interval $[a_{j-1}+k,a_j+k]$ for $j=1,\dotsc,m$ and $k\in\mathbb{Z}$, $f(x)$ can be regarded as a continuously differentiable function. We can split $f(x)$ into a Lipshitz continuous function, some step functions, and a sawtooth function. We shall illustrate this for a simplest example.
Let $f(x)$ be a piecewise smooth $1$-periodic functions on $\mathbb{R}$ with discontinuities at most $0,c,1$ in the interval $[0,1]$ with some $c\in(0,1)$. Note that $f(0\pm0)=f(1\pm0)$. We denote by $\chi_{[c,1]}(x)$ the characteristic function of the interval $[c,1]$. We define $f_0(x)$, $f_1(x)$, and $f_2(x)$ by
$\begin{aligned}
f_0(x)
& :=
f(x)-f_1(x)-f_2(x),
\\
f_1(x)
& :=
\bigl(f(c+0)-f(c-0)\bigr)\chi_{[c,1]}(x),
\\
f_2(x)
& :=
-
\bigl\{
\bigl(f(0+0)-f(0-0)\bigr)
+
\bigl(f(c+0)-f(c-0)\bigr)
\bigr\}
h(x).
\end{aligned}$
Then $f_0(x)$ is Lipshitz continuous. So the piecewise smooth function $f(x)$ is splitted into the Lipshitz function part $f_0(x)$, the step function part $f_1(x)$, and the sawtooth function part $f_2(x)$. From the view point of Fourier series, $f_0(x)$ is harmless, and $f_1(x)+f_2(x)$ contains discontinuities where the Gibbs phenomenon occurs.
We illustrate this decomposition visually.
"""
# ╔═╡ 252f9cc5-5c34-49f1-96a7-bf5108f30fbd
begin
Z=100*ones(481);
f0=sin.(2*pi*x);
f1=(ones(481)-g)/2;
f2=h/3;
F=f0+f1+f2;
plot(x,F,
grid=false,
linewidth=2,
xlim=(-0.15,1.15),
ylim=(-1.1,1.7),
title="An example of Piecewise Smooth Function",
xticks = ([0 1/2 1;], [0,"\$c\$",1]),
xlabel="\$x\$",
label="\$f(x)\$",
legend=:topright,
legendfont=font(12))
end
# ╔═╡ d8503bba-e3f3-4f9b-ac4e-bc4f1ffd7fbf
begin
plot(x,F,
grid=false,
linewidth=2,
xlim=(-0.15,1.15),
ylim=(-1.1,1.7),
title="Decomposition of Piecewise Smooth Function",
xticks = ([0 1/2 1;], [0,"\$c\$",1]),
xlabel="\$x\$",
label="\$f(x)\$",
legend=:topright,
legendfont=font(12))
plot!(x,Z,
linewidth=2,
label=:false)
plot!(x,Z,
linewidth=2,
label=:false)
plot!(x,Z,
linewidth=2,
label=:false)
plot!(x,f0,
linewidth=2,
label="\$f_0(x)=f(x)-f_1(x)-f_2(x)\$")
plot!(x,f1+f2,
linewidth=2,
label="\$f_1(x)+f_2(x)\$")
end
# ╔═╡ d51cfe76-e1a3-4894-a2f5-43949ece5892
begin
plot(x,F,
grid=false,
linewidth=2,
xlim=(-0.15,1.15),
ylim=(-1.1,1.7),
title="How to resolve discontinuity at \$x=c\$",
xticks = ([0 1/2 1;], [0,"\$c\$",1]),
xlabel="\$x\$",
label="\$f(x)\$",
legend=:topright,
legendfont=font(12))
plot!(x,f1,
linewidth=2,
label="\$f_1(x)\$")
end
# ╔═╡ 692f012c-ec6d-4a2e-b76e-e87cda3155fb
begin
plot(x,F,
grid=false,
linewidth=2,
xlim=(-0.15,1.15),
ylim=(-1.1,1.7),
title="Discontinuity at \$x=c\$ is resolved",
xticks = ([0 1/2 1;], [0,"\$c\$",1]),
xlabel="\$x\$",
label="\$f(x)\$",
legend=:topright,
legendfont=font(12))
plot!(x,Z,
linewidth=2,
label=:false)
plot!(x,F-f1,
linewidth=2,
label="\$f(x)-f_1(x)\$")
end
# ╔═╡ d9e2f9f3-b162-46fd-abde-9a1797f20d3a
begin
plot(x,Z,
grid=false,
linewidth=2,
xlim=(-0.15,1.15),
ylim=(-1.1,1.7),
title="How to resolve discontinuity at \$x=0\$ mod \$1\$",
xticks = ([0 1/2 1;], [0,"c",1]),
xlabel="\$x\$",
label=:false,
legend=:topright,
legendfont=font(12))
plot!(x,Z,
linewidth=2,
label=:false)
plot!(x,F-f1,
linewidth=2,
label="\$f(x)-f_1(x)\$")
plot!(x,f2,
linewidth=2,
label="\$f_2(x)\$")
end
# ╔═╡ a24d7900-ecb0-4a42-bc1e-785b182fe677
begin
plot(x,Z,
grid=false,
linewidth=2,
xlim=(-0.15,1.15),
ylim=(-1.1,1.7),
title="Discontinuity at \$x=0\$ mod \$1\$ is resolved",
xticks = ([0 1/2 1;], [0,"\$c\$",1]),
xlabel="\$x\$",
label=:false,
legend=:topright,
legendfont=font(12))
plot!(x,Z,
linewidth=2,
label=:false)
plot!(x,F-f1,
linewidth=2,
label="\$f(x)-f_1(x)\$")
plot!(x,Z,
linewidth=2,
label=:false)
plot!(x,f0,
linewidth=2,
label="\$f_0(x)=f(x)-f_1(x)-f_2(x)\$")
end
# ╔═╡ ed6e4c4d-a686-4271-b964-0fe31c0361be
md"""
#### 10. Weyl's equidistribution theorem