function stringeq3
    clear; clf;
tmax=20;w=1/2;
t=0:tmax/100:tmax;
x=0:0.01:6;
for k = 1:length(t)
    plot(x, dalambert(x,t(k)));
    axis([0,6,-0.5,0.5]);
    M(k)= getframe;
end
movie(M,2)
    %tova sa ne4etnite prodaljeniq na funkciite
    function y = phi_even(x)
        if x>=0 y=phi(x);
        else y=phi(-x);
        end
    end      

function y = dalambert(x,t)
for j = 1 :length(x)
    if t==0 z=0;
    else 
        s=x(j)-w*t:w*t/20:x(j)+w*t;
        z = trapz(s,psi_even(s));
    end
    y(j) = (phi_even(x(j)-w*t)+phi_even(x(j)+w*t))/2+z/(2*w); 
end
end

    function y= phi(x)
        if x>= 1 && x<=2
            y=20*(x-1)^3*(2-x)^3;
        else if(0<=x && x<1) || x>2
            y=0;
            end
        end
    end

    function y=psi(x)
        for i = 1: length(x)
            % za b) poduslovie:  y(i)=sin(3*x(i))/20
            y(i)=0;
        end
    end
    function y=psi_even(x)
        for m=1:length(x)
            if x(m)>= 0 y(m)=psi(x(m));
            else y(m)=psi(-x(m));
            end
        end
    end
end