Presentation is loading. Please wait.

Presentation is loading. Please wait.

A L I MAM M OHAMMAD B IN S AUD I SLAMIC U NIVERSITY C OLLEGE OF S CIENCES D EPARTMENT OF M ATHEMATICS MATLAB 251 : MATH SOFTWARE Introduction to MATLAB.

Similar presentations


Presentation on theme: "A L I MAM M OHAMMAD B IN S AUD I SLAMIC U NIVERSITY C OLLEGE OF S CIENCES D EPARTMENT OF M ATHEMATICS MATLAB 251 : MATH SOFTWARE Introduction to MATLAB."— Presentation transcript:

1 A L I MAM M OHAMMAD B IN S AUD I SLAMIC U NIVERSITY C OLLEGE OF S CIENCES D EPARTMENT OF M ATHEMATICS MATLAB 251 : MATH SOFTWARE Introduction to MATLAB

2 4. Graphics in MATLAB

3 I NTRODUCTION TO M ATLAB 4.1 Main functions

4 I NTRODUCTION TO M ATLAB To put mathematics in labels you can use matlab’s backslash notation (familiar to users of the TEX typesetting system)

5 I NTRODUCTION TO M ATLAB 4.2 2D Graphics Plot symbols and colors may be obtained when we use one of the 4 first previous commands, by adding a string S in those commands. PLOT(X,Y,S) or PLOT(X1,Y1,S1,X2,Y2,S2,X3,Y3,S3,…) Plot symbols and colors may be obtained when we use one of the 4 first previous commands, by adding a string S in those commands. PLOT(X,Y,S) or PLOT(X1,Y1,S1,X2,Y2,S2,X3,Y3,S3,…) Sketch curves or clouds of pointsplot Plot semi-logarithmic curvessemilogx semilogy Plot semi-logarithmic curvesloglog Plot graphs in polar coordinatespolar Plot two curves in the same graph with their own axis systemplotyy Plot functionsezplot Plot functions in polar coordinatesezpolar Graphic zoomzoom

6 I NTRODUCTION TO M ATLAB >> x= linspace(1,10,20); >> y=sin(x);z=cos(x); >> plot(x,y,'-.',x,z,'r') >> t = 0:.1:2*pi; >> subplot(2,2,1) >> plot(cos(t),sin(t)) >> subplot(2,2,2) >> plot(cos(t),sin(2*t)) >> subplot(2,2,3) >> plot(cos(t),sin(3*t)) >> subplot(2,2,4) >> plot(cos(t),sin(4*t))

7 I NTRODUCTION TO M ATLAB 4.3 Graphic symbols

8 I NTRODUCTION TO M ATLAB 4.4 Clearing the Figure Window You can clear the plot window by typing clf, which stands for ‘clear figure’. To get rid of a figure window entirely, type close. To get rid of all the figure windows, type close all. New figure windows can be created by typing figure. 4.5 Axes So far we have allowed matlab to choose the axes for our plots. You can change the axes in many ways: axis([xmin xmax ymin ymax ]) sets the axes’ minimum and maximum values. axis square makes the axes the same length axis equal makes the axes the same scale axis tight sets the axes limits to the range of the data axis auto allows matlab to choose axes limits axis off removes the axes leaving only the plotted data axis on puts the axes back again

9 I NTRODUCTION TO M ATLAB 4.6 3D graphics 1. Elementary commands (using matrix) 3. Tools commands 2. Elementary commands (math functions) Sketch linear currves and clouds of pointsplot3 Sketch a matrix under a meshed curvemesh Sketch a matrix under a surfaced curvesurf Sketch 2D functions and parametric functionsezplot3 Sketch 2D functions and parametric functions under a meshed curveezmesh Sketch 2D functions and parametric functions under a surfaced curveezsurf Transparent meshinghidden Color smoothingshading Lightinglight Add a bar of colorcolorbar Table of colorcolormap

10 I NTRODUCTION TO M ATLAB Examples: >> t=0:.1:2*pi; >> plot3(cos(3*t),sin(3*t),t) >> [X,Y]=meshgrid(-10:10); >> Z=sqrt(X.^2+Y.^2); >> mesh(X,Y,Z)

11 I NTRODUCTION TO M ATLAB An interesting function: peaks function >> [X,Y,Z]=peaks; >> mesh(X,Y,Z) >> [X,Y,Z]=peaks; >> surf(X,Y,Z)

12 I NTRODUCTION TO M ATLAB >>shading interp; >>axis tight; >>colorbar;

13 I NTRODUCTION TO M ATLAB >> [X,Y,Z]=peaks; >> contour(X,Y,Z) >> [X,Y,Z]=peaks; >> plot3(X,Y,Z) >> [X,Y,Z]=peaks; >> surfc(X,Y,Z); >>shading flat;

14 I NTRODUCTION TO M ATLAB Suppose we have the set of(X,Y) coordinates The (x,y) can be split into two matrices >>x=[1:4];y=[1:4]; >>[X,Y]=meshgrid(x,y) This is meshgrid principle


Download ppt "A L I MAM M OHAMMAD B IN S AUD I SLAMIC U NIVERSITY C OLLEGE OF S CIENCES D EPARTMENT OF M ATHEMATICS MATLAB 251 : MATH SOFTWARE Introduction to MATLAB."

Similar presentations


Ads by Google