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

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

g[x_]:=Piecewise[{{x,0≤x≤1/2},{1-x,1/2<x≤1}}]

Plot[OddExtension[g,1][x],{x,-3,3},AxesLabel->{"x","y"},Ticks->{Table[{t,t"L"},{t,-3,3,1}],Table[{t/2,t"L/2"},{t,-1,1,1}]}]

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

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

Integrate[x Sin[n π x/L],{x,0,L/2},Assumptions->{n∈Integers}](2/L)

Integrate[(L-x) Sin[n π x/L],{x,L/2,L},Assumptions->{n∈Integers}](2/L)

%+%%//Simplify

u[n_Integer][x_,t_]:=(4L/(π^2))Sum[Exp[-k (j^2)(π^2)t/(L^2)]Sin[j π x/L]Sin[j π/2]/j,{j,1,n}]

u[10][0,t]

u[10][L,t]

DensityPlot[u[25][x,t]/.{k->1,L->1},{x,0,1},{t,0,1},PlotRange->All,PlotTheme->"Detailed"]

ContourPlot[u[50][x,t]/.{k->1,L->1},{x,0,1},{t,0,1},PlotRange->All,PlotTheme->"Detailed"]

Plot[Evaluate[Table[u[100][x,t]/.{k->1,L->1},{t,0.01,1/2,1/10}]],{x,0,1},PlotRange->All,PlotTheme->"Detailed",FrameLabel->{"x","t"},PlotLegends->Table["t = "<>ToString[t],{t,0.01,0.5,0.1}]]

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

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

Example

g[x_]:=Piecewise[{{0,0≤x<π/2},{100,π/2≤x≤π}}]

Integrate[100Cos[n x],{x,π/2,π},Assumptions->{n∈Integers}](2/π)

u[n_Integer][x_,t_]:=50-(200/π)Sum[Exp[-(j^2)t]Cos[j x]Sin[j π/2]/j,{j,1,n}]

DensityPlot[u[50][x,t],{x,0,π},{t,0.01,1},PlotRange->All,FrameTicks->{{Automatic,None},{Table[π k/6,{k,0,6,1}],None}},PlotTheme->"Detailed"]

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

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

ContourPlot[u[50][x,t],{x,0,π},{t,0.01,1},PlotRange->All,PlotTheme->"Detailed"]

Plot[Evaluate[Table[u[100][x,t],{t,0.01,1.01,1/5}]],{x,0,π},PlotRange->All,PlotTheme->"Detailed",FrameLabel->{"x","t"},FrameTicks->{{Automatic,None},{Table[π k/6,{k,0,6,1}],None}},PlotLegends->Table["t = "<>ToString[t],{t,0.01,1.01,0.2}]]

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

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

Example

g[x_]:=A Cos[λ x]+B Sin[λ x]

g'[0]==α g[0]

g'[L]==-β g[L]

%/.B->α A/λ

α Cos[L λ]-λ Sin[L λ]==-β (Cos[L λ]+((α Sin[L λ])/λ))

Plot[{Tan[λ],(α+β)λ/((λ^2)-α β)/.{α->1,β->1}},{λ,0,4π},Exclusions->{Cos[λ]==0,λ==1},ExclusionsStyle->{Directive[Red,Dashed],None},PlotRange->{-5,5},AxesLabel->{"λ","y"},Ticks->{Table[k π/2,{k,0,8,1}],Automatic}]

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

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

FindRoot[Tan[λ]-λ/((λ^2)-1),{λ,1.4}]

FindRoot[Tan[λ]-λ/((λ^2)-1),{λ,π}]

FindRoot[Tan[λ]-λ/((λ^2)-1),{λ,2π}]

FindRoot[Tan[λ]-λ/((λ^2)-1),{λ,3π}]

Example

2Integrate[x Sin[n π x],{x,0,1}]/.{Sin[n π]->0,Cos[n π]->(((-1))^n)}

2Integrate[(x^2) Sin[n π x],{x,0,1}]/.{Sin[n π]->0,Cos[n π]->(((-1))^n)}

2Integrate[(x-(x^2)) Sin[n π x],{x,0,1}]/.{Sin[n π]->0,Cos[n π]->(((-1))^n)}

u[n_Integer][x_,t_]:=10(1+x)+(8/(π^3))Sum[Exp[-5(((2k-1))^2)(π^2)t]Sin[(2k-1)π x]/(((2k-1))^3),{k,1,n}]

Plot[Evaluate[Table[u[10][x,t],{t,0.001,1.001,0.2}]],{x,0,1},PlotTheme->"Scientific"]

Nonhomogeneous Example

Clear[u]

Integrate[(a'[t]+(b'[t]-a'[t])x/L) Sin[n π x/L],{x,0,L}]/.{Cos[n π]->(((-1))^n),Sin[n π]->0}

Simplify[%]

Integrate[Exp[(n^2)(π^2)s]((((-1))^n)Cos[s]-1),{s,0,t}]

b[n_][t_]:=((1-(E^((n^2) (π^2) t)))/((n^2) (π^2)))+(((((-1))^n) (-(n^2) (π^2)+(E^((n^2) (π^2) t)) ((n^2) (π^2) Cos[t]+Sin[t])))/(1+(n^4) (π^4)))

r[x_,t_]:=t+(1-t+Sin[t])x

v2[n_][x_,t_]:=Sum[b[j][t]Exp[-(j^2)(π^2)t]Sin[j π x],{j,1,n}]

u[n_][x_,t_]:=r[x,t]+v2[n][x,t]

u[10][0,t]

u[10][1,t]

u[10][x,0]

DensityPlot[u[20][x,t],{x,0,1},{t,0,2π},FrameLabel->{"x","t"},PlotTheme->"Detailed"]

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

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