================= === 2D graphs === ================= ============================== === simple graphs (ez...) ==== ============================== ezplot('x*sin(x)') % on interval < -2*pi, 2*pi > or: f = 'x*sin(x)'; ezplot(f) ezplot(f, [-2, 10]) % on interval < -2, 10 > % or ezplot(f, -2, 10) grid on grid off ======= for 2 variables ============ ezplot('x^2 + y^2 - 4') ezsurf('x^2 + y^2 - 4') colorbar ezmesh('x^2 + y^2 - 4') ezcontour('x^2 + y^2 - 4') f = 'x^2 - y^2-5'; ezplot(f, [-10, 10]) % in a square ezplot(f, [-10, 10, -5, 5]) % in a rectangle ----- graphical solution of equations --- ezplot('x^2 + 1') % the first function hold on % next plot to the same figure ezplot('x^2 + y^2 - 4') % the second function hold off % next plot wipe away the previous one axis([-2 2 0 3]) % zoom in or: xlim([-1.5 , 1.5]) % interval on x axis ylim([1.5 , 2]) % interval on y axis axis equal ezsurf('x^2 + y^2 - 4') hold on ezsurf('-x^2 + y + 8') ============================= ==== command plot =========== ============================= x = -pi:0.3:pi; % points on x axis (from -pi to pi, step 0.3) y = x.*sin(x); % points on y axis (function values) plot(x, y) % points connected by blue lines plot(x,y, 'r') % red line plot(x,y, 'r', 'linewidth', 2) % thicker red line plot(x,y, 'r*') % points marked as red asterisks plot(x,y, 'k--o', 'linewidth', 2) % dashed black line, circles hold on plot(x,y, 'mo', 'linewidth', 6) % bigger magenta circles hold off xlabel('x: (-pi, pi)') ylabel('x*sin(x)') title('Plot of the function x*sin(x)') help plot % other possibilities --- more functions in one graph --- x = pi*[-1:0.1:1]; y1 = sin(x); y2 = cos(x).^2; y3 = exp(x); plot(x, y1, x, y2, 'r', x, y3, 'k') legend('sin(x)','cos(x)^2', 'e^x') legend('sin(x)','cos(x)^2', 'e^x', 'location', 'northwest') --- or : plot(x, [y1; y2; y3]) % rows of 2. matrix plot(x, [y1' y2' y3']) % columns of 2. matrix --- or one after another --- plot(x, y1) hold on % continue on the same picture plot(x, y2) plot(x, y3) hold off % next time opens a new picture ------- more plots in one picture ---- subplot(3,1,1); plot(x,y1) % division 3 rows, 1 columns, 1-st picture subplot(3,1,2); plot(x,y2) subplot(3,1,3); plot(x,y3) --- managing more pictures --- f1 = figure; % 1. picture f2 = figure; % 2. picture f3 = figure; % 3. picture prints to actual (i.e. 3.) picture figure(f1); % switch to 1. pict. plot(x, y1) % draws to 1. pict. figure(f2); % switch to 2. pict. plot(x, y2) % draws to 2. pict. close(f2) % close 2. pict. close all % close all pict. --- parametric curve --- t = 0 : 0.2 : 2*pi; x = sin(t); y = cos(t); plot(x, y) axis equal axis normal =========================== ======= 3D graphs ========== =========================== t = 0 : pi/50 : 10* pi; plot3(sin(t), cos(t), t, 'r*') zlabel('z') ============ graph on a rectangle mesh ================ x = 0 : 0.3 : 10; % mesh on x axis y = -5 : 0.2 :5; % mesh on y axis [xx,yy] = meshgrid(x,y); % rectangular mesh on xy plane z = xx.^2 + yy.^3; % computation of the z-coordinate at mesh nodes mesh(xx,yy,z) % mesh graph colorbar meshc(xx,yy,z) % mesh graph with isolines (contours) in xy plane surf(xx,yy,z) % surface graph surfc(xx,yy,z) % surface graph with isolines ============ graph on an irregular mesh ================ n = 50; % number of points (nodes) x = rand(1,n); % coordinates of nodes (here random numbers) y = rand(1,n); z = y + sin(3*x); % function values at nodes tri = delaunay(x,y); % triangulation trisurf(tri, x, y, z) % surface graph trimesh(tri, x, y, z) % mesh graph =======================================================