% set up x and t grids
N=100;
M=50000;     % hope this is big enough
h=2/N;
k=2/M;
x=-1+2*(0:N)/N;

u = (x+1).^3/8;    % obeys boundary conditions
hold on
plot(x,u,'r')      % plot inital condition
xlabel('x')

% do euler to get to t=1, plot, and find the answer to the question
for j=1:M/2
    u(2:N) = u(2:N)+(3/10)*k/h^2*(u(1:(N-1))+u(3:(N+1))-2*u(2:N));
end
plot(x,u,'b')
max(abs(u-(x+1)/2))   % answer 0.1847

% do euler to get to t=2, plot, and find the answer to the question
for j=1:M/2
    u(2:N) = u(2:N)+(3/10)*k/h^2*(u(1:(N-1))+u(3:(N+1))-2*u(2:N));
end
plot(x,u,'g')
max(abs(u-(x+1)/2))    % answer 0.0881