Fourier Series HW 1

For f[x]=x

Compute the first 4 coefficients in the Fourier Sine Series for f on the interval (0,π).

Superimpose plots of f on (0,π) and the truncated Fourier Sine Series with 4, 8, 12 terms on (-2π,2π). Explain what happens outside the interval (0,π).

Plot the relative error for your three truncated Fourier Sine Series on (-π,π).  Explain any interesting features

Fourier Series HW 2

For f[x]=Abs[x]

Compute the first 4 non-zero coefficients in the Fourier Series for f on the interval (-π/2,π/2).

Superimpose plots of f on (0,π) and the truncated Fourier Series with 5, 9, 13 non-zero terms on (-2π,2π). Explain what happens outside the interval (-π/2,π/2).  Explain why  some terms are automatically zero.

Plot the relative error for your three truncated Fourier Series on (-π/2,π/2).  Explain any interesting features.

Plot the derivatives of your truncated Fourier Series on (-2π, 2π).  What do you think is happening here?

Fourier Bessel Series HW 1

For f[x]=(x^2)(x-1)

Compute the first 4 coefficients in the Fourier Bessel (with n=1) Series for f on the interval (0,1).

Plot f and the truncated Fourier Bessel Series with 4, 8, and 12 non-zero terms on (-0.1,1.1). Explain what happens outside the interval (0,1).

Plot the relative error for your three truncated Fourier Bessel Series on (0,1).  Explain any interesting features.

Plot the derivatives of your truncated Fourier Bessel Series on (0, 1).  What do you think is happening here?

Design a system of Bessel functions to approximate a function that is zero at x=0 and flat at x=1 on (0,1). Explain your reasoning. Use your system to approximate 1-(((x-1))^2) and illustrate the results.

Sturm Louiville

The text says that basically all the 1D eigenvalues of a specific but fairly general type are kinda just like the Bessel eval problem.

Analytic Example: 1

Lets make up an example and watch what the SL statements in the book say.

ODE

p[x]:=(((1+x))^2)
q[x]:=1
σ[x]:=1
ϕSol[x_,λ_]=ϕ[x]/.DSolve[ 
D[p[x] ϕ'[x],x]+ q[x] ϕ[x] + λ σ[x] ϕ[x]==0,
ϕ[x],
x
][[1]]//Simplify

Dirichlet Boundary Conditions at x=0 and x=1.

ϕSol[0,λ]==0
ϕSolF[x_,λ_]=Simplify[
ϕSol[x,λ]//.{C[2]->-C[1],C[1]->I}]
ϕSolF[1,1.0]
Plot[{
Re[ϕSolF[1,λ]],
Im[ϕSolF[1,λ]]
},{λ,0, 543},
PlotLegends->"Expressions"]

{λ1,λ2,λ3,λ4}=Chop[λ/.FindRoot[ϕSolF[1,λ]==0, {λ,{20,80,170,350}}]]

Plot[ 
{ϕSolF[x,λ1],ϕSolF[x,λ2],ϕSolF[x,λ3],ϕSolF[x,λ4]},
{x,0,1}]

Plot[ {
ϕSolF[x,λ1] ϕSolF[x,λ2],
 ϕSolF[x,λ1] ϕSolF[x,λ3],
ϕSolF[x,λ2] ϕSolF[x,λ3]
},{x,0,1}]

NIntegrate[ {
ϕSolF[x,λ1] ϕSolF[x,λ2],
 ϕSolF[x,λ1] ϕSolF[x,λ3],
ϕSolF[x,λ2] ϕSolF[x,λ3]
},{x,0,1}]

Numeric Example: 2

Lets make up an example and watch what the SL statements in the book say.

ODE: The problem was that the original σ function 1+(x^4) was growing so fast that it was causing numerical problems I changed the functions around so everything was roughly the same size.  Maybe that was not the only problem.

Clear[p,x,q,σ,ϕ,ϕSol1, ϕSol2,λ]
p[x_]:=(E^(Sin[x]))
q[x_]:=Sin[0.8 ArcTan[x-3] ] 
σ[x_]:=(((x^4)(1.2+Cos[x]))/(1+(x^4)))
{a,b}={4,6}
Plot[ {p[x],q[x],σ[x]},{x,a,b},
PlotLegends->"Expressions"]

Generate two linearly independent solutions of the ODE with λ as a parameter.  IC at x=0.5 is purely for convenience.

Clear[ϕ,x,λ]
(* 0.1 ϕ[a] + ϕ'[a] == 0 *)
(* ϕ'[b] == 0  *)
ϕSol1=ϕ/.ParametricNDSolve[ {
D[p[x] ϕ'[x],x]+ q[x] ϕ[x] + λ σ[x] ϕ[x]==0,
ϕ[5]==0,
ϕ'[5]==1
},
ϕ,
{x,a,b},
{λ}]
ϕSol2=ϕ/.ParametricNDSolve[ {
D[p[x] ϕ'[x],x]+ q[x] ϕ[x] + λ σ[x] ϕ[x]==0,
ϕ[5]==1,
ϕ'[5]==0
},
ϕ,
{x,a,b},
{λ}]

The bigger λ is the more wiggles there are.

λVal=23.1;
Plot[ {ϕSol1[λVal][x],ϕSol2[λVal][x]},{x, a,b},
PlotLegends->Automatic,
PlotPoints->200]

Since the two solutions are Linearly Independent the general solution is
	c1 ϕSol1[λ][x] + c2 ϕSol2[λ][x]
When we plug in our BC we get two linear homeogeneous equations in the two unknowns c1 and c2.  There is a non-trivial solution iff the determinant of the matrix is zero.  So we build the matrix and look for zeros of the determinant.

(* 0.1 ϕ[a] + ϕ'[a] == 0 *)
(* ϕ'[b] == 0  *)
Clear[A, DetA,λ]
A[λ_]:= (({{0.1 ( ϕSol1[λ][a]) +  ϕSol1[λ]'[a], 0.1 ( ϕSol2[λ][a]) +ϕSol2[λ]'[a] }, {ϕSol1[λ]'[b], ϕSol2[λ]'[b]}}))
DetA[λ_]:= Det[A[λ]];
Plot[ DetA[λ], {λ,(10^(-4)), 14},
PlotRange->All,
AxesLabel->{"λ","Det"}]

Lets bracket some roots.

{DetA[0.1],DetA[0.3]}
{DetA[2],DetA[3]}
{DetA[6],DetA[7]}
{DetA[10],DetA[13]}

Note do not use default “Newton” method something goes badly wrong and redefines the function and the functions inside the function. Bug will be reported Thursday.  We get accurate values of the roots.

{λ1,λ2,λ3,λ4}=λ/.{
FindRoot[ 
DetA[λ], {λ, 0.1,0.3},
Method->"Brent"
],
FindRoot[ 
DetA[λ], {λ,2,3},
Method->"Brent",
AccuracyGoal->15
],
FindRoot[ 
DetA[λ], {λ,6,7},
Method->"Brent",
AccuracyGoal->15
],
FindRoot[ 
DetA[λ], {λ,10,13},
Method->"Brent",
AccuracyGoal->15
]
}

The values of the Determinat are small but not zero!

Map[DetA,{λ1,λ2,λ3,λ4}]

Lets look at the functions that results

λVal=λ1;
{{c1,c2}}=NullSpace[ A[λVal]];
Efun1[x_]=c1 ϕSol1[λVal][x]+c2 ϕSol2[λVal][x];
λVal=λ2;
{{c1,c2}}=NullSpace[ A[λVal],
Tolerance->(10^(-9))];
Efun2[x_]=c1 ϕSol1[λVal][x]+c2 ϕSol2[λVal][x];
λVal=λ3;
{{c1,c2}}=NullSpace[ A[λVal],
Tolerance->(10^(-9))];
Efun3[x_]=c1 ϕSol1[λVal][x]+c2 ϕSol2[λVal][x];
λVal=λ4;
{{c1,c2}}=NullSpace[ A[λVal],
Tolerance->(10^(-9))];
Efun4[x_]=c1 ϕSol1[λVal][x]+c2 ϕSol2[λVal][x];

Lets look at the eigenfunctions.

Plot[
{Efun1[x],Efun2[x],Efun3[x],Efun4[x]},
{x, a,b},
PlotLegends->"Expressions"]

Lets look at the product of the eigenfunctions

Plot[
{Efun1[x]Efun2[x],Efun1[x] Efun3[x] , Efun2[x] Efun3[x]},
{x, a,b}]

Lets look at the integrals of the products. This is a little slow because of the NDSolve inside everything.  They are not zero.  No reason why they should be!

NIntegrate[
{Efun1[x]Efun2[x],Efun1[x] Efun3[x] , Efun2[x] Efun3[x]},
{x, a,b}]

The SL theory does imply that the integrals with the weight σ[x] are zero.

Plot[
{σ[x]Efun1[x]Efun2[x],σ[x]Efun1[x] Efun3[x] ,σ[x] Efun2[x] Efun3[x],
σ[x] Efun1[x] Efun4[x],
σ[x] Efun2[x] Efun4[x],
σ[x] Efun3[x] Efun4[x]},
{x, a,b},
PlotRange->All]

NIntegrate[
{σ[x]Efun1[x]Efun2[x],σ[x]Efun1[x] Efun3[x] ,σ[x] Efun2[x] Efun3[x],
σ[x] Efun1[x] Efun4[x],
σ[x] Efun2[x] Efun4[x],
σ[x] Efun3[x] Efun4[x]},
{x, a,b}]