
    if (nt==1)
        [fig1,HandleM]=movie_init(x,B,Bm,A,N);
    else
        if (mod(nt,ntplot)==0)
            movie_plot(x,B,Bm,A,fig1,HandleM);
        end
    end




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [fig1,HandleM]=movie_init(x,B,Bm,A,N)

        close all
        fig1=figure(1);
        HandleM(1)=line(x,B,'LineWidth',3);
        HandleM(2)=line(x(1)+.02,Bm(1),'LineStyle','none','Marker','o','MarkerFaceColor','r');
        HandleM(3)=line(x(1),A(1),'LineStyle','none','Marker','o','MarkerFaceColor','g');
        HandleM(4)=line(x(N)+.02,Bm(2),'LineStyle','none','Marker','o','MarkerFaceColor','r');
        HandleM(5)=line(x(N),A(2),'LineStyle','none','Marker','o','MarkerFaceColor','g');
        hold on
        set(gcf,'DoubleBuffer','on');
        xlabel(' x ')
        ylabel(' B ')
        legend(' B',' Bm',' A')
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function movie_plot(x,B,Bm,A,fig1,HandleM)

        set(HandleM(1),'YData',B);
        set(HandleM(2),'YData',Bm(1));
        set(HandleM(3),'YData',A(1));
        set(HandleM(4),'YData',Bm(2));
        set(HandleM(5),'YData',A(2));        
        drawnow;
    
end


