I like to know where my notebook resides.

NotebookDirectory[]

Below are the natural modes of vibration of a string with the mass density ρ, with the magnitude of the tensile force (Subscript[T, 0]) and the length lL. We consider two different time parts, cosine and sine:

Clear[NMVC,NMVS,x,t,n,ρ,T0,lL];
NMVC[x_,t_,n_,T0_,ρ_,lL_]:=Sin[((n Pi)/lL) x]Cos[((n Pi (Sqrt[T0]))/((Sqrt[ρ])lL)) t];
NMVS[x_,t_,n_,T0_,ρ_,lL_]:=Sin[((n Pi)/lL) x]Sin[((n Pi (Sqrt[T0]))/((Sqrt[ρ])lL)) t]

Test the functions defined above:

NMVC[x,t,1,1,1,Pi]

NMVS[x,t,1,1,1,Pi]

To display the time nicely, I need to understand the command which controls the display of decimal numbers.

?NumberForm

NumberForm[N[Pi],{10,9}]

Clear[T0,lL,tc];Manipulate[
Which[tc=="cos",
Plot[
Evaluate[NMVC[x,t,n,T0,ρ,lL]],{x,0,lL},
PlotStyle->{{Blue,Thickness[0.005]}},
Epilog->{RGBColor[0,0,.5],PointSize[0.01],Point[{0,0}],Point[{lL,0}]},
PlotRange->{{-0.03,2.03},{-1.1,1.1}},
PlotLabel->TableForm[
{"time","=",
NumberForm[N[t],{5,3},NumberPadding->{" ","0"}]},
TableDirections-> Row,TableAlignments->{Left,Left,Right},TableSpacing->{0.5,.3}],

Frame->True,AspectRatio->1/4,ImageSize->600
],
tc=="sin",Plot[
Evaluate[NMVS[x,t,n,T0,ρ,lL]],{x,0,lL},
PlotStyle->{{Blue,Thickness[0.005]}},
Epilog->{RGBColor[0,0,.5],PointSize[0.01],Point[{0,0}],Point[{lL,0}]},
PlotRange->{{-0.03,2.03},{-1.1,1.1}},
PlotLabel->TableForm[
{"time","=",
NumberForm[N[t],{5,3},NumberPadding->{" ","0"}]},
TableDirections-> Row,TableAlignments->{Left,Left,Right},TableSpacing->{0.5,.3}],
Frame->True,AspectRatio->1/4,ImageSize->600
]
]
,
{{t,0,"time"},0,8 Pi,N[(Pi/128)]},{{n,1},Range[10],ControlType->Setter},
{{tc,"cos","time component"},{"cos","sin"},ControlType->RadioButton},
{{T0,1},0.1,3,ControlType->VerticalSlider,ControlPlacement->Right},
{{ρ,1},0.1,3,ControlType->VerticalSlider,ControlPlacement->Left},{{lL,1,"length"},0.1,2,ControlType->Slider,ControlPlacement->Bottom},ContinuousAction->True]

Module[{t},t=0;Plot[Evaluate[NMVC[x,t,6,1,1,Pi]],{x,0,Pi},PlotStyle->{{Thickness[0.01],RGBColor[1,0.5,0]}},
Epilog->{
{PointSize[0.012],White,Point[#]&/@{{0,0},{Pi,0}}},
{Text["t =",{Pi/2-0.1,1.26},BaseStyle-> {FontWeight->"Normal",FontColor->RGBColor[1,1,1]}],Text[NumberForm[N[2t],{3,1}],{Pi/2,1.26},BaseStyle-> {FontWeight->"Normal",FontColor->RGBColor[1,1,1]}]}
},
PlotRange->{{-0.1,Pi+0.1},{-1.4,1.4}},AspectRatio->1/5,Frame->True,FrameTicks->{{{},{}},{Range[0,Pi,Pi/4],{}}},Axes->False,ImageSize->600,Background->Black]]

Explore how the command Table[] works with nested tables.

Table[Table[{j,k},{j,1,4}],{k,4,8}]

NMV1=Table[Plot[Evaluate[NMVC[x,t,1,1,1,Pi]],{x,0,Pi},PlotStyle->{{Thickness[0.01],RGBColor[1,0.5,0]}},
Epilog->{
{PointSize[0.012],White,Point[#]&/@{{0,0},{Pi,0}}},
{Text["t =",{Pi/2-0.1,1.26},BaseStyle-> {FontWeight->"Normal",FontColor->RGBColor[1,1,1]}],Text[NumberForm[N[t],{3,1}],{Pi/2,1.26},BaseStyle-> {FontWeight->"Normal",FontColor->RGBColor[1,1,1]}]}
},
PlotRange->{{-0.1,Pi+0.1},{-1.4,1.4}},AspectRatio->1/5,Frame->True,FrameTicks->{{{},{}},{Range[0,Pi,Pi/4],{}}},Axes->False,ImageSize->600,Background->Black],{t,0,2 Pi,0.05}];

Length[NMV1]

NMV1[[1]]

NMVC[x,t,n,1,1,Pi]

NMVtt=Table[Table[Plot[Evaluate[NMVC[x,t,n,1,1,Pi]],{x,0,Pi},PlotStyle->{{Thickness[0.01],RGBColor[1,0.5,0]}},
Epilog->{
{PointSize[0.012],White,Point[#]&/@{{0,0},{Pi,0}}},
{Text["t =",{Pi/2-0.1,1.26},BaseStyle-> {FontWeight->"Normal",FontColor->RGBColor[1,1,1]}],Text[NumberForm[N[t],{3,1}],{Pi/2,1.26},BaseStyle-> {FontWeight->"Normal",FontColor->RGBColor[1,1,1]}]}
},
PlotRange->{{-0.1,Pi+0.1},{-1.4,1.4}},AspectRatio->1/5,Frame->True,FrameTicks->{{{},{}},{Range[0,Pi,Pi/4],{}}},Axes->False,ImageSize->600,Background->Black],{t,0,2 Pi,2Pi/120.}],{n,1,6}];

Length[NMVtt[[2]]]

Show[NMVtt[[2,121]],ImageSize->600]

ListAnimate[Show[#,ImageSize->600]&/@NMV1,ControlPlacement->Top]

Manipulate[ListAnimate[Show[#,ImageSize->600]&/@NMVtt[[n]],AnimationRunning->True,ControlPlacement->Top],{n,Range[1,6]},ControlType->Setter]

I will use the function below as the initial displacement of the string.

Plot[(4/(Pi^2))x (Pi-x)Exp[-5(((x-1))^2)],{x,-1,5},PlotRange->{0,1}]

Since we will take the initial velocity to be zero, we only need the following separated solutions:

NMVC[x,t,n,1,1,Pi]

We will work with the approximation obtained with 50 terms of the corresponding Fourier series which converges uniformly to the initial condition.

Clear[aat]; aat=Table[(2/Pi)NIntegrate[(4/(Pi^2))x (Pi-x)Exp[-5(((x-1))^2)]Sin[n x],{x,0,Pi}],{n,1,50}];

uup[x_,t_]=Sum[aat[[n]]Cos[n t] Sin[n x],{n,1,Length[aat]}];

We obtained a very good approximation, as the plot below shows. The orange function is the given function, and the navy function is the approximation.

Plot[{(4/(Pi^2))x (Pi-x)Exp[-5(((x-1))^2)],Evaluate[uup[x,0]]},{x,0,Pi},PlotStyle->{{Thickness[0.008],RGBColor[1,0.5,0]},{Thickness[0.004],RGBColor[0,0,0.5]}},PlotRange->{0,1}]

Now show vibrations of this string.

Manipulate[Plot[Evaluate[uup[x,t]],{x,0,Pi},PlotStyle->{{Thickness[0.01],RGBColor[1,0.5,0]}},
Epilog->{
{PointSize[0.012],White,Point[#]&/@{{0,0},{Pi,0}}},
{Text["t =",{Pi/2-0.1,1.26},BaseStyle-> {FontWeight->"Normal",FontColor->RGBColor[1,1,1]}],Text[NumberForm[N[t],{4,2}],{Pi/2,1.26},BaseStyle-> {FontWeight->"Normal",FontColor->RGBColor[1,1,1]}]}
},
PlotRange->{{-0.1,Pi+0.1},{-1.4,1.4}},AspectRatio->1/5,Frame->True,FrameTicks->{{{},{}},{Range[0,Pi,Pi/4],{}}},Axes->False,ImageSize->600,Background->Black],{t,0,18.9},ControlPlacement->Top]

uuptt=Table[Plot[Evaluate[uup[x,t]],{x,0,Pi},PlotStyle->{{Thickness[0.01],RGBColor[1,0.5,0]}},
Epilog->{
{PointSize[0.012],White,Point[#]&/@{{0,0},{Pi,0}}},
{Text["t =",{Pi/2-0.1,1.26},BaseStyle-> {FontWeight->"Normal",FontColor->RGBColor[1,1,1]}],Text[NumberForm[N[t],{3,1}],{Pi/2,1.26},BaseStyle-> {FontWeight->"Normal",FontColor->RGBColor[1,1,1]}]}
},
PlotRange->{{-0.1,Pi+0.1},{-1.4,1.4}},AspectRatio->1/5,Frame->True,FrameTicks->{{{},{}},{Range[0,Pi,Pi/4],{}}},Axes->False,ImageSize->800,Background->Black],{t,0,6.4,6.4/240}];

Length[uuptt]

ListAnimate[Show[#,ImageSize->600]&/@uuptt,ControlPlacement->Top]

The commands below is how I make animated gifs in Mathematica. I forst create a table of pictures. Then export those tables as gifs. That creates an animated gifs. The modern browsers can also display animated pngs.

NMVttime=Table[Table[Plot[Evaluate[NMVC[x,t,n,1,1,Pi]],{x,0,Pi},PlotStyle->{{Thickness[0.01],RGBColor[1,0.5,0]}},
Epilog->{
{PointSize[0.012],White,Point[#]&/@{{0,0},{Pi,0}}},
{Text["t =",{Pi/2-0.1,1.26},BaseStyle-> {FontWeight->"Normal",FontColor->RGBColor[1,1,1]}],Text[NumberForm[N[t],{3,1}],{Pi/2,1.26},BaseStyle-> {FontWeight->"Normal",FontColor->RGBColor[1,1,1]}]}
},
PlotRange->{{-0.1,Pi+0.1},{-1.4,1.4}},AspectRatio->1/5,Frame->True,FrameTicks->{{{},{}},{Range[0,Pi,Pi/4],{}}},Axes->False,ImageSize->800,Background->Black],{t,0,2 Pi,2Pi/240.}],{n,1,6}];

Length[NMVttime[[1]]]

dds=0.1&/@Range[Length[NMVttime[[1]]]]; (* duration of each frame that we want*)

NotebookDirectory[]

The commands below are commented out since I do not want them executed whenever I evaluate this notebook. The commands below export the tables created above as animated gifs. I hope I got them reasonable well designed, so until I decide that I can improve them, they will stay commented out.

(* SetDirectory[NotebookDirectory[]] *)

(* Export["NMVttime1s1.gif",NMVttime[[1]][[1]],"ImageSize"->800];Export["NMVttime1.gif",NMVttime[[1]],"AnimationRepetitions"->Infinity,"ImageSize"->800,"DisplayDurations"->dds] ;
  Export["NMVttime2s1.gif",NMVttime[[2]][[1]],"ImageSize"->800];Export["NMVttime2.gif",NMVttime[[2]],"AnimationRepetitions"->Infinity,"ImageSize"->800,"DisplayDurations"->dds] ;
Export["NMVttime3s1.gif",NMVttime[[3]][[1]],"ImageSize"->800];Export["NMVttime3.gif",NMVttime[[3]],"AnimationRepetitions"->Infinity,"ImageSize"->800,"DisplayDurations"->dds] ;
Export["NMVttime4s1.gif",NMVttime[[4]][[1]],"ImageSize"->800];Export["NMVttime4.gif",NMVttime[[4]],"AnimationRepetitions"->Infinity,"ImageSize"->800,"DisplayDurations"->dds] ;
Export["NMVttime5s1.gif",NMVttime[[5]][[1]],"ImageSize"->800];Export["NMVttime5.gif",NMVttime[[5]],"AnimationRepetitions"->Infinity,"ImageSize"->800,"DisplayDurations"->dds] ;
Export["NMVttime6s1.gif",NMVttime[[6]][[1]],"ImageSize"->800];Export["NMVttime6.gif",NMVttime[[6]],"AnimationRepetitions"->Infinity,"ImageSize"->800,"DisplayDurations"->dds]  *)

(* Export["uuptts1.gif",uuptt[[1]],"ImageSize"->800];Export["uupttAni.gif",uuptt,"AnimationRepetitions"->Infinity,"ImageSize"->800,"DisplayDurations"->dds] ; *)