h = 0.1;
tau = 0.004;
x = 0:h:4;
t = 0:tau:0.5;
N = length(x);
M = length(t);
for m = 1:M
    u(1,m) = t(m)*sin(2*t(m));
    u(N,m) = 0;
end
for n = 2:N-1
    u(n,1) = sin(pi*x(n));
    u(n,2) = u(n,1)+tau*0;
end
for m = 2:M-1
    for n = 2:N-1
        u(n,m+1) = u(n,m)+(tau/h.^2)*(u(n+1,m)-2*u(n,m)+u(n-1,m));
    end
end
for m = 1:M
    plot(x,u(:, m));
    axis([0,4,-5,5]);
    MM(m) = getframe;
end
