% Unit 2 (MATLAB Course @ UAM)
% (c) Alexander Knebe

%========================
% 2D random vector field
%========================
clear all
close all
clc
 
% range and # of points
Nmesh   = 10;
stretch = 0.9;

xmin  = -2.6;
xmax  = +3.2;
ymin  = -1.6;
ymax  = +2.8;


% generate a linearly spaced mesh in x and y
xmesh = linspace(xmin,xmax,Nmesh);
ymesh = linspace(ymin,ymax,Nmesh);
[x,y] = meshgrid(xmesh,ymesh);


% generate a 2D random vector field
vx = rand(Nmesh,Nmesh)-0.5;
vy = rand(Nmesh,Nmesh)-0.5;

% plot the vectors
figure(1)
quiver(x,y,vx,vy,stretch)  % NOTE: "stretch" scales the length!
axis image

