Q:

plotting streamlines with stream functions

I am trying to plot a streamline with a stream function:
psi = Y.*(F.*M.*cosh((1 + phi.*cos(2.*pi.*X)).*M)+ (1 + F.*M.^2*beta).*sinh((1 + phi.*cos(2.*pi.*X)).*M))-(F + (1 + phi.*cos(2.*pi.*X))).*sinh(M.*Y)/(1 + phi.*cos(2.*pi.*X)).*M.*cosh((1 + phi.*cos(2.*pi.*X)).*M)+ (-1 + (1 + phi.*cos(2.*pi.*X)).*M.^2.*beta).*sinh((1 + phi.*cos(2.*pi.*X)).*M )+ (alpha.*((F + (1 + phi.*cos(2.*pi.*X))).*Y.*cosh(2.*(1 + phi.*cos(2.*pi.*X)).*M) + Y.*(-1 + 2.*(1 + phi.*cos(2.*pi.*X)).^2.*M.^2- 2.*M.*Y.*cosh(M.*Y).*((1 + phi.*cos(2.*pi.*X)).*M.*cosh((1 + phi.*cos(2.*pi.*X)).*M)+ (-1 + (1 + phi.*cos(2.*pi.*X)).*M.^2.*beta).*sinh((1 + phi.*cos(2.*pi.*X)).*M))- 2.*(1 + phi.*cos(2.*pi.*X)).*M.*sinh(2.*(1 + phi.*cos(2.*pi.*X)).*M) + 2.*((1 + phi.*cos(2.*pi.*X)).*M.*(Y + (1 + phi.*cos(2.*pi.*X)).^2.*M.^2.*beta).*cosh((1 + phi.*cos(2.*pi.*X)).*M) + (-Y + (1 + phi.*cos(2.*pi.*X)).*M.*2.*((1 + phi.*cos(2.*pi.*X)).^2 - (1 + phi.*cos(2.*pi.*X)).*beta + Y.*beta)).*sinh((1 + phi.*cos(2.*pi.*X).*M)).*sinh(M.*Y)))./8.*((1 + phi.*cos(2.*pi.*X)).*M.*cosh((1 + phi.*cos(2.*pi.*X)).*M) + (-1 + (1 + phi.*cos(2.*pi.*X)).*M.^2.* beta).*sinh((1 + phi.*cos(2.*pi.*X)).*M)).^2));

I have written a code:
M = 0;
phi = 0.4;
beta = 0.0;
theta = 0.65;
F = theta - 1;
alpha = 0.0;

[X,Y]= meshgrid(linspace(-0.5,0.5),linspace(0,1.5));
Z = Y.*(F.*M.*cosh((1 + phi.*cos(2.*pi.*X)).*M)+ (1 + F.*M.^2*beta).*sinh((1 + phi.*cos(2.*pi.*X)).*M))-(F + (1 + phi.*cos(2.*pi.*X))).*sinh(M.*Y)/(1 + phi.*cos(2.*pi.*X)).*M.*cosh((1 + phi.*cos(2.*pi.*X)).*M)+ (-1 + (1 + phi.*cos(2.*pi.*X)).*M.^2.*beta).*sinh((1 + phi.*cos(2.*pi.*X)).*M )+ (alpha.*((F + (1 + phi.*cos(2.*pi.*X))).*Y.*cosh(2.*(1 + phi.*cos(2.*pi.*X)).*M) + Y.*(-1 + 2.*(1 + phi.*cos(2.*pi.*X)).^2.*M.^2- 2.*M.*Y.*cosh(M.*Y).*((1 + phi.*cos(2.*pi.*X)).*M.*cosh((1 + phi.*cos(2.*pi.*X)).*M)+ (-1 + (1 + phi.*cos(2.*pi.*X)).*M.^2.*beta).*sinh((1 + phi.*cos(2.*pi.*X)).*M))- 2.*(1 + phi.*cos(2.*pi.*X)).*M.*sinh(2.*(1 + phi.*cos(2.*pi.*X)).*M) + 2.*((1 + phi.*cos(2.*pi.*X)).*M.*(Y + (1 + phi.*cos(2.*pi.*X)).^2.*M.^2.*beta).*cosh((1 + phi.*cos(2.*pi.*X)).*M) + (-Y + (1 + phi.*cos(2.*pi.*X)).*M.*2.*((1 + phi.*cos(2.*pi.*X)).^2 - (1 + phi.*cos(2.*pi.*X)).*beta + Y.*beta)).*sinh((1 + phi.*cos(2.*pi.*X).*M)).*sinh(M.*Y)))./8.*((1 + phi.*cos(2.*pi.*X)).*M.*cosh((1 + phi.*cos(2.*pi.*X)).*M) + (-1 + (1 + phi.*cos(2.*pi.*X)).*M.^2.* beta).*sinh((1 + phi.*cos(2.*pi.*X)).*M)).^2));
contour(X,Y,Z,100)

[C,h] = contour(X,Y,Z);
set(h,'ShowText','on','TextStep',get(h,'LevelStep')*2)
colormap cool

I am getting
Warning: Matrix is singular to working precision.
Warning: Contour not rendered for non-finite ZData
> In contour>parseargs at 192
  In contour at 69
Warning: Contour not rendered for non-finite ZData
> In contour>parseargs at 192
  In contour at 69

what is the problem? thanks.

A:

you're dividing a singluar matrix:
(F + (1 + phi.*cos(2.*pi.*X))).*sinh(M.*Y)/(1 + phi.*cos(2.*pi.*X))
I think you're missing a dot before the slash:
M = 1;
phi = 0.4;
beta = 0.0;
theta = 0.65;
F = theta - 1;
alpha = 0.0;
[X,Y]= meshgrid(linspace(-0.5,0.5),linspace(0,1.5));
Z = Y.*(F.*M.*cosh((1 + phi.*cos(2.*pi.*X)).*M)+ (1 + F.*M.^2*beta).*sinh((1 + phi.*cos(2.*pi.*X)).*M))-(F + (1 + phi.*cos(2.*pi.*X))).*sinh(M.*Y)./(1 + phi.*cos(2.*pi.*X)).*M.*cosh((1 + phi.*cos(2.*pi.*X)).*M)+ (-1 + (1 + phi.*cos(2.*pi.*X)).*M.^2.*beta).*sinh((1 + phi.*cos(2.*pi.*X)).*M )+ (alpha.*((F + (1 + phi.*cos(2.*pi.*X))).*Y.*cosh(2.*(1 + phi.*cos(2.*pi.*X)).*M) + Y.*(-1 + 2.*(1 + phi.*cos(2.*pi.*X)).^2.*M.^2- 2.*M.*Y.*cosh(M.*Y).*((1 + phi.*cos(2.*pi.*X)).*M.*cosh((1 + phi.*cos(2.*pi.*X)).*M)+ (-1 + (1 + phi.*cos(2.*pi.*X)).*M.^2.*beta).*sinh((1 + phi.*cos(2.*pi.*X)).*M))- 2.*(1 + phi.*cos(2.*pi.*X)).*M.*sinh(2.*(1 + phi.*cos(2.*pi.*X)).*M) + 2.*((1 + phi.*cos(2.*pi.*X)).*M.*(Y + (1 + phi.*cos(2.*pi.*X)).^2.*M.^2.*beta).*cosh((1 + phi.*cos(2.*pi.*X)).*M) + (-Y + (1 + phi.*cos(2.*pi.*X)).*M.*2.*((1 + phi.*cos(2.*pi.*X)).^2 - (1 + phi.*cos(2.*pi.*X)).*beta + Y.*beta)).*sinh((1 + phi.*cos(2.*pi.*X).*M)).*sinh(M.*Y)))./8.*((1 + phi.*cos(2.*pi.*X)).*M.*cosh((1 + phi.*cos(2.*pi.*X)).*M) + (-1 + (1 + phi.*cos(2.*pi.*X)).*M.^2.* beta).*sinh((1 + phi.*cos(2.*pi.*X)).*M)).^2));
contour(X,Y,Z,100)
[C,h] = contour(X,Y,Z);
set(h,'ShowText','on','TextStep',get(h,'LevelStep')*2)
colormap cool

Also, be sure to change M to value different from 0

