function stringeq4
clear; clf;
tmax=20; L=6; w=1/2;
t=0:tmax/100:tmax;
x=0:L/100:L;
for k=1:length(t)
    plot(x, dalambert(x,t(k)))
    axis([0,L,-0.5,0.5])
    M(k)=getframe;
end
movie(M,2)

    function y=dalambert(x,t)
        for j=1:length(x)
            y(j)=(phi_prod(x(j)-w*t)+phi_prod(x(j)+w*t))/2;
        end
    end
    function y=phi_prod(x)
        if -L<=x && x<=L
            y=phi_odd(x);
        else if x>L
                y=phi_prod(x-2*L);
            else
                y=phi_prod(x+2*L);
            end
        end
    end
    function y=phi_odd(x)
        if 0<=x && x<=L
            y=phi(x);
        else if -L<=x && x<0
                y=-phi(-x);
            end
        end
    end
    function y=phi(x)
        if 1<=x && x<=2
            y=20*(x-1)^3*(2-x)^3;
        else if(0<=x && x<1)|(2<x && x<=L)
                y=0;
            end
        end
    end
end