function laxf(c,h,r)
%one way wave equation
%lax friedrichs

% clear all
% c = 1;
% h = 0.1;
% k = 0.08;

k = r*h
steps = 5/(c*k)

%loop to populate vector of initial conditions between -2 and 3
j=1;
for i = -2:h:3
	x(j) = i;
    if (abs(i)>1);
        u(1,j) = 0;        
    else
        u(1,j) = 1 - abs(i);    
    end
    j = j + 1;
end
n = j - 1;

%loop to populate subsequent lines of matrix
for m = 1:steps
	u(m+1,1) = 0;
    for j = 2:n-1
        u(m+1,j) = (0.5 * (u(m,j-1) + u(m,j+1))) - ((c*k/(2*h))*(u(m,j+1) - u(m,j-1)));
    end
	u(m+1,n) = u(m+1,n-1);
end

%graphics
for m = 1:steps
    plot(x,u(m,1:n));
	axis([-2 3 -0.5 2])
	M(:,m) = getframe;
end
