% complex_plot generates surface and contour plots of the magnitude % (or modulus) of a function of a complex variable z = x + i*y. % Programmer: Dick Furnstahl furnstahl.1@osu.edu % % Revision history: % 18-Apr-2005 -- original version for Physics 263 % clear; % this sets variables to zero, so we start with a clean slate xmin = -2; xmax = 2; % set the minimum and maximum values of x ymin = -2; ymax = 2; % set the minimum and maximum values of y num_pts = 50; % set the number of points in each direction % Set a grid X Y with evenly spaced points [X Y] = meshgrid( linspace(xmin,xmax,num_pts), linspace(ymin,ymax,num_pts) ); % Define z = x + i*y for each point in the grid Z = X + i*Y; % Here is where we evaluate the function we want to study. % Note the use of "." before operations like "^" and "/". f = abs( Z ./ (1 + Z.^2) ); % use "abs" to take the modulus of the function figure(1); % figure 1 will be a surface plot surf(X,Y,f); colorbar; % make the plot and add a color bar xlabel('x-axis'); ylabel('y-axis'); % add labels to x and y axes figure(2); % figure 2 will be a contour plot num_contours = 10; % use num_contours contour lines contourf(X,Y,f,num_contours); colorbar; % make the plot and add a color bar xlabel('x-axis'); ylabel('y-axis'); % add labels