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

%========================
% 3D random vector field
%========================
clear all
close all
clc

% range and # of points
Nmesh = 10;

xmin  = -2.6;
xmax  = +3.2;
ymin  = -1.6;
ymax  = +2.8;
zmin  = -2.5;
zmax  = +3.0;

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


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

quiver3(x,y,z,vx,vy,vz)
axis image

