%---------------------------------------------- % Example Commands for Lab 2 %---------------------------------------------- %--------------------------------------------------------- %Now Lets look at Scalar and Vector fields %--------------------------------------------------------- clear; %Its a good idea to always clear variables at the beginning x=[1:0.2:5]; y=[1:0.2:5]; %two vectors defining positions to be used in meshgrid [X,Y]=meshgrid(x,y); %X is a 10 x 10 matrix of x coordinates. Each %column is a different x-coordinate. %Y is a 10 x 10 matrix of y coordinates. Each %row is a different y-coordinate R=sqrt(X.^2 + Y.^2); %R is a 10 x 10 matrix of distance from origin %This just illustrates that you can do arithmetic %on matrices just like vectors Vx=ones(size(X)); %X component of vector set to an arbitray function % In this case it is a matrix of 1's of the same % size/shape as X Vy=0.2.*Y; %Y component of vector increases with Y figure(2); clf; %clear the figure C=contourf(X,Y,Vy); hold on; %Contour horizontal component of V %which is a scalar field clabel(C); alscale=1; %arrow length scale quiver(X,Y,Vx,Vy,alscale,'k'); hold on; %plot vectors V= colormap hot axis([1 4 1 4]); axis('equal'); colorbar('horiz')