d'Alembert's Solution to the Wave Equation
One end fixed and one end free
> restart: with(plots): Mod:=(x,y)->x-floor(x/y)*y:
A string of length L is fixed at x = 0 and free at x = L with initial conditions and . d'Alembert's solution to the wave equation is given by the expression u(x,t) below with and the periodic extensions of period 4L of f and g odd at x = 0 and even at x = L .
> u:=(x,t)->1/2*(fp(x+c*t)+fp(x-c*t))+1/(2*c)*int(gp(z),z=x-c*t..x+c*t);
The extensions are obtained by first extending f and g for 0 < x < 4 L.. This gives one period of the extension.
> f1:=x->piecewise(x<=L,f(x),x<=2*L,f(2*L-x),x<=3*L,-f(4*L-x),x>3*L,-f(4*L-x)); g1:=x->piecewise(x<=L,g(x),x<=2*L,g(2*L-x),x<=3*L,-g(4*L-x),x>3*L,-g(4*L-x));
Now, the functions are extended as periodic functions over the entire real line.
> fp:=x->f1(Mod(x,4*L)); gp:=x->g1(Mod(x,4*L));
Example 1: For a simple example, one finds that the above functions are defined correctly.
> L:=2: f:=x->x*(2*L-x); g:=0:
> plot({f(x),g(x)},x=0..L,color=[blue,red]);
> plot({feven(x),geven(x)},x=0..4*L,color=[blue,red]);
> plot({fp(x),gp(x)},x=-4*L..6*L,color=[blue,red]);
The solution to the wave equation can be animated. Click on the graph below and then on the play button
> c:=.2: animate( u(x,t),x=0..L,t=0..40,frames=50,color=blue);
Here are other examples:
>
L:=2:c:=.2:a:=L/2: f:=x->sin(Pi*x/L/2): g:=x->0:
animate( u(x,t),x=0..L,t=0..20,frames=50,color=blue);
>
L:=2:c:=.2:a:=L/2: f:=x->sin(3*Pi*x/L/2): g:=x->0:
animate( u(x,t),x=0..L,t=0..40,frames=50,color=blue);
>
L:=2:c:=.2:a:=L/2: f:=x->sin(Pi*x/L/2)+.5*sin(3*Pi*x/L/2): g:=x->0:
animate( u(x,t),x=0..L,t=0..40,frames=50,color=blue);
>
Try your own initial conditions and play with the wavespeed c.