Solving a specific Sturm-Liouville problem

We will solve the following problem:

-y''(x)=λ y(x)

y(0)-y'(0) =0 

y(π) = 0

Negative eigenvalues

Set λ = -(μ^2), with μ > 0

ExpToTrig[DSolve[y''[x]==(μ^2) y[x],y[x],x]]

Thus the general solution is

gsol=C[1] Cosh[x μ]+C[2] Sinh[x μ]

gsol/.{x->0}

D[gsol,x]/.{x->0}

Hence the first boundary condition is

(gsol/.{x->0})-(D[gsol,x]/.{x->0})

The second boundary condition is

(gsol/.{x->Pi})

We need a nontrivial solution for C[1] and C[2] of the system

C[1]-μ C[2] = 0
C[1] Cosh[π μ]+C[2] Sinh[π μ] = 0

The determinant of this system is

Det[{{1,-μ},{Cosh[π μ], Sinh[π μ]}}]

Since the nontrivial solution exixts only when the determinant is 0, we need to find μ-intercepts of the above function

Plot[μ Cosh[π μ]+Sinh[π μ],{μ,0,10},PlotRange->{0,10}]

This function does not have positive μ-intercepts. Thus our problem has no negative eigenvalues.

Zero eigenvalue

DSolve[y''[x]==0,y[x],x]

The general solution is

gsol0=C[1]+x C[2]

gsol0/.{x->0}

D[gsol0,x]/.{x->0}

The first boundary condition is

(gsol0/.{x->0})-(D[gsol0,x]/.{x->0})

The second boundary condition is

(gsol0/.{x->Pi})

Since the determinant

Det[{{1,-1},{1, π}}]

is nonzero the number zero is not an eigenvalue of our problem.

Positive eigenvalues

Set λ = (μ^2), with μ > 0

DSolve[-y''[x]==(μ^2) y[x],y[x],x]

The general solution is

gsolp=C[1] Cos[x μ]+C[2] Sin[x μ]

The first boundary condition is

(gsolp/.{x->0})-(D[gsolp,x]/.{x->0})

The second boundary condition is

(gsolp/.{x->Pi})

The determinant of the system for C[1] and C[2] is

Det[{{1,-μ},{Cos[π μ], Sin[π μ]}}]

The system for C[1] and C[2] has nontrivial solution if and only if the above determinant is 0. Hence we need to find those μ-s for which the above determinant equals 0. Visualy:

Plot[μ Cos[π μ]+Sin[π μ],{μ,0,12},PlotRange->{-10,10},Ticks->{Range[0,12],Automatic}]

Or, we need to find the intersections of the following functions

Plot[{-μ ,((Sin[π μ])/(Cos[π μ]))},{μ,0,12},PlotRange->{-10,10},Ticks->{Range[0,12],Automatic},Exclusions->Range[(1/2),13,1]]

To find approximate solutions for μ we use

FindRoot[μ Cos[π μ]+Sin[π μ]==0,{μ,.7}]

μ/.FindRoot[μ Cos[π μ]+Sin[π μ]==0,{μ,.7}]

Here is the first 13 values for μ placed in a table

mus13=Table[μ/.FindRoot[μ Cos[π μ]+Sin[π μ]==0,{μ,k+.7}],{k,0,12}]

Verify graphically:

Plot[μ Cos[π μ]+Sin[π μ],{μ,0,12},PlotRange->{-10,10},Ticks->{Range[0,12],Automatic},Epilog->{{Red,Point[{#,0}]&/@mus13}}]

Plot[{-μ ,((Sin[π μ])/(Cos[π μ]))},{μ,0,12},PlotRange->{-13,4},Ticks->{Range[0,12],Automatic},Exclusions->Range[(1/2),13,1],Epilog->{{Red,Point[{#,-#}]&/@mus13}}]

These are corresponding 13 eigenfunction

yy[x_,k_]:=1 Cos[x mus13[[k]]]+(1/(mus13[[k]])) Sin[x mus13[[k]]]

Manipulate[Plot[yy[x,k],{x,0,Pi},PlotRange->{-2,2}],{k,Range[13],Setter}]

Now we verify that the distinct eigenfunctions are mutually orthogonal:

MatrixForm[Chop[Table[Integrate[yy[x,j] yy[x,k],{x,0,Pi}],{j,1,13},{k,1,13}]]]

Next we choose a function that we want to approximate with a linear combination of eigenfunctions. We choose a polynomial which satisfies the boundary conditions:

((a+b x)(x-Pi)/.{x->0})-(D[(a+b x)(x-Pi),x]/.{x->0})

Solve[-a-a π+b π==0,b]

{{b->((Pi+Pi π)/π)}}

((Pi+Pi π)/π)

(Pi+(1+Pi) x)(x-Pi)

FullSimplify[((-π+x) (π+(1+π) x)/.{x->0})-(D[(-π+x) (π+(1+π) x),x]/.{x->0})]

ff[x_]:=(-π+x) (π+(1+π) x)

The coefficients in the approximation of ff using a linear combination of eigenfunctions are

aa13=Table[((Integrate[ff[x] yy[x,j],{x,0,Pi}])/(Integrate[ ((yy[x,j])^2),{x,0,Pi}])),{j,1,13}]

Here is the approximation

Appff[x_]=Sum[aa13[[j]] yy[x,j],{j,1,13}]

How good is our approximation?

Plot[{ff[x],Appff[x]},{x,0,Pi},PlotStyle->{{Blue,Thickness[0.01]},{Red,Thickness[0.005]}}]

Now assume that the function ff is the initial shape of a string with appropriate coefficients. Then the oscillations of  this string are well approximated with the function

uu[x_,t_]=Sum[aa13[[j]] yy[x,j] Cos[mus13[[j]] t],{j,1,13}]

Manipulate[Plot[uu[x,t],{x,0,Pi},PlotRange->{{-1.1,Pi+.1},{-20,20}},PlotStyle->{{Blue,Thickness[0.01]}},Axes->False,Frame->True,FrameTicks->{{-1,0,Pi/2,Pi},{},{},{}},AspectRatio->1/5,Epilog->{{Red,Thickness[0.01],Line[{{-1,0},{0,uu[0,t]}}]}},ImageSize->400],{t,0,8.18}]

Let us approximate one more function, again polynomial but with two roots

((a+b x)(x-2)(x-Pi)/.{x->0})-(D[(a+b x)(x-2)(x-Pi),x]/.{x->0})

Solve[2 a+3 a π-2 b π==0,b]

{{b->((2+3 π)/2)}}

(Pi+((2+3 π)/2) x)(x-2)(x-Pi)

FullSimplify[(((Pi+((2+3 π)/2) x)(x-2)(x-Pi))/.{x->0})-(D[(Pi+((2+3 π)/2) x)(x-2)(x-Pi),x]/.{x->0})]

gg[x_]:=(Pi+((2+3 π)/2) x)(x-2)(x-Pi)

The coefficients in the approximation of ff using a linear combination of eigenfunctions are

aa13g=Table[((Integrate[gg[x] yy[x,j],{x,0,Pi}])/(Integrate[ ((yy[x,j])^2),{x,0,Pi}])),{j,1,13}]

Here is the approximation

Appgg[x_]=Sum[aa13g[[j]] yy[x,j],{j,1,13}]

How good is our approximation?

Plot[{gg[x],Appgg[x]},{x,0,Pi},PlotStyle->{{Blue,Thickness[0.01]},{Red,Thickness[0.005]}}]

Now assume that the function gg is the initial shape of a string with appropriate coefficients. Then the oscillations of  this string are well approximated with the function

uug[x_,t_]=Sum[aa13g[[j]] yy[x,j] Cos[mus13[[j]] t],{j,1,13}]

Manipulate[Plot[uug[x,t],{x,0,Pi},PlotRange->{{-1.1,Pi+.1},{-27,27}},PlotStyle->{{Blue,Thickness[0.01]}},Axes->False,Frame->True,FrameTicks->{{-1,0,Pi/2,Pi},{},{},{}},AspectRatio->1/5,Epilog->{{Red,Thickness[0.01],Line[{{-1,0},{0,uug[0,t]}}]}},ImageSize->400],{t,0,15.1}]