Initialization

SetOptions[Plot,PlotStyle->{Blue,AbsoluteThickness[2], Dashed},
ImageSize->500,AxesStyle->Directive[FontFamily->"Arial",FontSize->18,Black,AbsoluteThickness[0.5],Arrowheads[0.04]]];

Work

PH424 Homework #2 - Triangle wave animation.

Basics

To execute a line of code, press "enter" (not return) or "shift return".
In this worksheet, text, or comment, is in Times font, formatted to appear against a blue background.  You can change this and other formatting under Edit Stylesheet in the Format menu.

It is often helpful to clear variables of any value that may be assigned to them.  Either of the following command works to clear the variables x and A.  It does NOT set them to zero, it just clears them.

Clear[x,t,n]

Define a single frequency function that obeys the boundary conditions on x, and the intial conditions on dψ/dt.  The variable n defines the wavelength, and the Fourier decomposition of the triangle waveform gives the amplitude of each component in terms of n.  (The fundamental wavelngth is twice the length of the rope, and the length of the rope  has been set to 1. The velocity of the wave in the rope is also 1.  Both in appropriate units of course).

ψ[x_,t_,n_]:=9/n^2/π^2*Sin[n*π/3]*Sin[n*π*x]*Cos[n*π*t]

Check that the function is what you thought it was.  Don't use an underscore after the variable on the lhs when you ask for the function to be returned.

ψ[x,t,n]

Now add up all the Fourier components - call the resulting function Ψ[x,t].  Ψ is no longer a function of n because it is a sum over n.

Ψ[x_,t_]:=Sum[ψ[x,t,n],{n,1,50,1}]

Plots

Animate[Plot[Ψ[x,t],{x,0,1},
PlotStyle->{Red,Thick},
AxesLabel->{x,Ψ},
PlotRange->{{0,1.1},{-1.2,1.3}},
Ticks->{{{0,0},{1/3,"L/3"},{1,"L"}},{{1,"A"}}}],
{t,0,2},AnimationRunning->False]