SetDirectory[$HomeDirectory<>"/Documents/handouts/math467/IntroWave"]

PeriodicExtension[f_,L_][x_]:=f[Mod[x,2L,-L]]

EvenExtension[f_,L_][x_]:=PeriodicExtension[Piecewise[{{f[#],0≤#≤L},{f[-#],-L≤#≤0}}]&,L][x]

OddExtension[f_,L_][x_]:=PeriodicExtension[Piecewise[{{f[#],0≤#≤L},{-f[-#],-L≤#≤0}}]&,L][x]

Example: Plucked String

f[x_]:=Piecewise[{{2x/5,0≤x≤5/2},{1,5/2<x<15/2},{4-2x/5,15/2≤x≤10}}]

Plot[OddExtension[f,10][x],{x,-20,20},AxesLabel->{"x","(Subscript[f, o])(x)"}]

Export["fodd.pdf",%,"PDF"]

Export["fodd.eps",%%,"EPS"]

fshift3=Plot[{OddExtension[f,10][x+3]/2,OddExtension[f,10][x-3]/2},{x,-20,20},AxesLabel->{"x","(Subscript[f, o])(x)"},PlotRange->{-1,1},PlotPoints->200]

Export["fshift3.pdf",%,"PDF"]

Export["fshift3.eps",%%,"EPS"]

Show[Plot[(OddExtension[f,10][x+3]+OddExtension[f,10][x-3])/2,{x,0,10},AxesLabel->{"x","u(x,t)"},PlotRange->{-1,1},PlotPoints->200,PlotStyle->Directive[Thick,Black]],fshift3]

Export["fsumshift3.pdf",%,"PDF"]

Export["fsumshift3.eps",%%,"EPS"]

Manipulate[Show[Plot[(OddExtension[f,10][x+t]+OddExtension[f,10][x-t])/2,{x,0,10},AxesLabel->{"x","u(x,t)"},PlotPoints->200,PlotStyle->Directive[Thick,Black]],Plot[{OddExtension[f,10][x+t]/2,OddExtension[f,10][x-t]/2},{x,-20,20},AxesLabel->{"x","(Subscript[f, o])(x)"},PlotPoints->200],PlotRange->{{-20,20},{-1,1}}],{t,0,20}]

Example: Struck String

g[s_]:=Piecewise[{{s/5,0≤s≤5},{2-s/5,5<s≤10}}]

G[x_,t_]:=NIntegrate[OddExtension[g,10][s],{s,x-t,x+t}]/2

Plot[{NIntegrate[OddExtension[g,10][s],{s,x-t,x+t}/.{t->0}]/2,NIntegrate[OddExtension[g,10][s],{s,x-t,x+t}/.{t->1}]/2,NIntegrate[OddExtension[g,10][s],{s,x-t,x+t}/.{t->2}]/2,NIntegrate[OddExtension[g,10][s],{s,x-t,x+t}/.{t->3}]/2,NIntegrate[OddExtension[g,10][s],{s,x-t,x+t}/.{t->4}]/2},{x,0,10},AxesLabel->{"x","u(x,t)"},PlotRange->All,PlotLegends->{"u(x,0)","u(x,1)","u(x,2)","u(x,3)","u(x,4)"}]

Export["struck.pdf",%,"PDF"]

Export["struck.eps",%%,"EPS"]

Manipulate[Plot[NIntegrate[OddExtension[g,10][s],{s,x-t,x+t}]/2,{x,0,10},AxesLabel->{"x","u(x,t)"},PlotRange->{-5/2,5/2}],{t,0,20}]

Example 03

Manipulate[Plot[5(Cos[π(x-t)/10]-Cos[π(x+t)/10])/π,{x,0,10},AxesLabel->{"x","u(x,t)"},PlotRange->10{-1,1}/π],{t,0,20}]

Example 04

u[x_,t_]:=Sin[2π x]Cos[2π t]+Sin[π x]Sin[π t]/π

D[u[x,t],t,t]-D[u[x,t],x,x]//Simplify

u[x,0]

D[u[x,t],t]/.t->0

Plot[Evaluate[Table[u[x,t],{t,0,1/2,1/6}]],{x,0,1},AxesLabel->{"x","u(x,t)"},PlotRange->Sqrt[2]{-1,1},PlotLegends->{"u(x,0)","u(x,1/6)","u(x,1/3)","u(x,1/2)"}]

Export["example04.pdf",%,"PDF"]

Export["example04.eps",%%,"EPS"]

Manipulate[Plot[u[x,t],{x,0,1},AxesLabel->{"x","u(x,t)"},PlotRange->Sqrt[2]{-1,1}],{t,0,10}]