%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%% Flow Around a Cylinder Using Complex Variables %%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% set the flow velocity at large distance if it is not yet set
if exist('U') ~= 1
  U=1
end

% set the angle of attack in degrees if it is not yet set
if exist('alp') ~= 1
  alp=0
end

% set radius of the cylinder if it is not yet set
if exist('r0') ~= 1
    r0=1
end

% set a value for the circulation if it is not yet set
if exist('Gamma') ~= 1
    Gamma=0
end

% create mesh points around the cylinder
[th,r]=meshgrid([-.001:5:360]*pi/180,[r0-.0001:.05:3]);
[x,y]=pol2cart(th,r);
z=x+i*y;

% compute the complex velocity potential at those points
F=U*(z*exp(-i*alp/180*pi)+r0^2*exp(i*alp/180*pi)./z)+i*Gamma/(2*pi)*log(z/r0);

% compute the real streamfunction
psi=imag(F);

% plot the streamlines 
contour(x,y,psi,floor(min(min(psi))):.2:ceil(max(max(psi))))
axis("equal")
