Asad
Asad

Reputation: 3042

I am trying to draw a stream function in matlab

I am using this code snap to draw a stream function

[X,Y]= meshgrid(linspace(0,80),linspace(-8,8));
[t]=meshgrid(linspace(0,100));
B=1+0.3*cos(0.9*t);
k=2*phi/10;
low=.1+k.^2.*B.^2.*sin(k.*(X-0.9.*t)).^2;
PSI=-tanh((Y-B.*cos(k.*(X-0.9.*t)))./sqrt(low));
contour(X,Y,PSI,3);
colormap cool

I wanted to something like the picture. What I am getting only the current(the sin shape lines) but not the vortex(The rectangular shape). enter image description here enter image description here

Upvotes: 1

Views: 4258

Answers (1)

Amro
Amro

Reputation: 124563

I tried to generate the plot using the parameters shown, but I did not manage to get the "vortex" shapes in the contour plot. Here is my implementation:

len = 200;
[X,Y] = meshgrid(linspace(0,80,len), linspace(-8,8,len));
t = meshgrid(linspace(0,1,len));

a = 1.2;
c = 0.12;
k = 2*pi/7.5;
w = 0.4;
e = 0.3;

B = a + e * cos(w*t);
D = k * (X - c*t);
PSI = - tanh((Y - B.*sin(D)) ./ sqrt(1 + (k * B.*cos(D)).^2)) + c*Y;

figure('Position',[100 100 650 300])
movegui('center')

subplot(211)
contour(X, Y, PSI, 10), ylim([-4.5 4.5])
%colormap cool
xlabel('kilometers'), ylabel('km'), title('Mobility Model')

subplot(212), axis off
text(0.5, 0.5, ...
    {['$\psi(x,y,t) = -\tanh{[ \frac{y - B(t) \sin(k(x-ct))}' ...
    '{\sqrt{1 + k^2 B^2(t) \cos^2(k(x-ct))}} ]} + cy$'];
    '$where\, B(t) = A + \epsilon cos(\omega t)$'}, 'Interpreter','latex', ...
    'FontSize',20, 'Horizontal','center', 'Vertical','middle')

matlab_contour_plot


This leads to me believe that the screenshot you've shown does not exactly match the equation/parameters below it...

In fact if we look at the surface plot in 3D, you'll find that there is no shape in the curve that would look like those triangles in between the sinusoidals. It's just two almost-flat planes, with a dented drop in between.

Here is the two-dimensional function shown as a surface plot:

surf(X, Y, PSI, 'FaceColor','interp', 'EdgeColor','none')
daspect([20 6 1])
axis vis3d, axis tight
box on, grid on, view(140,30)
xlabel X, ylabel Y, zlabel PSI
lighting phong
camlight left

surface_3d

Upvotes: 3

Related Questions