Section 3.4 Problem 6

In class, we found the eigenvalue condition is tan((Sqrt[λ]))=(Sqrt[λ]).  Introducing a new variable θ=(Sqrt[λ])allows us the write this as tan(θ)=θ.  To graphically see solutions, we plot tan(θ) and θ  on the same axes:

Plot[{Tan[θ],θ},{θ,0,10Pi}]

To get a better estimate of the first solution, we can zoom in:

Plot[{Tan[θ],θ},{θ,Pi/2,3Pi/2}]

Now use the FindRoot function to get a numerical approximation of the first solution.  The syntax for FindRoot requires an initial guess for the value of the variable.  In this case, we give an initial guess of 4 for θ.

FindRoot[Tan[θ]==θ,{θ,4}]

Note that the output of the FindRoot function is a list of "replacement rules".  (In this case, there is only one item in the list.) We use this replacement rule to define θ1 with the syntax /. and using % to refer to the previous output.

θ1=θ/.%

An equivalent syntax is Replace[θ, %]

The corresponding eigenfunction is

y1[x_]=Sin[θ1 x]-θ1 Cos[θ1 x]

It's graph is

Plot[y1[x],{x,0,1}]

Now let's take similar steps to get a numerical approximation of the second solution:

Plot[{Tan[θ],θ},{θ,2Pi,5Pi/2}]

FindRoot[Tan[θ]==θ,{θ,7.5}]

θ2=θ/.%

We've argued that the nth solution should be approximately (2n+1)(π/2) for large values of π.  For comparison with θ2, we look at

N[5Pi/2]

y2[x_]=Sin[θ2 x]-θ2 Cos[θ2 x]

Plot[y2[x],{x,0,1}]

We can check that y1 and y2 are orthogonal:

Integrate[y1[x]y2[x],{x,0,1}]

This is effectively zero.  The very small but nonzero result is a consequence of unavoidable computational errors from doing machine precision arithimetic (as opposed to exact arithmetic).

Given a function defined on the interval [0,1], we can compute expansion coefficients:

f[x_]=x

Plot[f[x],{x,0,1}]

y0[x_]=x-1

a0=Integrate[f[x]y0[x],{x,0,1}]/Integrate[y0[x]y0[x],{x,0,1}]

a1=Integrate[f[x]y1[x],{x,0,1}]/Integrate[y1[x]y1[x],{x,0,1}]

a2=Integrate[f[x]y2[x],{x,0,1}]/Integrate[y2[x]y2[x],{x,0,1}]

Plot[{f[x],a0 y0[x]+a1 y1[x]+a2 y2[x]},{x,0,1}]

The fit is not very good because we only have three terms in our expansion.

What follows extends what we did in class to compute more eigenvalues and more expansion coefficients for f(x)=x. I haven't added commentary so some of the syntax may be unfamiliar.  If you are interested in the details, we can talk about this in class.

Table[FindRoot[Tan[θ]==θ,{θ,k Pi/2-0.2}],{k,3,51,2}]

θ=θ/.%

y[x_,n_]:=Sin[θ[[n]]x]-θ[[n]]Cos[θ[[n]]x]

y[x_,0]=x-1

y[x,1]

y[x,10]

Plot[y[x,10],{x,0,1}]

Integrate[y[x,4]*y[x,10],{x,0,1}]

NIntegrate[f[x]*y[x,0],{x,0,1}]/NIntegrate[y[x,0]*y[x,0],{x,0,1}]

a=Table[NIntegrate[f[x]*y[x,n],{x,0,1}]/NIntegrate[y[x,n]*y[x,n],{x,0,1}],{n,0,Length[θ]}]

Sum[a[[n+1]]*y[x,n],{n,0,1}]

Manipulate[Plot[{f[x],Sum[a[[k+1]]*y[x,k],{k,0,n}]},{x,0,1},PlotRange->{0,1.2}],{n,0,Length[a]-1}]