function [v,z,x,y] = stream1(m,n,iterations,w)

%
% This function should compute the stream function for 
% stagnation flow around a corner
%
a = 0.; b = 1.; c = 0.; d = 1.; 
%iterations=100;
dx = (b-a)/(m-1);
dy = (d-c)/(n-1);
%initialize the solution
v=zeros(m,n);
for i = 1:m,
x(i) = a + (i-1)*dx;
end
for j = 1:n,
y(j) = c + (j-1)*dy;
end
% set horizontal boundary conditions
for i = 1:m,
% set the bottom boundary (floor)
v(i,1) = 0;
% set the top boundary (inflow)
v(i,n) = y(n)*x(i);
end
%
% set vertical boundary conditions
for j = 1:n,
% set the left boundary (wall)
v(1,j) = 0;
% set the right boundary (outflow)
v(m,j) = x(m)*y(j);
end
%
% set the internal values
for k = 1:iterations,
%v;
for i = 2:m-1,
for j = 2:n-1,
v(i,j) = v(i,j)+w*(v(i-1,j)+v(i+1,j)+v(i,j-1)+v(i,j+1)-4*v(i,j))/4;
end
end
end
diff=0;
for i = 1:n,
for j = 1:m,
z(i,j) = x(i)*y(j);
d = abs(z(i,j)-v(i,j));
if (d > diff), diff=d;
end
end
end
fprintf('max difference is %f12.8\n',diff)