function levelcurves1() % Illustrate level curves using Matlab's 3D graphics and contour graphics features. f1 = figure('Position', [0 0 1180 800], 'Name', 'Level Curve Example', 'NumberTitle', 'off'); set(f1, 'color', 'white'); % Divide figure window into right and left sides. a1 = axes('Position', [0.02 0.02 .46 .96]); a2 = axes('Position', [.55 0.20 .40 .60]); % Prepare function data. [x,y] = meshgrid(-1:.1:1, -1:.1:1); z = 3 - sqrt( (x-1).^2 + y.^2 ).*( (x+1).^2 + y.^2 ); % Plot the graph. set(f1, 'CurrentAxes', a1); surf(x,y,z, 'EdgeColor','none'); % Add a couple of horizontal traces. t=-1:.02:-.4; line( t, -sqrt(-1-(2/3)*t -t.^2 + 32*t.^2./(3*(27+512*t.^3+3*sqrt(3)*sqrt(27+1024*t.^3)).^(1/3)) + (1/6)*(27+512*t.^3+3*sqrt(3)*sqrt(27+1024*t.^3)).^(1/3)),repmat(2.5,length(t)),'Color','black'); line( t, sqrt(-1-(2/3)*t -t.^2 + 32*t.^2./(3*(27+512*t.^3+3*sqrt(3)*sqrt(27+1024*t.^3)).^(1/3)) + (1/6)*(27+512*t.^3+3*sqrt(3)*sqrt(27+1024*t.^3)).^(1/3)),repmat(2.5,length(t)),'Color','black'); t=.85:.02:1; line( t, -sqrt(-1-(2/3)*t -t.^2 + 32*t.^2./(3*(27+512*t.^3+3*sqrt(3)*sqrt(27+1024*t.^3)).^(1/3)) + (1/6)*(27+512*t.^3+3*sqrt(3)*sqrt(27+1024*t.^3)).^(1/3)),repmat(2.5,length(t)),'Color','black'); line( t, sqrt(-1-(2/3)*t -t.^2 + 32*t.^2./(3*(27+512*t.^3+3*sqrt(3)*sqrt(27+1024*t.^3)).^(1/3)) + (1/6)*(27+512*t.^3+3*sqrt(3)*sqrt(27+1024*t.^3)).^(1/3)),repmat(2.5,length(t)),'Color','black'); t=-1:.02:1; line( t, -sqrt(-1-(2/3)*t-t.^2+32*t.^2./(3*(243+512*t.^3+9*sqrt(3)*sqrt(243+1024*t.^3)).^(1/3))+(1/6)*(243+512*t.^3+9*sqrt(3)*sqrt(243+1024*t.^3)).^(1/3)),repmat(1.5,length(t)),'Color','black'); line( t, sqrt(-1-(2/3)*t-t.^2+32*t.^2./(3*(243+512*t.^3+9*sqrt(3)*sqrt(243+1024*t.^3)).^(1/3))+(1/6)*(243+512*t.^3+9*sqrt(3)*sqrt(243+1024*t.^3)).^(1/3)),repmat(1.5,length(t)),'Color','black'); % Add (custom) axes. % Get Prof. Smyth's code if you want to uncomment the axis commands. % xAxis(2.4); % yAxis(2.4); % zAxis(3.2); % Create a contour plot. set(f1, 'CurrentAxes', a2); contour(x,y,z,'ShowText','on'); % Export image to a PNG file. (Edit the path below to something appropriate for your system.) saveas( f1, ['/home/rsmyth/tmp/levelCurves1_1.png']);