% btm_fig77 generates a contour and "quiver" plot of the temperature % T(x,y) and its gradient, approximating figure 7.7 in "Basic % Training in Mathematics" by R. Shankar. % % The function is T(x,y) = y^2 + x^2. % Programmer: Dick Furnstahl furnstahl.1@osu.edu % % Revision history: % 01-May-2005 -- original version for Physics 263 % clear; % this sets variables to zero, so we start with a clean slate % Set a grid X Y with the desired range (and gridsize points on each axis) xmin = -2; xmax = 2; % set the minimum and maximum values of x ymin = -2; ymax = 2; % set the minimum and maximum values of y gridsize = 20; [X Y] = meshgrid( linspace(xmin,xmax,gridsize), linspace(ymin,ymax,gridsize) ); T = Y.^2 - X.^2; % define the temperature function [Tx Ty] = gradient(T); % calculate the gradient with the x-component % stored in Tx and the y-component in Ty % Draw the figure (we use "hold" to let us draw two plots on one figure) figure(1); % figure 1 will be a contour plot num_contours = 6; % use num_contours contour lines contourf(X,Y,T,num_contours); colorbar; % make the plot and add a color bar hold on; % hold the current plot scale = 1; % scaling of vector lengths quiver(X,Y,Tx,Ty,scale); % plot the gradient vectors xlabel('x-axis'); ylabel('y-axis'); % add labels hold off; % release the hold