NotebookDirectory[]

The heat equation with the Dirichlet boundary conditions

Few solutions of the heat equation with the Dirichlet boundary conditions

Using the method of separation of variables we found “few” solutions of the heat equation with the Dirichlet boundary conditions:

((∂u)/(∂t))=κ(((∂^2)u)/(∂(x^2)))  on   {(x,t) : 0≤x ≤L, t ≥0}

subject to

BCs  u(0,t) =0, u(L,t) =0

These few solutions are

Exp[-κ (((((n π)/L)))^2)t]* Sin[((n π)/L)x]

where  n  is any positive integer.

Illustrate in Mathematica

FullSimplify[
D[Exp[-κ (((((n π)/L)))^2)t]* Sin[((n π)/L)x],t]-κ  D[Exp[-κ (((((n π)/L)))^2)t]* Sin[((n π)/L)x],{x,2}]]

FullSimplify[(Exp[-κ (((((n π)/L)))^2)t]* Sin[((n π)/L)x])/.{x->{0,L}},n∈Integers]

From these few soluting we get many solutions by using the superposition principle:  for arbitrary constants (Subscript[b, n]) the linear combination

u(x,t) =(∑_(n=1)^nn) (Subscript[b, n ])Exp[-κ (((((n π)/L)))^2)t]* Sin[((n π)/L)x]

is also a solution.

To satisfy the initial condition  u(x,0) = f(x)  we will need to find (Subscript[b, n]) such that

f (x)  =(∑_(n=1)^nn) (Subscript[b, n ])Sin[((n π)/L)x]

The idea is to use the orthogonality of  the functions

Sin[((n π)/L)x]

FullSimplify[Integrate[Sin[((n Pi)/L)x]Sin[((m Pi)/L)x],x]]

FullSimplify[Integrate[Sin[((n Pi)/L)x]Sin[((m Pi)/L)x],{x,0,L}]]

FullSimplify[Integrate[Sin[((n Pi)/L)x]Sin[((m Pi)/L)x],{x,0,L}],And[n∈Integers,m∈Integers]]

The above calculation is clearly wrong when n=m

FullSimplify[Integrate[Sin[((n Pi)/L)x]Sin[((n Pi)/L)x],{x,0,L}],And[n∈Integers]]

The orthogonality of the first ten Sin functions is nicely seen from the table below:

MatrixForm[Table[Integrate[Sin[((n Pi)/L)x]Sin[((m Pi)/L)x],{x,0,L}],{n,1,10},{m,1,10}]]

With L= π we have

Plot[
Evaluate[Table[Sin[((n Pi x)/Pi)],{n,1,10}]],
{x,0,Pi},FrameTicks->{Range[-Pi,3 Pi,(Pi/2)],Range[-2,2],{},{}},Frame->True,PlotRange->{-1.1,1.1}]

Manipulate[Plot[Evaluate[Sin[n x]],{x,0,Pi},FrameTicks->{Range[-Pi,3 Pi,(Pi/2)],Range[-2,2],{},{}},Frame->True,PlotRange->{-1.1,1.1}],{{n,1},Range[1,10]},ControlType->Setter]

Using the orthogonality we calculate that a good candidate for approximation of  f(x) is

f (x)  ∼ (∑_(n=1)^nn) (Subscript[b, n ])Sin[((n π)/L)x]

where

(Subscript[b, n ])=(2/L)((∫_0)^L)f(x) Sin[((n π)/L)x]dx

We will explore these approximations below.

Symbolic calculation of the solution

Example 1

Clear[nn,ff,LL]; nn=20;LL=1; ff[x_]=x (((x-1))^2);

Plot[Evaluate[{ff[x]}
],{x,0,LL},PlotStyle->{{Blue,Thickness[0.01]},{Red,Thickness[0.005]}},Frame->True,PlotRange->{-.02,.17}]

Calculate the coefficients symbolically.

Clear[bb]; 

bb[n_]=(2/LL)Integrate[ff[s] Sin[((n Pi)/LL) s],{s,0,LL}]

nn=3;

(* nn stands for the number of terms that we use to approximate ff *)

Plot[Evaluate[{ff[x],Sum[bb[n] Sin[((n Pi)/LL) x],{n,1,nn}]}
],{x,0,LL},PlotStyle->{{Blue,Thickness[0.01]},{Red,Thickness[0.005]}},Frame->True,PlotRange->{-.02,.17}]

Manipulate[Plot[Evaluate[{ff[x],Sum[bb[n] Sin[((n Pi)/LL) x],{n,1,jj}]}
],{x,0,LL},PlotStyle->{{Blue,Thickness[0.01]},{Red,Thickness[0.005]}},Frame->True,PlotRange->{-.02,.17}],{{jj,5},Range[1,10]},ControlType->Setter]

nn=10;Plot3D[Evaluate[{Sum[bb[n] Exp[-(((((n Pi)/LL)))^2) t] Sin[((n Pi)/LL) x],{n,1,nn}]}
],{x,0,LL},{t,0,.2},PlotRange->{-0.01,.16}]

Clear[t,Movie1]; 
Movie1[t_]:=
 Plot[Evaluate[{Sum[bb[n] Exp[-(((((n Pi)/LL)))^2)t] Sin[((n Pi)/LL) x],{n,1,nn}]}
],{x,0,LL},PlotRange->{-0.01,.16}]

ListAnimate[Table[Movie1[t],{t,0,.5,.01}],AnimationRunning->False,AnimationRepetitions->2]

Example 2

Clear[nn,ff,LL]; nn=20;LL=1; ff[x_]=5(Sqrt[x]) (((1-x))^4);

Plot[ff[x],{x,0,LL}]

Calculate the coefficients symbolically. If this does not work do it numerically

Clear[bb]; 

bb[n_]=FullSimplify[(2/LL)Integrate[ff[s] Sin[((n Pi)/LL) s],{s,0,LL}]]

nn=50; (* increasing nn improves accuracy *)

Plot[Evaluate[{ff[x],Sum[N[bb[n]] Sin[((n Pi)/LL) x],{n,1,nn}]}
],{x,0,LL},PlotStyle->{{Blue,Thickness[0.01]},{Red,Thickness[0.005]}},Frame->True,PlotRange->{-.2,1.2}]

Plot3D[Evaluate[{Sum[N[bb[n]] Exp[-(((((n Pi)/LL)))^2) t] Sin[((n Pi)/LL) x],{n,1,nn}]}
],{x,0,LL},{t,0,.1},PlotRange->{-0.01,1.2}]

Clear[t,Movie2];

Movie2[t_]:=Plot[Evaluate[{Sum[N[bb[n]] Exp[-(((((n Pi)/LL)))^2)t] Sin[((n Pi)/LL) x],{n,1,nn}]}
],{x,0,LL},PlotRange->{-0.01,1.2}];

ListAnimate[Table[Movie2[t],{t,0,1,.01}],AnimationRunning->False,AnimationRepetitions->2]

Example 3

Clear[nn,ff,LL]; nn=20;LL=Pi; ff[x_]=UnitStep[(Pi/2)-x];

Plot[ff[x],{x,0,LL}]

Calculate the coefficients symbolically. If this does not work do it numerically.

Clear[bb]; 

bb[n_]=(2/LL)Integrate[ff[s] Sin[((n Pi)/LL) s],{s,0,LL}]

nn=50;
Plot[Evaluate[{ff[x],Sum[bb[n] Sin[((n Pi)/LL) x],{n,1,nn}]}
],{x,0,LL},PlotStyle->{{Blue,Thickness[0.01]},{Red,Thickness[0.005]}},Frame->True,PlotRange->{-.2,1.4}]

Plot3D[Evaluate[{Sum[bb[n] Exp[-(((((n Pi)/LL)))^2) t] Sin[((n Pi)/LL) x],{n,1,nn}]}
],{x,0,LL},{t,0,1},PlotRange->{-0.2,1.25}]

Clear[t,Movie3];
Movie3[t_]:=Plot[Evaluate[{Sum[bb[n] Exp[-(((((n Pi)/LL)))^2)t] Sin[n x],{n,1,nn}]}
],{x,0,LL},PlotRange->{-0.2,1.3}]

ListAnimate[Table[Movie3[t],{t,0,1,.01}],AnimationRunning->False,AnimationRepetitions->2]

Example 4

Clear[nn,ff,LL]; nn=7;LL=Pi; ff[x_]=((Sin[x])^7);

Calculate the coefficients symbolically.

Clear[bb]; 

bb[n_]=(2/LL)Integrate[ff[s] Sin[((n Pi)/LL) s],{s,0,LL}]

There are problems with this formula!

bb[3]

Factor[Denominator[bb[n]]]

bbl=Table[Limit[bb[n],n-> k],{k,1,12,1}]

The same numbers would have been obtained if we calculate

Table[(2/LL)Integrate[ff[s] Sin[((n Pi)/LL) s],{s,0,LL}],{n,1,12}]

Thus in this case we have an exact solution if we use seven terms in the expansion of  ff[x].

nn=7;
Plot[Evaluate[{ff[x],Sum[bbl[[n]] Sin[((n Pi)/LL) x],{n,1,nn}]}
],{x,0,LL},PlotStyle->{{Blue,Thickness[0.01]},{Red,Thickness[0.005]}},Frame->True,PlotRange->{-.2,1.1}]

In fact we have the exact formula for ff in this case

FullSimplify[ff[x]==Sum[bbl[[n]] Sin[((n Pi)/LL) x],{n,1,nn}]]

Plot3D[Evaluate[{Sum[bbl[[n]] Exp[-(((((n Pi)/LL)))^2) t] Sin[((n Pi)/LL) x],{n,1,nn}]}
],{x,0,LL},{t,0,1},PlotRange->{-0.2,1.1}]

Clear[t,Movie4];
Movie4[t_]:=Plot[Evaluate[{Sum[bbl[[n]] Exp[-(((((n Pi)/LL)))^2)t] Sin[n x],{n,1,nn}]}
],{x,0,LL},PlotRange->{-0.1,1.1}]

ListAnimate[Table[Movie4[t],{t,0,1,.01}],AnimationRunning->False,AnimationRepetitions->2]

Numeric calculation of the solution

Example 1n

Clear[mm,gg,LL]; mm=20;LL=Pi; gg[x_]=((Sin[x])^(1/2));

Calculate the coefficients symbolically.

bb[n_]=(2/LL)Integrate[gg[s] Sin[((n Pi)/LL) s],{s,0,LL},Assumptions->And[n∈Integers,n>0]]

bb[5]

Chop[N[bb[4.999999999999]]]

The above formula is useless. We better do numerical integration.

Clear[bbl];

bbl=Chop[Table[(2/LL)NIntegrate[
gg[s] Sin[((n Pi)/LL) s],
{s,0,LL},
Method->{Automatic},MaxRecursion->200,AccuracyGoal->12,PrecisionGoal->16],{n,1,mm}]]

mm=20;
Plot[Evaluate[{gg[x],Sum[bbl[[n]] Sin[((n Pi)/LL) x],{n,1,mm}]}
],{x,0,LL},PlotStyle->{{Blue,Thickness[0.01]},{Red,Thickness[0.005]}},Frame->True,PlotRange->{-.2,1.15}]

Plot3D[Evaluate[{Sum[bbl[[n]] Exp[-(((((n Pi)/LL)))^2) t] Sin[((n Pi)/LL) x],{n,1,mm}]}
],{x,0,LL},{t,0,2},PlotRange->{-0.1,1.1}]

Clear[t,Movie1n];

Movie1n[t_]:=Plot[Evaluate[{Sum[bbl[[n]] Exp[-(((((n Pi)/LL)))^2) t] Sin[((n Pi)/LL) x],{n,1,mm}]}
],{x,0,LL},PlotRange->{-0.1,1.1}]

ListAnimate[Table[Movie1n[t],{t,0,2,.05}],AnimationRunning->False,AnimationRepetitions->2]

Example 2n

Clear[mm,gg,LL]; mm=20;LL=Pi; gg[x_]=((Sin[x])^(1/10));

Calculate the coefficients numerically.

Clear[bbl];

bbl=Chop[Table[(2/LL)NIntegrate[gg[s] Sin[((n Pi)/LL) s],{s,0,LL},Method->{Automatic},MaxRecursion->200,AccuracyGoal->12,PrecisionGoal->16],{n,1,mm,1}]]

Plot[Evaluate[{gg[x],Sum[bbl[[n]] Sin[((n Pi)/LL) x],{n,1,mm}]}
],{x,-0.,LL},PlotStyle->{{Blue,Thickness[0.01]},{Red,Thickness[0.005]}},Frame->True,PlotRange->{{-0.1,LL+.1},{-.2,1.25}},Exclusions->None,PlotPoints->400]

Plot3D[Evaluate[{Sum[bbl[[n]] Exp[-(((((n Pi)/LL)))^2) t] Sin[((n Pi)/LL) x],{n,1,mm}]}
],{x,0,LL},{t,0,2},PlotRange->{-0.1,1.15},PlotPoints->200]

Clear[t,Movie2n];

Movie2n[t_]:=Plot[Evaluate[{Sum[bbl[[n]] Exp[-(((((n Pi)/LL)))^2) t] Sin[((n Pi)/LL) x],{n,1,mm}]}
],{x,0,LL},PlotRange->{-0.1,1.1}]

ListAnimate[Table[Movie2n[t],{t,0,2,.05}],AnimationRunning->False,AnimationRepetitions->2]

The heat equation with the Neumann boundary conditions

Few solutions of the heat equation with the Neumann boundary conditions

Using the method of separation of variables we found “few” solutions of the heat equation with the Neumann boundary conditions:

((∂u)/(∂t))=κ(((∂^2)u)/(∂(x^2)))  on   {(x,t) : 0≤x ≤L, t ≥0}

subject to

BCs  ((∂u)/(∂x))(0,t) =0, ((∂u)/(∂x))(L,t) =0

These few solutions are

1

and

Exp[-κ (((((n π)/L)))^2)t]* Cos[((n π)/L)x]

where  n  is any positive integer.  From these few soluting we get many solutions by using the superposition principle:  for arbitrary constants (Subscript[a, n]) the linear combination

u(x,t) =(Subscript[a, 0])+(∑_(n=1)^nn) (Subscript[a, n ])Exp[-κ (((((n π)/L)))^2)t]* Cos[((n π)/L)x]

is also a solution.

To satisfy the initial condition  u(x,0) = f(x)  we will need to find (Subscript[a, n]) such that

f (x)  =(Subscript[a, 0])+(∑_(n=1)^nn) (Subscript[a, n ])Cos[((n π)/L)x]

The idea is to use the orthogonality of  the functions

Cos[((n π)/L)x]

Clear[L];FullSimplify[Integrate[Cos[((n Pi)/L)x]Cos[((m Pi)/L)x],x]]

Clear[L];FullSimplify[Integrate[Cos[((n Pi)/L)x]Cos[((m Pi)/L)x],{x,0,L}]]

Clear[L];FullSimplify[Integrate[Cos[((n Pi)/L)x]Cos[((m Pi)/L)x],{x,0,L}],And[n∈Integers,m∈Integers]]

The above calculation is clearly wrong when n=m

Clear[L]; FullSimplify[Integrate[Cos[((n Pi)/L)x]Cos[((n Pi)/L)x],{x,0,L}],And[n∈Integers]]

The orthogonality of the first ten Cos functions and the constant is nicely seen from the table below:

MatrixForm[Table[Integrate[Cos[((n Pi)/L)x]Cos[((m Pi)/L)x],{x,0,L}],{n,0,10},{m,0,10}]]

With L= π we have

Plot[
Evaluate[Table[Cos[((n Pi x)/Pi)],{n,0,10}]],
{x,0,Pi},FrameTicks->{Range[-Pi,3 Pi,(Pi/2)],Range[-2,2],{},{}},Frame->True,PlotRange->{-1.1,1.1}]

Manipulate[Plot[Evaluate[Cos[n x]],{x,0,Pi},FrameTicks->{Range[-Pi,3 Pi,(Pi/2)],Range[-2,2],{},{}},Frame->True,PlotRange->{-1.1,1.1}],{{n,1},Range[0,10]},ControlType->Setter]

Using the orthogonality we calculate that a good candidate for approximation of  f(x) is

f (x)  ∼(Subscript[a, 0]) +(∑_(n=1)^nn) (Subscript[a, n ])Cos[((n π)/L)x]

where

(Subscript[a, 0 ])=(1/L)((∫_0)^L)f(x) dx ,  (Subscript[a, n ])=(2/L)((∫_0)^L)f(x) Cos[((n π)/L)x]dx, n > 0.

We will explore these approximations below.

Symbolic calculation of the solution

Example 1

Clear[nn,ff,LL]; nn=20;LL=1; ff[x_]=(x^2) (((x-2))^2);

Plot[Evaluate[{ff[x]}
],{x,0,LL},PlotStyle->{{Blue,Thickness[0.01]},{Red,Thickness[0.005]}},Frame->True,PlotRange->{-.02,1.2}]

Calculate the coefficients symbolically.

Clear[aa]; 

aa[0]=(1/LL)Integrate[ff[s],{s,0,LL}];

aa[n_]=(2/LL)Integrate[ff[s] Cos[((n Pi)/LL) s],{s,0,LL}]

nn=7;

(* nn stands for the number of terms that we use to approximate ff *)

Plot[Evaluate[{ff[x],Sum[aa[n] Cos[((n Pi)/LL) x],{n,0,nn}]}
],{x,0,LL},PlotStyle->{{Blue,Thickness[0.01]},{Red,Thickness[0.005]}},Frame->True,PlotRange->{-.02,1.2}]

Plot3D[Evaluate[{Sum[aa[n] Exp[-(((((n Pi)/LL)))^2) t] Cos[((n Pi)/LL) x],{n,0,nn}]}
],{x,0,LL},{t,0,.2},PlotRange->{-0.01,1.2}]

Clear[t,Movie1N]; 
Movie1N[t_]:=
 Plot[Evaluate[{Sum[aa[n] Exp[-(((((n Pi)/LL)))^2)t] Cos[((n Pi)/LL) x],{n,0,nn}]}
],{x,0,LL},PlotRange->{-0.01,1.2}]

ListAnimate[Table[Movie1N[t],{t,0,.2,.005}],AnimationRunning->False,AnimationRepetitions->2]

Numeric calculation of the solution

Example 1n

Clear[mm,gg,LL]; mm=20;LL=Pi; gg[x_]=(((((Cos[x/2])^8)))^(1/3));

Plot[Evaluate[{gg[x]}
],{x,0,LL},PlotStyle->{{Blue,Thickness[0.01]},{Red,Thickness[0.005]}},Frame->True,PlotRange->{-.2,1.15}]

Clear[aal];

aal=Chop[Prepend[Table[(2/LL)NIntegrate[
gg[s] Cos[((n Pi)/LL) s],
{s,0,LL},
Method->{Automatic},MaxRecursion->200,AccuracyGoal->12,PrecisionGoal->16],{n,1,mm}],
(1/LL)NIntegrate[
gg[s],
{s,0,LL},
Method->{Automatic},MaxRecursion->200,AccuracyGoal->12,PrecisionGoal->16]]]

Length[aal]

Plot[Evaluate[{gg[x],Sum[aal[[n+1]] Cos[((n Pi)/LL) x],{n,0,Length[aal]-1}]}
],{x,0,LL},PlotStyle->{{Blue,Thickness[0.01]},{Red,Thickness[0.005]}},Frame->True,PlotRange->{-.2,1.15}]

Plot3D[Evaluate[{Sum[aal[[n+1]] Exp[-(((((n Pi)/LL)))^2) t] Cos[((n Pi)/LL) x],{n,0,Length[aal]-1}]}
],{x,0,LL},{t,0,3},PlotRange->{-0.1,1.1}]

Clear[t,Movie1nN];

Movie1nN[t_]:=Plot[Evaluate[{Sum[aal[[n+1]] Exp[-(((((n Pi)/LL)))^2) t] Cos[((n Pi)/LL) x],{n,0,Length[aal]-1}]}
],{x,0,LL},PlotRange->{-0.1,1.1}]

ListAnimate[Table[Movie1nN[t],{t,0,3,.05}],AnimationRunning->False,AnimationRepetitions->2]

The heat equation with the periodic  boundary conditions

Few solutions of the heat equation with the periodic boundary conditions

Using the method of separation of variables we found “few” solutions of the heat equation with the periodic boundary conditions:

((∂u)/(∂t))=κ(((∂^2)u)/(∂(x^2)))  on   {(x,t) : -L≤x ≤L, t ≥0}

subject to

BCs:  u(-L,t) =u(L,t) ,  ((∂u)/(∂x))(-L,t) =((∂u)/(∂x))(L,t)

These few solutions are

1

and

Exp[-κ (((((n π)/L)))^2)t]* Cos[((n π)/L)x]

and

Exp[-κ (((((n π)/L)))^2)t]* Sin[((n π)/L)x]

where  n  is any positive integer.  From these few soluting we get many solutions by using the superposition principle:  for arbitrary constants (Subscript[b, n]) the linear combination

u(x,t) =(Subscript[a, 0])+(∑_(n=1)^nn) (Subscript[a, n ])Exp[-κ (((((n π)/L)))^2)t]* Cos[((n π)/L)x] + (∑_(n=1)^nn) (Subscript[b, n ])Exp[-κ (((((n π)/L)))^2)t]* Sin[((n π)/L)x]

is also a solution.

To satisfy the initial condition  u(x,0) = f(x)  we will need to find (Subscript[a, n])s and (Subscript[b, n])s such that

f (x)  =(Subscript[a, 0])+(∑_(n=1)^nn) (Subscript[a, n ])Cos[((n π)/L)x]+(∑_(n=1)^nn) (Subscript[b, n ])Sin[((n π)/L)x]

The idea is to use the orthogonality of  the functions

1

and

Cos[((n π)/L)x]

and

Sin[((n π)/L)x]

on the interval  [-L,L].

Clear[L];FullSimplify[Integrate[Cos[((n Pi)/L)x]Cos[((m Pi)/L)x],{x,-L,L}]]

Clear[L];FullSimplify[Integrate[Cos[((n Pi)/L)x]Cos[((m Pi)/L)x],{x,-L,L}],And[n∈Integers,m∈Integers]]

The above calculation is clearly wrong when n=m

Clear[L]; FullSimplify[Integrate[Cos[((n Pi)/L)x]Cos[((n Pi)/L)x],{x,-L,L}],And[n∈Integers]]

Similarly

Clear[L];FullSimplify[Integrate[Sin[((n Pi)/L)x]Sin[((m Pi)/L)x],{x,-L,L}],And[n∈Integers,m∈Integers]]

The above calculation is clearly wrong when n=m

Clear[L]; FullSimplify[Integrate[Sin[((n Pi)/L)x]Sin[((n Pi)/L)x],{x,-L,L}],And[n∈Integers]]

and finally

Clear[L];FullSimplify[Integrate[Cos[((n Pi)/L)x]Sin[((m Pi)/L)x],{x,-L,L}],And[n∈Integers,m∈Integers]]

The orthogonality of the first ten Cos functions and the constant is nicely seen from the table below:

CoSiFunT=Join[Table[Cos[((n π)/L)x],{n,0,5}],Table[Sin[((n π)/L)x],{n,1,5}]]

MatrixForm[Table[Integrate[CoSiFunT[[j]] CoSiFunT[[k]],{x,-L,L}],{j,1,Length[CoSiFunT]},{k,1,Length[CoSiFunT]}]
]

Using the orthogonality we calculate that a good candidate for approximation of  f(x) is

f (x)  ∼(Subscript[a, 0]) +(∑_(n=1)^nn) (Subscript[a, n ])Cos[((n π)/L)x]+(∑_(n=1)^nn) (Subscript[b, n ])Sin[((n π)/L)x]

where

(Subscript[a, 0 ])=(1/(2L))((∫_(-L))^L)f(x) dx ,  (Subscript[a, n ])=(1/L)((∫_0)^L)f(x) Cos[((n π)/L)x]dx, (Subscript[b, n ])=(1/L)((∫_(-L))^L)f(x) Sin[((n π)/L)x]dx, n > 0.

We will explore these approximations below.

Symbolic calculation of the solution

Example 1

Clear[nn,ff,LL]; nn=20;LL=1; ff[x_]=((x^2)-1)(3x-1)+1;

Plot[Evaluate[{ff[x]}
],{x,-LL,LL},PlotStyle->{{Blue,Thickness[0.01]},{Red,Thickness[0.005]}},Frame->True,PlotRange->{0,3}]

Calculate the coefficients symbolically.

Clear[aa]; 

aa[0]=(1/(2 LL))Integrate[ff[s],{s,-LL,LL}];

aa[n_]=(1/LL)Integrate[ff[s] Cos[((n Pi)/LL) s],{s,-LL,LL}];

bb[n_]=(1/LL)Integrate[ff[s] Sin[((n Pi)/LL) s],{s,-LL,LL}]

nn=7;

(* nn stands for the number of terms that we use to approximate ff *)

Plot[Evaluate[{ff[x],Sum[aa[n] Cos[((n Pi)/LL) x],{n,0,nn}]+Sum[bb[n] Sin[((n Pi)/LL) x],{n,1,nn}]}
],{x,-LL,LL},PlotStyle->{{Blue,Thickness[0.01]},{Red,Thickness[0.005]}},Frame->True,PlotRange->{0,3}]

Plot3D[Evaluate[{Sum[aa[n] Exp[-(((((n Pi)/LL)))^2) t] Cos[((n Pi)/LL) x],{n,0,nn}]+Sum[bb[n] Exp[-(((((n Pi)/LL)))^2) t] Sin[((n Pi)/LL) x],{n,1,nn}]}
],{x,-LL,LL},{t,0,.5},PlotRange->{0,3}]

Clear[t,Movie1P]; 
Movie1P[t_]:=
 Plot[Evaluate[{Sum[aa[n] Exp[-(((((n Pi)/LL)))^2)t] Cos[((n Pi)/LL) x],{n,0,nn}]+Sum[bb[n] Exp[-(((((n Pi)/LL)))^2)t] Sin[((n Pi)/LL) x],{n,1,nn}]}
],{x,-LL,LL},PlotRange->{0,3}]

ListAnimate[Table[Movie1P[t],{t,0,1,.005}],AnimationRunning->False,AnimationRepetitions->2]

Numeric calculation of the solution

Example 1p

Clear[mm,gg,LL]; mm=10;LL=1; gg[x_]=((((-Sinh[1]x+Cosh[1])Exp[x]))^(3/2));

gg[-1]==gg[1]

Plot[Evaluate[{gg[x]}
],{x,-LL,LL},PlotStyle->{{Blue,Thickness[0.01]},{Red,Thickness[0.005]}},Frame->True,PlotRange->{0,2.3}]

Try symbolic integration

(* (1/LL)Integrate[
gg[s] Cos[((n Pi)/LL) s],
{s,-LL,LL}] *)

Clear[aal];

aal=Chop[Prepend[Table[(1/LL)NIntegrate[
gg[s] Cos[((n Pi)/LL) s],
{s,-LL,LL},
Method->{Automatic},MaxRecursion->200,AccuracyGoal->12,PrecisionGoal->16],{n,1,mm}],
(1/(2LL))NIntegrate[
gg[s],
{s,-LL,LL},
Method->{Automatic},MaxRecursion->200,AccuracyGoal->12,PrecisionGoal->16]]]

Length[aal]

bbl=Chop[Table[(1/LL)NIntegrate[
gg[s] Sin[((n Pi)/LL) s],
{s,-LL,LL},
Method->{Automatic},MaxRecursion->200,AccuracyGoal->12,PrecisionGoal->16],{n,1,mm}]]

Plot[Evaluate[{gg[x],Sum[aal[[n+1]] Cos[((n Pi)/LL) x],{n,0,Length[aal]-1}]+Sum[bbl[[n]] Sin[((n Pi)/LL) x],{n,1,Length[bbl]}]}
],{x,-LL,LL},PlotStyle->{{Blue,Thickness[0.01]},{Red,Thickness[0.005]}},Frame->True,PlotRange->{0,2.3}]

Plot3D[Evaluate[{Sum[aal[[n+1]] Exp[-(((((n Pi)/LL)))^2) t] Cos[((n Pi)/LL) x],{n,0,Length[aal]-1}]+Sum[bbl[[n]] Exp[-(((((n Pi)/LL)))^2) t] Sin[((n Pi)/LL) x],{n,1,Length[bbl]}]}
],{x,-LL,LL},{t,0,.2},PlotRange->{0.8,2.2}]

Clear[t,Movie1nN];

Movie1nP[t_]:=Plot[Evaluate[{Sum[aal[[n+1]] Exp[-(((((n Pi)/LL)))^2) t] Cos[((n Pi)/LL) x],{n,0,Length[aal]-1}]+Sum[bbl[[n]] Exp[-(((((n Pi)/LL)))^2) t] Sin[((n Pi)/LL) x],{n,1,Length[bbl]}]}
],{x,-LL,LL},PlotRange->{0.8,2.2}]

ListAnimate[Table[Movie1nP[t],{t,0,.5,.01}],AnimationRunning->False,AnimationRepetitions->2]