DE.09 The Heat Equation 
       \(∂\_{x, 2}temp[x, t] = ∂\_t temp[x, t]\)
and the Wave Equation
       \(\(\ 
      ∂\_{x, 2}position[x, t] = 
        ∂\_{t, 2}position[x, t]\)\)
 BASICS

Needs["Graphics`Colors`"];
Needs["Graphics`FilledPlot`"];

If[MemberQ[{"Global`","Graphics`Common`GraphicsCommon`","Vector3D`"}, 
    Context[ScaleFactor]],Remove["*`ScaleFactor"]];
<<"Graphics`Legend`";
<<"Graphics`Common`GraphicsCommon`";
Remove["*`ScaleFactor"];
Graphics`Colors`GosiaGreen=RGBColor[0, 0.392187, 0];
Off[General::spell];
Off[General::spell1];
Off[ParametricPlot3D::ppcom];
Off[ParametricPlot::ppcom];
Off[Plot::plnr];
Needs["Calculus`Master`"];
Off[Unique::"usym"];
SetOptions[Limit,Analytic->True];

CMView = {2.7, 1.6, 1.2};
Clear[FastFourierfit,Fourierfitters,F,Fvalues,n,k,
      jump,num,numtab,coeffs,t,L];
jump[n_] := jump[n] = N[1/(2 n)];
Fvalues[F_,L_,n_] := 
  N[Table[F[L t],{t,0,1 - jump[n],jump[n]}]];
  

numtab[n_] := numtab[n] = Table[k,{k,1,n}];

Fourierfitters[L_,n_,t_] := Table[E^(2 Pi I k t/L),
          {k,-n + 1,n - 1}];
coeffs[n_,list_] := Join[Reverse[Part[Fourier[list],numtab[n]]],
	Part[InverseFourier[list],Drop[numtab[n],1]]]/
		N[Sqrt[Length[list]]]

FastFourierfit[F_,L_,n_,t_] := 
     Chop[Fourierfitters[L,n,t].coeffs[n,Fvalues[F,L,n]]];    
L:=Expand[a D[#1,{#2,2}] + b D[#1,#2] + c #1]&

Off[Graphics::gpt]

New Vector Drawers

(* :Title:  NewVectorDraw  *)
(* :Author: Bruce Carpenter *)
(* :Summary:  Construct 2 and 3 dimensional vectors,
     arrows, and arrowheads as graphics 
     objects.
*)
(* :Date:  Copyright 1997, Math Everywhere, Inc. 
*)
(*  :Drawbacks:  Since the vectors are drawn out of 
     context, the shapes of the arrowheads are only 
     correct with AspectRatio set to Automatic.
*)
BeginPackage["Vector3D`","Graphics`Colors`"];

Axes3D::usage = "Axes3D[a, b] creates a Graphics3D object of cartesian axes with x, y, and z running from -a/3 to a, and with axes labels b units beyond the tips of the axes.  Axes3D[a] is Axes3D[a, a/8].";

Perpend::usage = "Perpend[a] returns a unit vector which is perpendicular to the vector a.";

Arrow::usage = "Arrow[a] produces a 2 or 3 dimensional vector from the origin to a. Arrow[a, Tail -> tail] gives a vector from tail to a.";
	
Vector::usage = "Vector[a, b] gives a 2D or 3D vector from a to b.";

ArrowHead::usage = "ArrowHead[a, vec] produces an arrowhead with its tip placed at the point a, pointing in the direction of the vector vec.";

Tail::usage = "Tail -> point puts the tail of the vector at point.";

Norm::usage = "Norm[vec] returns the Euclidean length of vec.";

Normalize::usage = "Normalize[vec] returns a unit vector in the direction of vec, provided vec is nonzero.";

Aperture::usage = "Aperture is the ratio of the radius of the base to the length of the head of a vector.";

TipSize::usage = "TipSize specifies an absolute size for the inner tip length of the head of a vector.";

TipRatio::usage = "TipRatio is the ratio of the inner length of the arrowhead to the length of the shaft of a vector.";

HeadRatio::usage = "HeadRatio is the ratio of the outer length of the arrowhead to the length of the shaft of a vector.";

HeadSize::usage = "HeadSize specifies an absolute size for the head of a vector.";

ScaleFactor::usage = "ScaleFactor specifies the amount to scale a vector in length and may be either a number or a pure function.";

ZeroVectorPointSize::usage = "ZeroVectorPointSize is the size of the point used to represent a zero vector.";

Options[Vector] = Options[Arrow] = Options[ArrowHead] =
{HeadRatio -> 0.18, TipRatio -> 0.14, Aperture -> 0.3, ScaleFactor -> 1, HeadType -> Polygon, ShaftQ -> True, EdgesQ -> True, VectorColor -> RGBColor[0,0,1], ShaftWidth -> 0.005, ZeroVectorPointSize -> 0.01};
		
Begin["`Private`"];

SetOptions[ParametricPlot,AspectRatio -> Automatic];
SetOptions[Plot,AspectRatio -> Automatic];
SetOptions[Graphics,AspectRatio -> Automatic];

Axes3D[u_,v_] := 
      Graphics3D[{
            {Blue,Line[{{-u/3,0,0},{u,0,0}}]},
                    Text["x",{u + v,0,0}],
            {Blue,Line[{{0,-u/3,0},{0,u,0}}]},
                    Text["y",{0, u + v,0}],
            {Blue,Line[{{0,0,-u/3},{0,0,u}}]},
                    Text["z",{0,0,u + v}]}]; 
Axes3D[u_] := Axes3D[u,u/8];
				
Norm[a_?VectorQ] := N[Sqrt[a.a]];

Normalize[a_?VectorQ] := If[a.a == 0, a, a/Norm[a]];

Perpend[a_?VectorQ] := Normalize[{a[[2]],-a[[1]]}]/;Length[a]==2
Perpend[a_?VectorQ] := Normalize[If[a[[1]]==0,{1,0,0},{0,a[[3]],-a[[2]]}]]/;Length[a]==3

Base3D = Table[{Cos[2 k Pi/8.], Sin[2 k Pi/8.]},{k,0,8}]; 

Vector[from_?VectorQ, to_?VectorQ, opts___] := Module[
   {sq, sw, ht, hs, hr, tr, ap, sf, vc, zvps, diff = to - from, tip},
   {sq, sw, ht, hs, hr, ts, tr, ap, sf, vc, zvps} = {ShaftQ, ShaftWidth, HeadType, HeadSize, HeadRatio, TipSize, TipRatio, Aperture, ScaleFactor, VectorColor, ZeroVectorPointSize} /. {opts} /. Options[Vector];
   If[from==to, Return[Graphics[{PointSize[zvps],vc,Point[from]}]]];
   diff = If[NumberQ[N[sf]], sf diff, sf[diff]];
   tip = from + diff;
   If[NumberQ[hs], hr = hs/Norm[diff]; tr = 0.75 hr];
   If[NumberQ[ts], tr = ts/Norm[diff]];
   Graphics[{If[sq,{vc,Thickness[sw],Line[{from,tip - tr diff}]},{}],
      With[{trans = ap hr Norm[diff] Perpend[diff]},
      {vc, Thickness[sw], ht[{tip,
                   (tip - hr diff + trans),
                   (tip - tr diff),
                   (tip - hr diff - trans),tip}]}]}]
] /; Length[from]==Length[to]==2

Vector[from_?VectorQ, to_?VectorQ, opts___] := Module[
   {sq, eq, sw, hs, hr, tr,ap, sf, vc, zvps, diff = to - from, tip},
   {sq, eq, sw, hs, hr, ap, sf, vc, zvps} = {ShaftQ, EdgesQ, ShaftWidth, HeadSize, HeadRatio, Aperture, ScaleFactor, VectorColor, ZeroVectorPointSize} /. {opts} /. Options[Vector];
   If[from==to, Return[Graphics3D[{PointSize[zvps],vc,Point[from]}]]];
   diff = If[NumberQ[N[sf]], sf diff, sf[diff]];
   tip = from + diff;
   If[NumberQ[hs], hr = hs/Norm[diff]];
   tr = hr/2;
   Graphics3D[{If[sq,{vc,Thickness[sw],Line[{from,tip-tr diff}]},{}], If[eq, {}, EdgeForm[]], {SurfaceColor[vc],
      With[{temp = Perpend[diff]},
      Polygon[Append[#,tip]]& /@ Partition[(tip - hr diff + #)&/@((ap hr Norm[diff] Base3D) . {temp,Normalize[Cross[temp,diff]]}),2,1]]}}]
] /; Length[from]==Length[to]==3


Arrow[a_, Tail->b_, opts___] := Vector[b,a+b,opts]

Arrow[a_, opts___] := Vector[Table[0,{Length[a]}],a,opts]

ArrowHead[a_, b_, opts___] := Vector[a-b,a,ShaftQ->False,opts];

End[];

EndPackage[];
Null

VectorField and Phase Lines

(*  :Title: VectorAndPhase.m  *)

(*  :Author:  Bill Davis  *)

(*  :Dates:  about March, 1996 *)

(*  :Drawbacks:  I wish someone serious would come and turn these into
                 Really carefully done packages.  *)

BeginPackage["PhaseStuff`","Vector3D`",
		"Utilities`FilterOptions`"];

PhaseLine::usage = "PhaseLine[fcn,{var,a,b},tint,pos]
	makes a vertical phase line for the function, fcn, of the variable, var,
	for the variable going from a to b, with 
	a color given by tint,  at the x-coordinate pos.";
	
PhaseLine3D::usage = "PhaseLIne3D[fcn,{var,a,b},tint,loc]
	makes a vertical phase line for the function, fcn, of the variable, var,
	for the variable going from a to b, with 
	a color given by tint, and base point at loc = {x,y}";
	
VectorField::usage = "VectorField[{function,{var1,a,b,space1},{var2,c,d,space2}]
	will make a vector field of normalized vectors, colored by
	magnitude, for the function of the variables on the
	range {r1,r2} with spacing between points given by 
	{space1, space2}.  If a single function of a single variable is given,
	the vector field {1,f} will be plotted.";
	
StikPikXZ::usage = "StikPikXZ[picture,a:_0] takes a 2 dimensional
	Mathematica picture and embeds it on the XZ plane at y = a.  
	Some optional characteristics of the graphs are lost in the 
	process.  StikPikYZ and StikPikXZ are similar.";
	
StikPikYZ::usage = "StikPikYZ[picture,a:_0] takes a 2 dimensional
	Mathematica picture and embeds it on the XZ plane at y = a.  
	Some optional characteristics of the graphs are lost in the 
	process.  StikPikYZ and StikPikXZ are similar.";
	
StikPikXY::usage = "StikPikXY[picture,a:_0] takes a 2 dimensional
	Mathematica picture and embeds it on the XZ plane at y = a.  
	Some optional characteristics of the graphs are lost in the 
	process.  StikPikYZ and StikPikXZ are similar.";
	
Begin["`Private`"];	

PhaseLine[fcn_,{var_,a_,b_},tint_,pos_:0] := 
	Module[{len,len1,k,zset,zero,zero1,signs,stick,dots,pointers},
	zset = Solve[fcn==0,var];
	zero = If[Length[zset]==0,{},var/.zset];
	zero = Sort[zero];
	zero = Select[zero,((# >= a)&&(# <= b))&];
	zero1 = Sort[Union[zero,{a,b}]];
	len = Length[zero];
	len1 = Length[zero1];
	signs = Table[Sign[fcn/.var->((zero1[[k+1]] + zero1[[k]])/2)],
		{k,1,len1-1}];
	stick = {Thickness[0.007],Line[{{pos,a},{pos,b}}]};
	dots = Point[{pos,#}]&/@zero;
	dots = Join[{PointSize[0.05],tint},dots];
	heads = Table[MakeHead[zero1[[k]],zero1[[k+1]],pos,
		signs[[k]],b-a,tint],{k,1,len1-1}];
	Return[{Graphics[Join[{tint},stick,dots]],heads}]
		]
		
MakeHead[a_,b_,c_,s_,slen_,tint_] := Module[{u,v,w},
	u = Min[2(b-a),3/4 slen];
	Return[ArrowHead[{c,a(.5-s/5)+b(.5+s/5)},
		{0,s u},VectorColor->tint]]]
		
PhaseLine3D[fcn_,{var_,a_,b_},tint_,pos_:{0,0}] := 
	Module[{len,len1,k,zset,zero,zero1,signs,stick,dots,pointers},
	zset = Solve[fcn==0,var];
	zero = If[Length[zset]==0,{},var/.zset];
	zero = Sort[zero];
	zero = Select[zero,((# >= a)&&(# <= b))&];
	zero1 = Sort[Union[zero,{a,b}]];
	len = Length[zero];
	len1 = Length[zero1];
	signs = Table[Sign[fcn/.var->((zero1[[k+1]] + zero1[[k]])/2)],
		{k,1,len1-1}];
	stick = {Thickness[0.007],Line[{{pos[[1]],pos[[2]],a},
		{pos[[1]],pos[[2]],b}}]};
	dots = Point[{pos[[1]],pos[[2]],#}]&/@zero;
	dots = Join[{PointSize[0.03],tint},dots];
	heads = Table[MakeHead3D[zero1[[k]],zero1[[k+1]],pos,
		signs[[k]],b-a,tint],{k,1,len1-1}];
	Return[{Graphics3D[Join[{tint},stick,dots]],heads}]
		]
		
MakeHead3D[a_,b_,c_,s_,slen_,tint_] := Module[{u,v,w},
	u = Min[2(b-a),1/2 slen];
	Return[ArrowHead[{c[[1]],c[[2]],a(.5-s/5)+b(.5+s/5)},
		{0,0,s u},VectorColor->tint]]]
		
		
VectorField[function_List,{var1_,a_,b_,sp1_:1},{var2_,c_,d_,sp2_:1}] := 
	Module[{i,j,U,V,UU,VV,ulow,uhigh,vlow,vhigh,maxval,minval,
		lengths,directions,locations,mlen},
	mlen = Min[sp1,sp2];
	normf[uu_,vv_] = Sqrt[function[[1]]^2+function[[2]]^2]/.
		{var1->uu,var2->vv};
	lengths = Table[N[normf[U,V]],{U,a,b,sp1},{V,c,d,sp2}];
	maxval = Max[lengths]; minval = Min[lengths];
	If[minval == maxval,maxval += 1];
	locations = Table[{uu,vv},{uu,a,b,sp1},
		{vv,c,d,sp2}];
	directions = Table[If[N[normf[U,V]]==0,{0,0},
		mlen (function/.{var1->U,var2->V})/(1.3 N[normf[U,V]])],
			{U,a,b,sp1},{V,c,d,sp2}];
	{UU,VV} = Dimensions[directions][[{1,2}]];
	Return[Table[Arrow[directions[[i,j]],
			Tail->locations[[i,j]],Aperture->1,
			HeadRatio->.4,ShaftWidth->0.008, VectorColor->
			RGBColor[(lengths[[i,j]] - minval)/(maxval-minval),0,
				(maxval -lengths[[i,j]])/(maxval-minval)]],{i,UU},{j,VV}]]
		]
		
VectorField[function_,{var1_,a_,b_,sp1_:1},{var2_,c_,d_,sp2_:1}] :=
	VectorField[{1,function},{var1,a,b,sp1},{var2,c,d,sp2}]
	
	
Needs["Utilities`FilterOptions`"]

FixOptions[a_] := Module[{picture = a, opt3},
If[Options[picture] != {}, 
	opt3 = FilterOptions[Graphics3D,#]&/@Options[picture];
	(* Fix things that might carry 2D characteristics. *)
	opt3 = opt3//. {(AxesLabel -> _) ->(AxesLabel -> None),
			(PlotRange->_) -> (PlotRange->Automatic),
			(PlotRegion -> _) -> (PlotRegion -> Automatic),
			(Ticks -> _) -> (Ticks -> Automatic)};
	picture = Apply[List,picture];
	picture[[-1]] = opt3;
	picture = Apply[Graphics3D,picture]];
	Return[picture]
	]

StikPikXZ[picture_,a_:0] := Module[{PIK3 = picture},
	PIK3 = PIK3//.{Graphics->Graphics3D,
		{u_?NumberQ,v_?NumberQ}:>{u,a,v}};
	PIK3 = FixOptions[PIK3];
	Return[PIK3]
		]


StikPikYZ[picture_,a_:0] := Module[{PIK3 = picture},
	PIK3 = PIK3//.{Graphics->Graphics3D,
		{u_?NumberQ,v_?NumberQ}:>{a,u,v}};
	PIK3 = FixOptions[PIK3];
	Return[PIK3]
		]


StikPikXY[picture_,a_:0] := Module[{PIK3 = picture},
	PIK3 = PIK3//.{Graphics->Graphics3D,
		{u_?NumberQ,v_?NumberQ}:>{u,v,a}};
	PIK3 = FixOptions[PIK3];
	Return[PIK3]
		]
		
End[];

EndPackage[];
Null

ThreeAxes[u,v]

ThreeAxes[u_,v_] := 
      Graphics3D[{
            {Blue,Line[{{-u,0,0},{u,0,0}}]},
                    Text["x",{u + v,0,0}],
            {Blue,Line[{{0,-u,0},{0,u,0}}]},
                    Text["y",{0, u + v,0}],
            {Blue,Line[{{0,0,0},{0,0,u}}]},
                    Text["z",{0,0,u + v}]}]; 
ThreeAxes[u_] := ThreeAxes[u,u/8];
ThreeAxes::usage = "ThreeAxes[a,b] makes a standard cartesian axis graphics object
	with x, y, and z running from -a to a, and with axis
	labels b units beyond the tips of the axes.  ThreeAxes[a]
	is ThreeAxes[a,a/8].";

Crisscross

Clear[x];
crisscross = Plot[{Cos[x],Sin[x]},{x,Pi/8,3 Pi/8},
    PlotStyle->{{RGBColor[1,0,0],Thickness[0.02]}},
    Axes->None,AspectRatio->1/3,
    DisplayFunction->Identity];

Pendulum Stuff

modticksX[gr_Graphics,m_] :=
   Module[{f,x},
     f[{a_,"",st___}] := {a,""};
     f[{a_,b_,st___}] := {a,b m};
     Show[gr,
        AxesOrigin->Reverse[FullOptions[gr,AxesOrigin]],
        Ticks->{Map[f,FullOptions[gr,Ticks][[1]]],
                Automatic}]
]

modticksY[gr_Graphics,m_] :=
   Module[{f,x},
     f[{a_,"",st___}] := {a,""};
     f[{a_,b_,st___}] := {a,b m};
     Show[gr,
        AxesOrigin->Reverse[FullOptions[gr,AxesOrigin]],
        Ticks->{Automatic,
                Map[f,FullOptions[gr,Ticks][[2]]]
               }]
]

Clear[center,angle,length,a,l,pendulum,calibratedpendulum];

pendulum[length_,angle_]:=
Module[
{center:={length Sin[Pi-angle],length Cos[Pi-angle]}},

Show[

Graphics[{Blue,Thickness[.01],
Line[{{0,0},{0,-(length+3)}}]}],

Graphics[{Blue,
Polygon[{{-5,-(length+3)},{-5,-(length+3.5)},{-5.3,-(length+3.5)},
{-5.3,-(length+4)},{5.3,-(length+4)},{5.3,-(length+3.5)},
{5,-(length+3.5)},{5,-(length+3)},{-5,-(length+3)}}]}],

Graphics[{Black,
Disk[{0,0},length,{(-Pi/2+angle-Pi/84),(-Pi/2+angle+Pi/84)}]}],

Graphics[{Black,
Disk[center,length,{(Pi/2+angle-Pi/500),(Pi/2+angle+Pi/500)}]}],

Graphics[{Red,PointSize[.05],Point[{0,0}]}],

Graphics[{Red,
Disk[center,length/5,{0,360 Degree}]}],

Graphics[{GoldenrodLight,
Disk[center,length/6,{330 Degree,350 Degree}]}],

Graphics[{Red,
Disk[center,length/7,{0,360 Degree}]}],

Graphics[{Black,PointSize[.02],Point[center]}],


AspectRatio->Automatic,
PlotRange->{{length+5,-(length+3)},{(length+4),-(length+4)}},
AxesOrigin->{0,0},
DisplayFunction->Identity]
]

calibratedpendulum[length_,angle_]:=
Module[
{center:={length Sin[Pi-angle],length Cos[Pi-angle]}},

Show[

Graphics[{Blue,Thickness[.01],
Line[{{0,0},{0,-(length+3)}}]}],

Graphics[{Blue,
Polygon[{{-5,-(length+3)},{-5,-(length+3.5)},{-5.3,-(length+3.5)},
{-5.3,-(length+4)},{5.3,-(length+4)},{5.3,-(length+3.5)},
{5,-(length+3.5)},{5,-(length+3)},{-5,-(length+3)}}]}],

Graphics[{Black,
Disk[{0,0},length,{(-Pi/2+angle-Pi/84),(-Pi/2+angle+Pi/84)}]}],

Graphics[{Black,
Disk[center,length,{(Pi/2+angle-Pi/500),(Pi/2+angle+Pi/500)}]}],

Graphics[{Red,PointSize[.05],Point[{0,0}]}],

Graphics[{Red,
Disk[center,length/5,{0,360 Degree}]}],

Graphics[{GoldenrodLight,
Disk[center,length/6,{330 Degree,350 Degree}]}],

Graphics[{Red,
Disk[center,length/7,{0,360 Degree}]}],

Graphics[{Black,PointSize[.02],Point[center]}],

Graphics[Text[StringForm["y[t] =  ``",angle],
{8 length/8 Sin[15 Pi/12], 8 length/8 Cos[5Pi/6]}]],

AspectRatio->Automatic,
PlotRange->{{length+5,-(length+3)},{(length+4),-(length+4)}},
AxesOrigin->{0,0},DisplayFunction->Identity]
]

B.1) Rigging f[t] on [0, 2  L] to get a pure sine fit of f[t] on [0, L]

B.1.a)

When you go for a fast Fourier fit of a function on an interval [0,L] you usually get a mixture of both Sines and Cosines:

\(Clear[f, t]; 
f[t_] = t\^2\ E\^\(\(-0.5\)\ t\); 
\(L = 2\ π; 
    \)\)Chop[ComplexExpand[FastFourierfit[f, L, 4, t]]]

But sometimes you get pure Cosines:

\(Clear[f, t]; 
f[t_] = t\ \((t - 1)\)\^2\ \((2 - t)\); 
\(L = 2; 
    \)\)Chop[ComplexExpand[FastFourierfit[f, L, 6, t]]]

Other times you get pure Sines:

\(Clear[f, t]; 
f[t_] = t\ \((1 - t)\)\ \((2 - t)\); 
\(L = 2; \)\)Chop[ComplexExpand[FastFourierfit[f, L, 6, t]]]

The question here is:
How do you recognize when you are going to get a pure Sine fit?

Look at plots of Sin[k 2 Pi/L t] on [0,L] like this:

L = 3; sinplots = 
      Plot[{Sin[(((2 π) t)/L)], Sin[((2 (2 π) t)/L)], 
          Sin[((3 (2 π) t)/L)]}, {t, 0, L}, 
        PlotStyle -> {{Thickness[0.01], DeepPink}}, 
        AxesLabel -> {"t", "Sines"}];

Embellish the plot a bit:

centerline = 
      Graphics[{Blue, Thickness[0.01], Line[{{(L/2), -1}, {(L/2), 1}}]}]; 
    Show[sinplots, centerline];

To the right of the line, each sine plot is the negative mirror image of its plot to the left of the line.

Functions that plot out the same way on [0,L] have fast Fourier fits on [0,L] composed of pure sines. 
Look at the plot of this function f[t] on [0,L] for L = 2:

\(Clear[f, t]; 
f[t_] = t\ \((1 - t)\)\ \((2 - t)\); 
\(L = 2; \)\)fplot = 
      Plot[f[t], {t, 0, L}, PlotStyle -> {{Thickness[0.02], Blue}}, 
        AxesLabel -> {"t", "f[t]"}, 
        Epilog -> {Red, Thickness[0.01], 
            Line[{{(L/2), -1}, {(L/2), 1}}]}];

To the right of the center line, the plot of f[t] is the negative mirror image of its plot to the left of the center line. This is why you can count on the fast Fourier fit of f[t] on [0,L] to come out as a pure Sine fit.
Try it:

Chop[ComplexExpand[FastFourierfit[f, L, 5, t]]]

Chop[ComplexExpand[FastFourierfit[f, L, 10, t]]]

Haw!
If you go with a different L, you'll probably lose the pure Sine fit:

L = Random[Real, {3, 4}]

Chop[ComplexExpand[FastFourierfit[f, L, 3, t]]]

For this L, the pure Sine fit on [0,L] was lost!
If you look at the plot of f[t] on [0,L], then you'll see why:

Plot[f[t], {t, 0, L}, PlotStyle -> {{Thickness[0.02], Blue}}, 
      AxesLabel -> {"t", "f[t]"}, 
      Epilog -> {Red, Thickness[0.01], 
          Line[{{(L/2), -1}, {(L/2), 1}}]}];

For this new L, the plot of f[t] to the right of the center line is NOT the negative mirror image of its plot to the left of the center line. 
This is why the pure Sine fit was lost on [0,L].

B.1.b.i) Rigging f[t] on [0, 2 L] to get a pure Sine fit of f[t] on [0,L]

Look at this:

\(Clear[f, t]; 
f[t_] = t\ Cos[\(π\ t\)\/2]\^2; 
\(L = 3; \)\)fplot = 
      Plot[f[t], {t, 0, L}, PlotStyle -> {{Thickness[0.02], Blue}}, 
        AxesLabel -> {"t", "f[t]"}, 
        Epilog -> {Red, Thickness[0.01], Line[{{(L/2), 0}, {(L/2), 2}}]}];

The plot tells you that that this particular function f[t] has no chance of a pure Sine fit on this particular interval [0,L]. 
Stay with the same L, the same f[t] on [0,L] but rig f[t] on [L, 2 L] as follows:
        riggedf[t] = f[t]  for 0≤ t ≤ L and
        riggedf[t] = f[2 L - t] for L < t ≤  2 L
 and look at some fast Fourier fits of riggedf[t] on [0, 2L]

\(Clear[riggedf, t]; 

    riggedf[t_] := f[t] /; 0 ≤ t ≤ L; 

    \(riggedf[t_] := \(-f[2\ L - t]\) /; L < t ≤ 2\ L; \)\)Chop[ComplexExpand[FastFourierfit[riggedf,2 L,3,t]]]

Chop[ComplexExpand[FastFourierfit[riggedf,2 L,5,t]]]

Chop[ComplexExpand[FastFourierfit[riggedf,2 L,10,t]]]

The fast Fourier fits of riggedf[t] on [0,2 L] are pure Sine fits!
Why did this happen?

Stay with the same L and take a gander at the plot of riggedf[t] on [0, 2 L]:

riggedfplot = 
      Plot[riggedf[t], {t, 0, 2 L}, 
        PlotStyle -> {{Thickness[0.01], Blue}}, PlotRange -> All, 
        AxesLabel -> {"t", "riggedf[t]"}, 
        Epilog -> {Red, 
            Line[{{((2 L)/2), -1}, {((2 L)/2), 1}}]}];

To the right of the center line, the plot of riggedf[t] is the negative mirror image of its plot to the left of the center line. 
This is why you can count on the fast Fourier fit of riggedf[t] on [0,2 L] to come out as a pure Sine fit. 
The purpose of rigging f[t] in this way is to guarantee the pure sine fit on [0, 2 L]
This will work for any L with L > 0 and any function f[t] with f[0] = f[L] = 0:
Try it:

Function 1:

\(Clear[f, t]; 
L = 4; 
\(f[t_] = 6\ t\ \((4 - t)\)\ E\^\(-t\); \)\){f[0], f[L]}

\(Clear[riggedf, t]; 

    riggedf[t_] := f[t] /; 0 ≤ t ≤ L; 

    \(riggedf[t_] := \(-f[2\ L - t]\) /; L < t ≤ 2\ L; \)\)Chop[ComplexExpand[FastFourierfit[riggedf, 2 L, 3, t]]]

Function 2:

\(Clear[f, t]; 
L = 1; 
\(f[t_] = t\^2\ Sin[π\ t]\ Log[1 + t]; 
    \)\){f[0], f[L]}

\(Clear[riggedf, t]; 

    riggedf[t_] := f[t] /; 0 ≤ t ≤ L; 

    \(riggedf[t_] := \(-f[2\ L - t]\) /; L < t ≤ 2\ L; \)\)Chop[ComplexExpand[FastFourierfit[riggedf, 2 L, 8, t]]]

\(Clear[f, t]; 
L = 3; 

    \(f[t_] = \((E\^\(\(-0.3\)\ t\) - 1)\)\ \((t - 3)\)\ Cos[t]; \)\){f[0], f[L]}

\(Clear[riggedf, t]; 

    riggedf[t_] := f[t] /; 0 ≤ t ≤ L; 

    \(riggedf[t_] := \(-f[2\ L - t]\) /; L < t ≤ 2\ L; \)\)Chop[ComplexExpand[FastFourierfit[riggedf, 2 L, 7, t]]]

B.1.b.ii)

Here is the plot of a function f[t] on an interval [0,L]:

\(Clear[f, t]; 
f[t_] = 0.4\ t\ \((t - 4)\)\^2\ E\^\(\(-0.4\)\ t\); 

    \(L = 4; \)\)fplot = 
      Plot[f[t], {t, 0, L}, PlotStyle -> {{Thickness[0.02], Blue}}, 
        AxesLabel -> {"t", "f[t]"}, 
        DisplayFunction -> Identity]; centerline = Graphics[{Red, Line[{{(L/2), 0}, {(L/2), 2}}]}]; Show[fplot, centerline, DisplayFunction -> $DisplayFunction];

Good, f[0] = f[L] = 0:

{f[0], f[L]}

Here's the plot of riggedf[t] on [0,2 L] shown together with the plot of f[t] on [0,L]:

\(Clear[riggedf, t]; 

    riggedf[t_] := f[t] /; 0 ≤ t ≤ L; 

    \(riggedf[t_] := \(-f[2\ L - t]\) /; L < t ≤ 2\ L; \)\)riggedfplot = 
      Plot[riggedf[t], {t, 0, 2 L}, 
        PlotStyle -> {{Thickness[0.008], Red}}, PlotRange -> All, 
        AxesLabel -> {"t", "riggedf[t]"}, 
        DisplayFunction -> Identity]; newcenterline = 
      Graphics[{Red, Line[{{((2 L)/2), -2}, {((2 L)/2), 2}}]}]; 
    all = 
      Show[fplot, riggedfplot, newcenterline, 
        AxesLabel -> {"t", ""}, 
        PlotLabel -> "f[t] and riggedf[t]", 
        DisplayFunction -> $DisplayFunction];

How does this plot signal a way of rigging a pure sine fit of f[t] on [0,L]

Take another look:

Show[all];

The plot tells you that:
-> f[t] and riggedf[t] run together for 0 ≤ t ≤  L and
-> riggedf[t] has a pure Sine fit on [0,2 L].
To rig a pure sine fit of f[t] on [0,L], all you gotta do is to use the pure sine fit of riggedf[t] on [0,2 L] to fit f[t] on [0,L];
Go for it:

Clear[riggedsinefit];
riggedsinefit[t_]=Chop[ComplexExpand[FastFourierfit[riggedf,2 L,7,t]]]

fitplot = 
      Plot[{f[t], riggedsinefit[t]}, {t, 0, L}, 
        PlotStyle -> {{Thickness[0.02], Blue}, {Thickness[0.008], Red}}, 
        AxesLabel -> {"t", ""}];

Just as expected, a beautiful Sine fit of f[t] on [0,L].
Math happens again.

B.1.b.iii)

Here's an interval [0,L] and a function f[t] resistant to a direct Sine on [0,L]:

\(Clear[f, t]; 
f[t_] = E\^\(\(-0.6\)\ t\)\ Sin[π\ t]; 
\(L = 5; 
    \)\)fplot = 
      Plot[f[t], {t, 0, L}, PlotStyle -> {{Thickness[0.02], Blue}}, 
        AxesLabel -> {"t", "f[t]"}, 
        DisplayFunction -> Identity]; centerline = 
      Graphics[{Red, Thickness[0.01], Line[{{(L/2), -1}, {(L/2), 1}}]}]; 
    Show[fplot, centerline, DisplayFunction -> $DisplayFunction];

Notice that f[0] = f[L] = 0.  
In spite of the lack of symmetry, rig a pure sine fit of f[t] on [0,L].

Just do it:

\(Clear[riggedf, t]; 

    riggedf[t_] := f[t] /; 0 ≤ t ≤ L; 

    \(riggedf[t_] := \(-f[2\ L - t]\) /; L < t ≤ 2\ L; \)\)Clear[riggedsinefit];
riggedsinefit[t_]=Chop[ComplexExpand[FastFourierfit[riggedf,2 L,6,t]]]

fitplot = 
      Plot[{f[t], riggedsinefit[t]}, {t, 0, L}, 
        PlotStyle -> {{Thickness[0.02], Blue}, {Thickness[0.008], Red}}, 
        AxesLabel -> {"t", ""}];

Not bad., but not  great.
You can increase the quality of the fit:

Clear[riggedsinefit];
riggedsinefit[t_]=Chop[ComplexExpand[FastFourierfit[riggedf,2 L,13,t]]]

Plot[{f[t], riggedsinefit[t]}, {t, 0, L}, 
      PlotStyle -> {{Thickness[0.02], Blue}, {Thickness[0.008], Red}}, 
      AxesLabel -> {"t", ""}];

It doesn't get much better than this.

B.1.b.iv)

Why is it a good idea to check whether 
      f[0] = f[L] = 0
before you go for a rigged Sine fit of f[t] on [0,L]?

The rigged sine fit of f[t] on [0,L] comes from from a fast Fourier fit of riggedf[t] on [0,2L]. This means you are fitting with complex exponentials 
      (E^(((I 2 k π t)/(2 L)))) = 
        (E^(((I k π t)/L))) 
Consequently the sines involved in the rigged Sine fit are 
       Sin[((k π t)/L)].
These functions are all zeroed out at t = 0 and t = L.
This forces all the rigged sine fitters of f[t] on [0,L]  to be zeroed out at t = 0 and at t = L.
The upshot:
If you expect a good rigged sine fit of f[t] on [0,L], you'll want 
        f[0] = f[L] = 0.

B.2) Fast Fourier Sine fit and the heat equation    
               \(∂\_{x, 2}temp[x, t] = ∂\_t temp[x, t]\)

B.2.a.i)

Start with a heated wire L units long with the temperature allowed to vary from position to position on the wire. Think of the wire as the interval 0 ≤ x ≤ L.  At the start of the experiment,  you instantly cool the ends at x = 0 and x = L  and maintain these ends at temperature 0, and you take pains to guarantee that the rest of the wire is perfectly insulated.
At the start of this particular experiment, the temperature of the wire at position x (for 0 ≤ x ≤ L = 5) is given by the following function startertemp[x]:

L = 5; \(Clear[startertemp, x]; 

    startertemp[x_] = 3\ Abs[0.2\ x - Round[0.2\ x]]; 

    \(starterplot = 
      Plot[startertemp[x], {x, 0, L}, 
        PlotStyle -> {{Thickness[0.015], Blue}}, 
        AxesLabel -> {"x", "starting temperature"}]; \)\)

To fully understand this plot, look at this:

\(Clear[pointer]; 

    pointer[x_] := 
      Arrow[{0, startertemp[x]}, Tail -> {x, 0}, 
        VectorColor -> Red]; 
\(Show[starterplot, pointer[3]]; \)\)

Think of the interval [0, L] = [0, 5] as the wire.  
The tip of the pointer tells you the starting temperature (at time t = 0) at the tail of the pointer.
Your problem here is to come up with a function temp[x, t] that estimates the  temperature of the wire at position x at time t after the experiment begins. 
Do it.

The function startertemp[x] is ripe for a rigged Fourier Sine fit on [0, L] because
              startertemp[x] = 0 for x = 0 and x = L:

{startertemp[0], startertemp[L]}

Rig startertemp[x] for a pure sine fit on [0, L] and get a good sine fit of startertemp[x] on [0, L]:

\(Clear[rigged]; 

    rigged[x_] := startertemp[x] /; 0 ≤ x ≤ L; 

    \(rigged[x_] := \(-startertemp[2\ L - x]\) /; L < x ≤ 2\ L; 
    \)\)n = 10; \(Clear[riggedsinefit]; 

    riggedsinefit[x_] = 
      Chop[ComplexExpand[FastFourierfit[rigged, 2\ L, n, x]]]\)

fitplot = 
      Plot[{startertemp[x], riggedsinefit[x]}, {x, 0, L}, 
        PlotStyle -> {{Thickness[0.02], Blue}, {Thickness[0.008], Red}}, 
        AxesLabel -> {"x", ""}];

That's a decent fit.
Now look at the rigged sine fit of startertemp[x]:

riggedsinefit[x]

Pick off the coefficients of the Sin[(((k π) x)/L)] terms:

\(Clear[A, k]; 

    A[k_]\  := \ Coefficient[riggedsinefit[x], Sin[\((k\ Pi/L)\)\ x]]; 


    Table[A[k], {k, 1, n}]\)

Now you're done because you can write down temp[x, t].
It's just:

\(Clear[temp, x, t]; 

    temp[x_, t_] = 
      ∑\+\(k = 1\)\%n A[k]\ E\^\(\(-\((\(k\ π\)\/L)\)\^2\)\ t\)\ 
          Sin[\(\((k\ π)\)\ x\)\/L]\)

Quite a slap in the face, but that's all there is to it.
If you want to understand why this works, then continue with the rest of this Basic problem.

B.2.a.ii) A Movie

Stay with the same situation as in part ii) immediately above and look at this movie:

\(Clear[tempplotter]; 

    tempplotter[t_] := 
      Plot[temp[x, t], {x, 0, L}, 
        PlotStyle -> {{Thickness[0.01], Blue}}, 
        PlotRange -> {0, 1.5}, 
        AxesLabel -> {"x", " temperature"}, 
        PlotLabel -> N[t]\ "= t", AspectRatio -> 1\/2]; 

    \(timejump = 1; \)\)Table[tempplotter[t], {t, 0, 8, timejump}]

What does this movie depict?

It depicts the the wire cooling down as time goes on.
This comes from the fact that the temperature at the ends of the wire are maintained at 0 throughout the experiment.
Another way of seeing what's happening is to take another look at the formula for temp[x, t]:

temp[x, t]

Those exponentials in the denominators are driving temp[x, t] to 0 as t gets large.

B.2.a.iii)

Look at this:

Plot[{startertemp[x], temp[x, 0]}, {x, 0, L}, 
      PlotStyle -> {{Thickness[0.015], Blue}, {Thickness[0.008], Red}}, 
      AxesLabel -> {"x", ""}];

This is a plot of startertemp[x] and temp[x, 0] for 0 ≤ x ≤ L.
Why is it totally natural to expect the this plot to come out they way it did?

To begin with, 
          temp[x, t] 
estimates the temperature of the wire at position x at t time units after the experiment starts.
But 
          startertemp[x] 
measures the the temperature of the wire at position x at the start (at time t = 0). So it is natural that
        temp[x, 0] should estimate starter[x] 
pretty well.

Look at:

temp[x, t]

When you put t = 0, all the exponentials become 1:

temp[x, 0]

This is the same as the rigged sine fit of starter[x]:

riggedsinefit[x]

This is why the plots of temp[x, 0] and startertemp[x] share a lot of ink:

Plot[{startertemp[x], temp[x, 0]}, {x, 0, L}, 
      PlotStyle -> {{Thickness[0.015], Blue}, {Thickness[0.008], Red}}, 
      AxesLabel -> {"x", ""}];

B.2.a.iv) The heat equation explains where the exponentials come from

In the parts above, you get temp[x, t] by taking a rigged sine fit of startertemp[x]:

riggedsinefit[x]

And you get temp[x, t] by inserting exponentials into each term of the rigged sine fit:

temp[x, t]

Why do you insert those exponentials?

This is the central question.

Engineering studies have shown that after the appropriate unit adjustments are made, the function temp[x,t] satisfies the  partial diffeerential equation known as the heat equation
        \(∂\_{x, 2}temp[x, t] = ∂\_t temp[x, t]\)

with 
->  temp[x, 0] = startertemp[x]
 and
->  temp[0, t] = 0  and temp[L, t] = 0 for all t's.

The key is the boundary conditions 
          temp[0, t] = 0  and temp[L, t] = 0 for all t's.
These match up well with the fact that
         Sin[((k π x)/L)] = 0 for x = 0 and x = L
for all positive integers k.  This suggests that for each fixed time t, you can fit temp[x,t] with a rigged Sine fit like this:

\(Clear[approxtemp, t, x, u, L]; 
n = 6; 

    approxtemp[x_, t_] = 
      ∑\+\(k = 1\)\%n u[t, k]\ Sin[\(\((k\ π)\)\ x\)\/L]\)

The Fourier fit coefficients u[t, k] depend on t as well as k because you expect a different rigged sine fit at different times t.
The heat equation says
     D[temp[x,t],{x,2}] = D[temp[x,t],t].
Plug 
    approxtemp[x, t] = 
        (∑_(k = 1)^n) u[t, k] Sin[(((k π) x)/L)]
into the heat equation and see that
     (∑_(k = 1)^n) u[t, k] (((((k π)/L)))^2) 
            (-Sin[(((k π) x)/L)]) = 
        (∑_(k = 1)^6)(∂_t) u[t, k] 
            Sin[(((k π) x)/L)].
You can make this happen by setting
      D[u[t, k], t] = -(((((k π)/L)))^2) u[t, k] .
This is a big break in your favor because this is the exponential differential equation and you know that this makes
      u[t, k] = A[k] (E^(-(((((k π)/L)))^2) t))
where the real constant A[k] has yet to be determined.

Substitute these u[t,k]'s into approxtemp[x,t] to get
    approxtemp[x, t] = 
        (∑_(k = 1)^n) A[k] (E^(-(((((k π)/L)))^2) t)) 
            Sin[(((k π) x)/L)]

Look at what happens for t = 0:
     approxtemp[x, 0] = 
        (∑_(k = 1)^n) A[k]  Sin[(((k π) x)/L)]

This is to fit the starting temperature, so you lift the A[k]'s from the rigged sine fit of startertemp[x].
And now you see why you want to insert the exponentials.

B.2.b) A new one

Start with a heated wire L units long with the temperature allowed to vary from position to position on the wire. Think of the wire as the interval 0 ≤  x  ≤ L.  At the start of the experiment,  you instantly cool the ends at x = 0 and x = L  and maintain these ends at temperature 0, and you take pains to guarantee that the rest of the wire is perfectly insulated.
At the start of this particular experiment, the temperature of the wire at position x (for  0 ≤  x  ≤ L = 3) is given by the following function startertemp[x]:

L = 3; \(Clear[startertemp, x]; 

    startertemp[x_] = 0.2\ Sin[2\ x]\^2\ \((x - 3)\)\^2; 

    \(starterplot = 
      Plot[startertemp[x], {x, 0, L}, 
        PlotStyle -> {{Thickness[0.01], Blue}}, 
        AxesLabel -> {"x", "starting temperature"}]; \)\)

To fully understand this plot, look at this:

\(Clear[pointer]; 

    pointer[x_] := 
      Arrow[{0, startertemp[x]}, Tail -> {x, 0}, 
        VectorColor -> Red]; 
\(Show[starterplot, pointer[1.7]]; \)\)

Think of the interval 
         [0,L] = [0,3] 
as the wire.
The tip of the pointer tells you the starting temperature (at time t = 0) at the tail of the pointer.
You now know how and understand how come up with a function temp[x,t] that estimates the  temperature of the wire at position x at time t after the experiment begins. 
Do it.
Make a good movie.

The function 
                startertemp[x]
 is ripe for a rigged Fourier Sine fit on [0, L]because 
               startertemp[x] = 0 for x = 0 and x = L:

{startertemp[0], startertemp[L]}

Rig startertemp[x] for a pure sine fit on [0,L] and get a good sine fit of startertemp[t] on [0,L]:

\(Clear[rigged, x, t]; 

    rigged[x_] := startertemp[x] /; 0 ≤ x ≤ L; 

    \(rigged[x_] := \(-startertemp[2\ L - x]\) /; L < x ≤ 2\ L; 
    \)\)\(Clear[riggedsinefit]; 
n = 4; 

    riggedsinefit[x_] = 
      Chop[ComplexExpand[FastFourierfit[rigged, 2\ L, n, x]]]\)

fitplot = 
      Plot[{startertemp[x], riggedsinefit[x]}, {x, 0, L}, 
        PlotStyle -> {{Thickness[0.02], Blue}, {Thickness[0.008], Red}}, 
        AxesLabel -> {"x", ""}];

That's not a great fit. To improve the fit, raise n:

n = 10; \(Clear[riggedsinefit]; 

    riggedsinefit[x_] = 
      Chop[ComplexExpand[FastFourierfit[rigged, 2\ L, n, x]]]\)

fitplot = 
      Plot[{startertemp[x], riggedsinefit[x]}, {x, 0, L}, 
        PlotStyle -> {{Thickness[0.02], Blue}, {Thickness[0.008], Red}}, 
        AxesLabel -> {"x", ""}];

That's a decent fit.
Now look at the rigged sine fit of startertep[x]:

riggedsinefit[x]

Pick off the coefficients of the Sin[(k Pi/L) x] terms:

\(Clear[A, k]; 

    A[k_] := Coefficient[riggedsinefit[x], Sin[\(\((k\ π)\)\ x\)\/L]]; 

    coeffs = Table[A[k], {k, 1, n}]\)

Now you're done because you can write down temp[x,t]:

\(Clear[temp, x, t]; 

    temp[x_, t_] = 
      ∑\+\(k = 1\)\%\(Length[coeffs]\)A[k]\ 
          E\^\(\(-\((\(k\ π\)\/L)\)\^2\)\ t\)\ 
          Sin[\(\((k\ π)\)\ x\)\/L]\)

Here's the movie:

\(Clear[tempplotter]; 

    tempplotter[t_] := 
      Plot[temp[x, t], {x, 0, L}, 
        PlotStyle -> {{Thickness[0.01], Blue}}, 
        PlotRange -> {0, 1.2}, 
        AxesLabel -> {"x", " temperature"}, 
        PlotLabel -> N[t]\ "= t", AspectRatio -> 1\/2]; 

    \(timejump = 0.5; \)\)Table[tempplotter[t], {t, 0, 3, timejump}]

After 3 time units, the temperature of the wire is approximately 0 from end to end.

B.3) Fast Fourier Sine fit and the wave equation
               \(∂\_{x, 2}position[x, t] = 
        ∂\_{t, 2}position[x, t]\)

B.3.a.i)

Run this code before you start:

\(Clear[FastFourierfit, Fourierfitters, F, Fvalues, n, k, 
\ \ \ \ \ \ 
      jump, num, numtab, coeffs, t, L]; 

    jump[n_]\  := \ \(jump[n]\  = \ N[1/\((2\ n)\)]\); 

    Fvalues[F_, L_, n_]\  := \ 
\ \ 
      N[Table[F[L\ t], {t, 0, 1\  - \ jump[n], jump[n]}]]; 
\ \ 


    numtab[n_]\  := \ \(numtab[n]\  = \ Table[k, {k, 1, n}]\); 


    Fourierfitters[L_, n_, t_]\  := \ 
      Table[E^\((2\ Pi\ I\ k\ t/L)\), 

        \ \ \ \ \ \ \ \ \ \ {k, \(-n\)\  + \ 1, n\  - \ 1}]; 

    coeffs[n_, list_]\  := \ 
      Join[Reverse[Part[Fourier[list], numtab[n]]], 
	
          Part[InverseFourier[list], Drop[numtab[n], 1]]]/
		
        N[Sqrt[Length[list]]]
\)\(FastFourierfit[F_, L_, n_, t_]\  := \ 
\ \ \ \ \ 
      Chop[Fourierfitters[L, n, t] . coeffs[n, Fvalues[F, L, n]]]; \ \ \ \ 

    L := Expand[a\ D[#1, {#2, 2}]\  + \ b\ D[#1, #2]\  + \ c\ #1]&\)

The ends of a guitar string are anchored at 0 and L on the x-axis and the string is pulled to an initial position and then allowed to vibrate on its own starting with initial velocity 0.

At the start of this particular experiment, the position of the wire at position x (for 0 ≤ x ≤  L = 5) is given by the following function starterposition[x]:

L = 5; \(Clear[starterposition, x]; 

    starterposition[x_] = 0.7\ Abs[0.2\ x - Round[0.2\ x]]; 

    \(starterplot = 
      Plot[starterposition[x], {x, 0, L}, 
        PlotStyle -> {{Thickness[0.01], Blue}}, PlotRange -> All, 
        AspectRatio -> 1\/4, 
        AxesLabel -> {"x", "starting position"}]; \)\)

Think of the curve as the the starting position of the guitar string.
To fully understand this plot, look at this:

\(Clear[pointer]; 

    pointer[x_] := 
      Graphics[{Red, Thickness[0.01], 
          Line[{{x, starterposition[x]}, {x, 0}}]}]; 

    \(Show[starterplot, pointer[2]]; \)\)

The tip of the pointer tells you the starting position (at time t = 0) at the tail of the pointer.
Your problem here is to come up with a function position[x,t] that estimates the position of the guitar string at position x on the x-axis at time t after the experiment begins. 
Do it.

R

The function starterposition[x] is ripe for a rigged Fourier Sine fit on [0,L] because starterposition[x] = 0 for x = 0 and x = L:

{starterposition[0], starterposition[L]}

Rig starterposition[x] for a pure sine fit on [0,L] and get a good sine fit of starterposition[x] on [0,L]:

\(Clear[rigged]; 

    rigged[x_] := starterposition[x] /; 0 ≤ x ≤ L; 

    \(rigged[x_] := 
      \(-starterposition[2\ L - x]\) /; L < x ≤ 2\ L; \)\)\(Clear[riggedsinefit]; 
n = 12; 

    riggedsinefit[x_] = 
      Chop[ComplexExpand[FastFourierfit[rigged, 2\ L, n, x]]]\)

fitplot = 
      Plot[{starterposition[x], riggedsinefit[x]}, {x, 0, L}, 
        PlotStyle -> {{Thickness[0.02], Blue}, {Thickness[0.01], Red}}, 
        AspectRatio -> (1/4), AxesLabel -> {"x", ""}];

That's a great fit.
Now look at the rigged sine fit of starterposition[x]:

riggedsinefit[x]

Pick off the coefficients of the Sin[(k Pi/L) x] terms:

\(Clear[A, k]; 

    A[k_] := Coefficient[riggedsinefit[x], Sin[\(\((k\ π)\)\ x\)\/L]]; 

    coeffs = Table[A[k], {k, 1, n}]\)

Now you're done because you can write down approxposition[x,t]:

\(Clear[approxposition, x, t]; 

    approxposition[x_, t_] = 
      ∑\+\(k = 1\)\%\(Length[coeffs]\)A[k]\ 
          Cos[\(\((k\ π)\)\ t\)\/L]\ Sin[\(\((k\ π)\)\ x\)\/L]\)

Quite a slap in the face, but that's all there is to it.
If you want to understand why this works, then continue with the rest of this Basic problem.

B.3.a.ii) A Movie

Stay with the same situation as in part a.i) immediately above and look at this movie:

\(Clear[positionplotter]; 

    positionplotter[t_] := 
      Plot[approxposition[x, t], {x, 0, L}, 
        PlotStyle -> {{Thickness[0.01], Blue}}, 
        PlotRange -> {\(-0.4\), 0.4}, 
        AxesLabel -> {"x", " position"}, 
        PlotLabel -> N[t]\ "= t", AspectRatio -> 1\/2]; 

    \(timejump = L\/3; \)\)Table[positionplotter[t], {t, 0, 2 L, timejump}]

What does this movie depict?

It depicts the vibration of the guitar string. 
Notice that the string returns to its starting position after 2 L time units:

positionplotter[0];

positionplotter[2 L];

This oscillatory (periodic)  behavior as time goes on comes from the Cosines in position[x,t]:

approxposition[x, t]

B.3.a.iii) The wave equation explains where the Cosines come from

You get position[x,t] by taking a rigged sine fit of starterposition[x]:

riggedsinefit[x]

And you get position[x,t] by inserting Cosines into each term of the rigged sine fit:

approxposition[x, t]

Why do you insert those Cosines?

This is the central question.

Engineering studies have shown that after the appropriate unit adjustments are made, the function position[x,t] satisfies the wave equation
                  \(∂\_{x, 2}position[x, t] = 
        ∂\_{t, 2}position[x, t]\).

with 
-> position[x, 0] = starterposition[x]
-> position[0, t] = 0 and position[L, t] = 0 for all t's

and with 
-> (∂_t) position[x, t] = 0 for t = 0 .

The key is the boundary conditions 
         position[0, t] = 0 and position[L, t] = 0.
These match up well with the fact that
        Sin[((k π x)/L)] = 0 for x = 0 and x = L
for all positive integers k.  This suggests that for a fixed time t, you can fit position[x,t] with a rigged Sine fit like this:

\(Clear[approxposition, t, x, u, L]; 
n = 4; 

    approxposition[x_, t_] = 
      ∑\+\(k = 1\)\%n u[t, k]\ Sin[\(\((k\ π)\)\ x\)\/L]\)

The Fourier fit coefficients u[t, k] depend on t as well as k because you expect a different rigged sine fit at different times t.
The wave equation says
           \(\(\ \ 
      ∂\_{x, 2}position[x, t] = 
        ∂\_{t, 2}position[x, t]\)\)
    
Plug 
             approxposition[x, t] = 
        (∑_(k = 1)^n) u[t, k] Sin[(((k π) x)/L)]
into both sides of thw wave equation and see that you want:
     (∑_(k = 1)^n) u[t, k] (((((k π)/L)))^2) 
          (-Sin[(((k π) x)/L)])=   \(∑\+\(k = 1\)\%n∂\_{t, 2}u[t, k]\ 
          Sin[\(\((k\ π)\)\ x\)\/L]\).
You can make this happen by setting
      \(∂\_{t, 2}u[t, k] = 
        \(-\((\(k\ π\)\/L)\)\^2\)\ u[t, k]\) .
This is the same as
      \(∂\_{t, 2}u[t, k] + \((\(k\ π\)\/L)\)\^2\ u[t, k] = 0
        \)
This is a big break in your favor because this is the undamped unforced oscillator:

\(Clear[u, t, A, B, k]; 

    u[t_, k_] = 
      A[k]\ Cos[\(\((k\ π)\)\ t\)\/L] + 
        B[k]\ Sin[\(\((k\ π)\)\ t\)\/L]\)

Here the real constants A[k] and B[k] have yet to be determined.

Now look at the condition 
       (∂_t) position[x, t] = 0 for t = 0.
Because 
       approxposition[x, t] = 
        (∑_(k = 1)^n) u[t, k] Sin[(((k π) x)/L)], 
you can achieve  
       (∂_t) position[x, t] = 0 for t = 0 
by insisting that:

((∂_t) u[t, k] /. t -> 0) == 0

This tells you to set B[k] = 0 so that u[t,k] becomes:

u[t, k] /. B[k] -> 0

Substitute 
         u[t, k] = A[k] Cos[(((k π) t)/L)]
into approxposition[x,t] to get
         approxposition[x, t] = 
        (∑_(k = 1)^n) 
          A[k] Cos[(((k π) x)/L)] 
            Sin[(((k π) x)/L)]:

Look at what happens for t = 0:
          approxposition[x, 0] = 
        (∑_(k = 1)^n) 
          A[k] Cos[(((k π) 0)/L)] 
            Sin[(((k π) x)/L)]
                                                  = (∑_(k = 1)^n) A[k] Sin[(((k π) x)/L)]

This is to fit the starting position, so you lift the A[k]'s from the rigged sine fit of starterposition[x].
And now you see why you want to insert the Cosines.

B.3.b) A new one

Activate this code:

\(Clear[FastFourierfit, Fourierfitters, F, Fvalues, n, k, 
\ \ \ \ \ \ 
      jump, num, numtab, coeffs, t, L]; 

    jump[n_]\  := \ \(jump[n]\  = \ N[1/\((2\ n)\)]\); 

    Fvalues[F_, L_, n_]\  := \ 
\ \ 
      N[Table[F[L\ t], {t, 0, 1\  - \ jump[n], jump[n]}]]; 
\ \ 


    numtab[n_]\  := \ \(numtab[n]\  = \ Table[k, {k, 1, n}]\); 


    Fourierfitters[L_, n_, t_]\  := \ 
      Table[E^\((2\ Pi\ I\ k\ t/L)\), 

        \ \ \ \ \ \ \ \ \ \ {k, \(-n\)\  + \ 1, n\  - \ 1}]; 

    coeffs[n_, list_]\  := \ 
      Join[Reverse[Part[Fourier[list], numtab[n]]], 
	
          Part[InverseFourier[list], Drop[numtab[n], 1]]]/
		
        N[Sqrt[Length[list]]]
\)\(FastFourierfit[F_, L_, n_, t_]\  := \ 
\ \ \ \ \ 
      Chop[Fourierfitters[L, n, t] . coeffs[n, Fvalues[F, L, n]]]; \ \ \ \ 

    L := Expand[a\ D[#1, {#2, 2}]\  + \ b\ D[#1, #2]\  + \ c\ #1]&\)

The ends of a guitar string are anchored at 0 and L on the x-axis and the string is pulled to an initial position and then allowed to vibrate on its own starting with initial velocity 0.

At the start of this partricular experiment, the position of the wire at position x (for 0 ≤ x ≤  L = 3) is given by the following function starterposition[x]:

L = 3; \(Clear[starterposition, x]; 

    starterposition[x_] = 0.1\ x\^2\ \((x - 3)\)\^2; 

    \(starterplot = 
      Plot[starterposition[x], {x, 0, L}, 
        PlotStyle -> {{Thickness[0.01], Blue}}, 
        AxesLabel -> {"x", "starting position"}]; \)\)

.Your problem here is to come up with a function position[x, t] that estimates the position of the guitar string at position x on the x-axis at time t after the experiment begins. 
Do it.
Make a good movie.

The function starterposition[x] is ripe for a rigged Fourier Sine fit on [0,L] because starterposition[x] = 0 for x = 0 and x = L:

{starterposition[0], starterposition[L]}

Rig starterposition[x] for a pure sine fit on [0,L] and get a good sine fit of starterposition[t] on [0,L]:

\(Clear[rigged]; 

    rigged[x_] := starterposition[x] /; 0 ≤ x ≤ L; 

    \(rigged[x_] := 
      \(-starterposition[2\ L - x]\) /; L < x ≤ 2\ L; \)\)\(Clear[riggedsinefit]; 
n = 7; 

    riggedsinefit[x_] = 
      Chop[ComplexExpand[FastFourierfit[rigged, 2\ L, n, x]]]\)

fitplot = 
      Plot[{starterposition[x], riggedsinefit[x]}, {x, 0, L}, 
        PlotStyle -> {{Thickness[0.02], Blue}, {Thickness[0.008], Red}}, 
        AxesLabel -> {"x", ""}];

That's a great fit.
Now look at the rigged sine fit of starterposition[x]:

riggedsinefit[x]

Pick off the coefficients of the Sin[(((k π) x)/L)] terms:

\(Clear[A, k]; 

    A[k_] := Coefficient[riggedsinefit[x], Sin[\(\((k\ π)\)\ x\)\/L]]; 

    coeffs = Table[A[k], {k, 1, n}]\)

Now you're done because you can write down approxposition[x,t]:

\(Clear[approxposition, x, t]; 

    approxposition[x_, t_] = 
      ∑\+\(k = 1\)\%\(Length[coeffs]\)A[k]\ 
          Cos[\(\((k\ π)\)\ t\)\/L]\ Sin[\(\((k\ π)\)\ x\)\/L]\)

Here comes the movie:

\(Clear[positionplotter]; 

    positionplotter[t_] := 
      Plot[approxposition[x, t], {x, 0, L}, 
        PlotStyle -> {{Thickness[0.01], Blue}}, 
        PlotRange -> {\(-0.6\), 0.6}, 
        AxesLabel -> {"x", " position"}, 
        PlotLabel -> N[t]\ "= t", AspectRatio -> 1\/2]; 

    \(timejump = L\/3; \)\)Table[positionplotter[t], {t, 0, 2 L, timejump}]

Hey Mr. Disney, look at that.

B.4) Fourier integral fit

Here's how you can use integrals to go after a Fourier fit on an interval [0,L]:
Start with the function and its plot on [0,L]:

\(Clear[f, t]; 
f[t_] = t\/2; 
\(L = 4; \)\)Plot[f[t], {t, 0, L}, PlotStyle -> {{Thickness[0.02], Blue}}, 
      AxesLabel -> {"t", "f[t]"}];

To fit f[t] on [0,L] with Fourier Integral fit, you fit with combinations  
        (E^(((I k 2 π t)/L)))
this way:

\(Clear[A, t]; 

    A[k_] := \(A[k] = 
        N[\(∫\_0\%L
                \( f[t]\ E\^\(-\(\(I\ k\ \((2\ π)\)\ t\)\/L\)\)\) 
                \[DifferentialD]t\)\/L]\); 
Clear[k, complexfitter]; 

    m = 5; 
complexfitter[t_] = 
      Chop[∑\+\(k = \(-m\)\)\%m A[k]\ 
            E\^\(\(I\ k\ \((2\ π)\)\ t\)\/L\)]\)

Covert to combinations of Sine and Cosine waves.

\(Clear[realfitter, t]; 

    realfitter[t_] = Chop[ComplexExpand[complexfitter[t]]]\)

Check out the fit with a plot:

Plot[{f[t], realfitter[t]}, {t, 0, L}, 
      PlotStyle -> {{Thickness[0.02], Blue}, {Thickness[0.01], Red}}, 
      AxesLabel -> {"t", ""}];

The periodic nature of the Fourier fit ruins the fit at the ends, but inside [0,L], the fit is not bad.

B.4.a)

How do you try to go after a better Fourier Integral fit?

The same way you go after a better fast Fourier fit: 
You increase n.  
Try it:

\(Clear[A, t]; 

    A[k_] := \(A[k] = 
        N[\(∫\_0\%L
                \( f[t]\ E\^\(-\(\(I\ k\ \((2\ π)\)\ t\)\/L\)\)\) 
                \[DifferentialD]t\)\/L]\); 
Clear[k, complexfitter]; 

    n = 13; 
complexfitter[t_] = 
      Chop[∑\+\(k = \(-n\)\)\%n A[k]\ 
            E\^\(\(I\ k\ \((2\ π)\)\ t\)\/L\)]\)

\(Clear[realfitter, t]; 

    realfitter[t_] = Chop[ComplexExpand[complexfitter[t]]]\)

Check out the fit with a plot:

Plot[{f[t], realfitter[t]}, {t, 0, L}, 
      PlotStyle -> {{Thickness[0.02], Blue}, {Thickness[0.01], Red}}, 
      AxesLabel -> {"t", ""}];

That's about as good as it can get. If f[0] had been the same as f[L], then the trouble near the endpoints would have disappeared.

B.4.b.i) The formula for the Fourier Integral coefficients 
                        A[k] = 
        (1/L) 
          (∫_0^L) f[t] 
              (E^(-((I k (2 π) t)/L))) 
              dt

What's the idea behind the formula 
           A[k] = 
        (1/L) 
          (∫_0^L) f[t] 
              (E^(-((I k (2 π) t)/L))) 
              dt
as used above?

The idea:
You go for the whole ball of wax in one gulp.
Given a function f[t] with period L, you go ahead and assume that f[t] can be written in a form like this:

m = 3; \(Clear[k, f, complexfitter, A, L]; 

    complexfitter[t_] = 
      ∑\+\(k = \(-m\)\)\%m A[k]\ E\^\(\(I\ k\ 2\ π\ t\)\/L\)\)

Once you go with the assumption that 
              f[t] = complexfitter[t], 
you gotta agree that
    (∫_0^L)
           complexfitter[t] (E^(-((I p (2 π) t)/L))) 
          dt =  (∫_0^L)
           f[t] (E^(-((I p (2 π) t)/L))) 
          dt
             
no matter what p you go with.
Peek at what this tells you:

\(Clear[p, f]; 

    Table[{Expand[
          ∫\_0\%L
              \( complexfitter[t]\ 
                E\^\(-\(\(I\ p\ \((2\ π)\)\ t\)\/L\)\)\) 
              \[DifferentialD]t], " must be", 
        ∫\_0\%L
            \( f[t]\ E\^\(-\(\(I\ p\ \((2\ π)\)\ t\)\/L\)\)\) 
            \[DifferentialD]t}, {p, \(-m\), m}]\)

Your eyes lead you to the formula
      A[k] = 
        (1/L) 
          (∫_0^L) f[t] 
              (E^(-((I k (2 π) t)/L))) 
              dt
This is the formula that was used in part i) so successfully.
Explanation over.

B.4.b.ii)

Not so fast.
Wasn't this supposed to be a math course?
You know very well that a false assumption like 
        f[t] = complexfitter[t]
can be used to explain anything.
How do you justify this false assumption?

Good question.  
The reason it works is that it is almost true.
Reason: For most functions f[t] with period L, only a bureaucratic bean-counter armed with a good magnifying glass could ever tell the difference between f[t] and the complexfitter you get with a very high m.
Try it on
      f[t] = (Sqrt[1 - Cos[π t]])
Because the period of Cos[π t] is 2, the period of f[t] is 
      L = 2.

\(Clear[f, t, x]; 
f[t_] = \@\(1 - Cos[π\ t]\); 
\(L = 2; \)\)m = 6; \(Clear[k, complexfitter, A]; 

    A[k_] := N[1\/L]\ 
        NIntegrate[
          f[x]\ E\^\(-\(\(I\ k\ \((2\ π)\)\ x\)\/L\)\), {x, 0, L}, 
          AccuracyGoal -> 3]; 

    complexfitter[t_] = 
      Chop[∑\+\(k = \(-m\)\)\%m A[k]\ 
            E\^\(\(I\ k\ \((2\ π)\)\ t\)\/L\)]\)

\(Clear[realfitter, t]; 

    realfitter[t_] = Chop[ComplexExpand[complexfitter[t]]]\)

Plot[{f[t], realfitter[t]}, {t, 0, L}, 
      PlotStyle -> {{Thickness[0.02], Blue}, {Thickness[0.01], Red}}, 
      AxesLabel -> {"t", ""}, PlotRange -> All];

Tell that miserable bean counter to get out of your life.

B.4.c.i) The connection between fast Fourier Fit and Fourier integral fit

Activate this code:

\(Clear[FastFourierfit, Fourierfitters, F, Fvalues, n, k, jump, num, 
      numtab, coeffs, t, L]; 
jump[n_] := \(jump[n] = N[1\/\(2\ n\)]\); 
    Fvalues[F_, L_, n_] := N[Table[F[L\ t], {t, 0, 1 - jump[n], jump[n]}]]; 
    numtab[n_] := \(numtab[n] = Table[k, {k, 1, n}]\); 
    Fourierfitters[L_, n_, t_] := 
      Table[E\^\(\(2\ π\ I\ k\ t\)\/L\), {k, \(-n\) + 1, n - 1}]; 
    coeffs[n_, list_] := 
      \(1\/N[\@Length[list]]\) 
        \((Join[Reverse[
              \(Fourier[list]\)[[numtab[n]
                  ]]], 
            \(InverseFourier[list]\)[[Drop[numtab[n], 1]
                ]]])\)\)\(FastFourierfit[F_, L_, n_, t_] := 
      Chop[Fourierfitters[L, n, t] . coeffs[n, Fvalues[F, L, n]]]; 
    L := Expand[a\ ∂\_{#2, 2}#1 + b\ ∂\_#2 #1 + c\ #1]&
        \)

Go with f[t] = t ( 3 - t) on [0, l} with L = 3 and compare what you get

\(Clear[f, t]; 
f[t_] = t\ \((3 - t)\); 
\(L = 3; \)\)\(Clear[A, t]; 

    A[k_] := \(A[k] = 
        N[\(∫\_0\%L
                \( f[t]\ E\^\(-\(\(I\ k\ \((2\ π)\)\ t\)\/L\)\)\) 
                \[DifferentialD]t\)\/L]\); 
Clear[k, complexintegralfitter]; 
    
m = 5; 

    complexintegralfitter[t_] = 
      Chop[∑\+\(k = \(-m\)\)\%m A[k]\ 
            E\^\(\(I\ k\ \((2\ π)\)\ t\)\/L\)]\)

n = m + 1; FastFourierfit[f, L, n, t]

They are almost the same.
Subtract them:

Expand[complexintegralfitter[t] - FastFourierfit[f, L, n, t]]

Puny coefficients reflecting how close the fast Fourier fit is to the Fourier integral fit.

Try it again with a bigger m:

\(Clear[k, complexintegralfitter]; 
m = 10; 

    \(complexintegralfitter[t_] = 
      Chop[∑\+\(k = \(-m\)\)\%m A[k]\ 
            E\^\(\(I\ k\ \((2\ π)\)\ t\)\/L\)]; \)\)n = m + 1; Expand[complexintegralfitter[t] - FastFourierfit[f, L, n, t]]

How do you explain this striking similarity of the two Fourier fits?

The fast Fourier fit tries to fit at equally spaced points on the plot of f[t] on [0,L]. When you go with a high n in FastFourierfit[f,L,n,t], you are fitting so many densely packed points that FastFourierfit[f,L,n,t] is almost fitting all the points on the plot of f[t] on [0,L]. 
This nearly replicates the Fourier integral fit of f[t] on [0,L] because the Fourier integral fit tries to fit the plot of f[t] all the points on the plot of f[t] on [0,L].

B.4.c.ii) Practicalities

Explain the following statement:
"Fast Fourier fit is almost always fast and practical; Fourier integral fit is almost sometimes low and slow and sometimes impractical and even impossible."

Answer:

The Achilles heel of the Fourier integral fit is the integral 
        A[k] = 
        (1/L) 
          (∫_0^L) f[t] 
              (E^(-((I k (2 π) t)/L))) 
              dt
that most be done to calculate the coefficients. It is possible to try to calculate them with NIntegrate, but the highly oscillatory nature of 
        f[t] (E^(-((I k (2 π) t)/L)))
sometimes makes the integrals impractical for NIntegrate.

Fast Fourier fit carries none of this disappointing baggage. 
It runs quickly and accurately - provided no impulses are around.

In their book, "Numerical Methods and Software" (Prentice-Hall, 1989),
David Kahner, Cleve Moler and Stephen Nash say  
"Many knowledgeable people feel that [Tukey's fast Fourier fit] is 
the single most important contribution to computing since 
the advent of the stored programming concept."

B.4.c.iii)

Why do folks want to do Fourier integral fit?

If the professors demand that the students work by hand, then the student has little choice between Fourier integral fit and fast Fourier fit.
Reason:
Doing fast Fourier fit by hand is completely out of the question.
Doing integrals by hand is sometimes possible but hardly ever a good use of your time.

In theoretical situations, most good folks want to use the Fourier integral fit because it gives them a specific formula to work with.  But after the theory is developed and calculations begin, then the same folks go with fast Fourier fit.

B.5) Fourier integral fit and the heat equation

Start with a heated wire L units long with the temperature allowed to vary from position to position on the wire. Think of the wire as the interval 0 ≤ x ≤ L.  At the start of the experiment,  you instantly cool the ends at x = 0 and x = L  and maintain these ends at temperature 0, and you take pains to guarantee that the rest of the wire is perfectly insulated.
At the start of this particular experiment, the temperature of the wire at position x (for 0 ≤ x ≤ L = 5) is given by the following function startertemp[x]:

L = 5; \(Clear[startertemp, x]; 

    startertemp[x_] = 3\ Abs[0.2\ x - Round[0.2\ x]]; 

    \(starterplot = 
      Plot[startertemp[x], {x, 0, L}, 
        PlotStyle -> {{Thickness[0.015], Blue}}, 
        AxesLabel -> {"x", "starting temperature"}]; \)\)

To fully understand this plot, look at this:

\(Clear[pointer]; 

    pointer[x_] := 
      Arrow[{0, startertemp[x]}, Tail -> {x, 0}, 
        VectorColor -> Red]; 
\(Show[starterplot, pointer[3]]; \)\)

Think of the interval [0,L] = [0,5] as the wire.  
The tip of the pointer tells you the starting temperature (at time t = 0) at the tail of the pointer.
Your problem here is to use Fourier Integral fit to come up with a function temp[x,t] that estimates the  temperature of the wire at position x at time t after the experiment begins. 
Do it.

The function startertemp[x] is ripe for a rigged Fourier Sine fit on [0,L] because
              startertemp[x] = 0 for x = 0 and x = L:

{startertemp[0], startertemp[L]}

Rig startertemp[x] for a pure sine fit on [0,L] and get a good Fourier integral sine fit of startertemp[x] on [0,L]:

\(Clear[rigged]; 

    rigged[x_] := startertemp[x] /; 0 ≤ x ≤ L; 

    rigged[x_] := \(-startertemp[2\ L - x]\) /; L < x ≤ 2\ L; 

    Clear[A, t]; 

    A[k_] := \(A[k] = 
        \((1/\((2\ L)\))\)\ 
          NIntegrate[
            rigged[x]\ E\^\(-\(\(I\ k\ x\ 2\ π\)\/\(2\ L\)\)\), {x, 0, 
              2\ L}]\); 
Clear[k, complexfitter]; 
m = 5; 

    complexfitter[x_] = 
      Chop[∑\+\(k = \(-m\)\)\%m A[k]\ 
            E\^\(\(I\ k\ \((2\ π)\)\ x\)\/\(2  L\)\)]\)

Covert to combinations of Sine and Cosine waves.

\(Clear[approxstartertemp, x]; 

    approxstartertemp[x_] = Chop[ComplexExpand[complexfitter[x]]]\)

Check out the fit with a plot:

The periodic nature of the Fourier fit ruins the fit at the ends, but inside [0,L], the fit is not bad.

Plot[{startertemp[x], approxstartertemp[x]}, {x, 0, L}, 
      PlotStyle -> {{Thickness[0.02], Blue}, {Thickness[0.01], Red}}, 
      AxesLabel -> {"t", ""}];

That's a decent fit.
Now look at the rigged sine fit of startertemp[x]:

approxstartertemp[x]

Pick off the coefficients of the Sin[(((k π) x)/L)] terms:

\(Clear[A, k]; 

    A[k_] := Coefficient[approxstartertemp[x], 
        Sin[\(\((k\ π)\)\ x\)\/L]]; 
Table[A[k], {k, 1, m}]\)

Now you're done because you can write downapprox temp[x,t].
It's just:

\(Clear[temp, x, t]; 

    approxtemp[x_, t_] = 
      ∑\+\(k = 1\)\%m A[k]\ 
          \((E\^\(\(-\((\(k\ π\)\/L)\)\^2\)\ t\)\ 
              Sin[\(\((k\ π)\)\ x\)\/L])\)\)

Tthat's all there is to it.