close all
clear all

load 'Lab4Data.mat'

%starting point
xp = 0.5;
yp = 2.7;

dx = 0.15;
dy = 0.05;
N = 100;
xn = xp;
yn = yp;
dt = 3;

%viscosity of water
mu = 1.002e-3;

for i = 2:N
    for j = 2:N
        %x and y
        X(i) = (i-1)*dx;
        Y(j) = (j-1)*dy;
        
        %velocity components
        dpsiy(i,j) = psi(i,j) - psi(i,j-1);
        dpsix(i,j) = psi(i,j) - psi(i-1,j);
        U(i,j) = dpsiy(i,j)/dy;
        V(i,j) = -dpsix(i,j)/dx;
        
        %shear stress
        dU(i,j) = U(i,j) - U(i,j-1);
        tau(i,j) = mu*(dU(i,j)/dy);
    end
end

for i = 1:50
    
    up = griddata(X,Y,U, xp,yp);
    vp = griddata(X,Y,V, xp,yp);
    xp = xp +up*dt;
    yp = yp +vp*dt;
    
    xp = [xp, xn];
    yp = [yp, yn];
    
    quiver(X,Y,U,V)
    axis([min(X) max(X) min(Y) max(Y)]);
    hold on;
    plot(xp,yp,'r-','LineWidth',3);
    F(i) = getframe;
    hold off;
end

%quiver(x,y,U,V)
%hold on
%contour(x,y,psi,'b')
%surface(x,y,tau)
%axis([0 15 0 5])
