# DREAM - PowerPoint PPT Presentation Download Presentation DREAM

DREAM Download Presentation ## DREAM

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
##### Presentation Transcript

1. DREAM IDEA PLAN IMPLEMENTATION

2. MatrixLaboratory Introduction to MatlabByDr. Kourosh Kiani

3. Course Structure • Spread over 8 weeks • 1 classes per week • 2 hour per class

4. 2D graph

5. Plotting The plot function has different forms, depending on the input arguments. If yis a vector, plot(y) produces a piecewise linear graph of the elements of y versus the index of the elements of y >> y = 0:1:100; >> plot(y)

6. Plotting >> y = 0:1:100; >> plot(y); >> grid; • GRID ON creates a grid on the current figure • GRID OFF turns off the grid from the current figure • GRID toggles the grid state

7. Plotting If you specify two vectors as arguments, plot(x,y) produces a graph of y versus x. >> x = 0:pi/100:2*pi; >> y = sin(x); >> plot(x,y); >> grid;

8. Plotting >> x = 0:pi/100:2*pi; >> y = sin(x); >> plot(x,y); >> grid; >> title('Plot of the Sine Function','FontSize',12) >> xlabel('x = 0:2\pi'); >> ylabel('Sine of x');

9. Plotting You can plot multiple graphs in one call to plot using x-y pairs. MATLAB automatically cycles through a predefined list of colors (determined by the axes ColorOrder property) to allow discrimination between sets of data. Plotting three curves as a function of t produces >> t = 0:pi/100:2*pi; >>y1 = sin(t); >>y2 = sin(t-0.25); >>y3 = sin(t-0.5); >>plot(t,y1,t,y2,t,y3); >> grid on;

10. HOLD ON holds the current plot HOLD OFF releases hold on current plot HOLD toggles the hold state Adding additional plots to a figure • » x = 0:.1:2*pi; • y = sin(x); • » plot(x,y,'b') • » grid on • » hold on • » plot(x,exp(-x),'r:*')

11. Color, Symbols, and Line Types b blue . point - solid g green o circle : dotted r red x x-mark -. dashdot c cyan + plus -- dashed m magenta * star y yellow s square k black d diamond v triangle (down) ^ triangle (up) < triangle (left) > triangle (right) p pentagram h hexagram Colors Symbols Line Types

12. Color, Symbols, and Line Types >> x=0:pi/100:2*pi; >> y=sin(x); >>plot(x,y, ‘g’); >> x=0:pi/100:2*pi; >> y=sin(x); >>plot(x,y, ‘r’);

13. Color, Symbols, and Line Types >> x=0:pi/100:2*pi; >> y=sin(x); >>plot(x,y, ‘:g’); >> x=0:pi/100:2*pi; >> y=sin(x); >>plot(x,y, ‘--r’);

14. Color, Symbols, and Line Types x = -pi:pi/10:pi; y = tan(sin(x)) - sin(tan(x)); plot(x,y,'--rs','LineWidth',2,… 'MarkerEdgeColor','k',‘… MarkerFaceColor','g',… 'MarkerSize',10)

15. Color, Symbols, and Line Types >> x = 0:pi/15:4*pi; >>y = exp(2*cos(x)); >>plot(x,y,'-r',x,y,'og')

16. Plotting: Multiple Graphs >> x = linspace(0, 4*pi); >>y1 = sin(x); >>y2 = sin(x) .^ 2; >>y3 = y1 + y2; >>plot(x,y1,x,y2,x,y3); >>legend( 'sin(x)', 'sin(x)^2', 'sin(x) +sin(x)^2' );

17. Plotting: Multiple Graphs >>x = linspace ( 0, 10*pi, 100 ); >>y = exp ( -0.1 * x ) .* sin ( x ); >>plot ( x, y, ' r' ); >>hold on; >>plot ( x, exp ( -0.1 * x ), ' g '); >>plot ( x, -exp ( -0.1 * x ) ); >>hold off;

18. Color, Symbols, and Line Types >>x= -pi:0.1:pi; >>y =sin(x); >>set(gca,’Xtick’, -pi:pi/2:pi) >>set(gca,’XTickLabel’,{‘pi’,’-pi/2’,’0’,’pi/2’,’pi’}

19. Plotting Examples >>x=-2:0.01:4; >>y=3.5^(-0.5*x).*cos(6*x); >>plot(x,y); >>line([0,0],[-3 3],’color’,’r’);

20. Plotting Examples >>x=-2:0.01:4; >>y=3.5^(-0.5*x).*cos(6*x); >>plot(x,y); >>line([1,2],[-3 3],’color’,’r’);

21. Plotting Examples >>x=-2:0.01:4; >>y=3.5^(-0.5*x).*cos(6*x); >>plot(x,y); >>line([-2,4],[1 1],’color’,’r’);

22. Subplots SUBPLOT- display multiple axes in the same figure window subplot(#rows, #cols, index) • >>x = 0:pi/100:2*pi; • subplot(2,2,1); • plot(x,sin(x)); • subplot(2,2,2); • plot(x,sin(x-0.25)); • subplot(2,2,3); • plot(x,sin(x-0.5); • subplot(2,2,4); • plot(x, cos(x));

23. Setting Aspect Ratio By default, MATLAB displays graphs in a rectangular axes that has the same aspect ratio as the figure window. >> t=0:pi/20:2pi; >> plot(sin(t), 2*cos(t)); >> grid on; >> axis square

24. Setting Aspect Ratio >> axis equal This produces an axes that is rectangular in shape, but has equal scaling along each axis.

25. Setting Aspect Ratio If you want the axes shape to conform to the plotted data, use the tight option in conjunction with equal: >> axis equal right

26. Loglog plot >> x = logspace(-1,2); >> loglog(x,exp(x), ‘-s’); >> grid on;

27. Loglog plot >> x = logspace(-1, 4); >> loglog(x,exp(x), ‘-s’); >> grid on;

28. semilogy >> x = 0:0.1:10; >> semilogy(x, 10.^x); >> grid on;

29. Two-Dimensional Stem Plots >>alpha = 0.02; >>beta = 0.5; >>t=0:4:200; >>y=exp(-alpha*t).*cos(beta*t); >>plot(t,y);

30. Two-Dimensional Stem Plots >>alpha = 0.02; >>beta = 0.5; >>t=0:4:200; >>y=exp(-alpha*t).*cos(beta*t); >>stem(t,y);

31. Two-Dimensional Stem Plots >>alpha = 0.02; >>beta = 0.5; >>t=0:4:200; >>y=exp(-alpha*t).*cos(beta*t); >>stem(t,y,’—sr’,’fill’);

32. Two-Dimensional Stem Plots >>y = 1988:1994;>>s = [ 8 12 20 22 18 24 27 ];>>stem(y,s);

33. Stairs plot >>x=0:pi/25:2*pi; >>y=sin(x); >>plot(x,y); >>hold on; >>stairs(x,y);

34. Stairs plot >>y = 1988:1994;>>s = [ 8 12 20 22 18 24 27 ];>>stairs(y,s);

35. plotyy Create graphs with y-axes on both left and right side >> x = 0:0.01:20; >> y1=200*exp(-0.05*x).*sin(x); >> y2=0.8*exp(-0.5*x).*sin(10*x); >> plotyy(x,y1,x,y2,’plot’);

36. plotyy >> t = 0:900; A = 1000; a = 0.005; b = 0.005; >>z1 = A*exp(-a*t); >>z2 = sin(b*t); >>plotyy(t,z1,t,z2,'semilogy','plot'); >> grid on;

37. plotyy x = 0:pi/20:2*pi; y = exp(sin(x)); plotyy(x,y,x,y,'plot','stem')

38. comet t= linspace(0,10*pi,20000); y=t.*cos(t); comet(t,y)

39. Plot3 Command The plot3 function displays a three-dimensional plot of a set of data points >> t=0:pi/50:10*pi; >>plot3(sin(t),cos(t)); >>grid on; >>axix square

40. Area graph >>area(Y)

41. Comparing Data Sets with Area Graphs Area graphs are useful for comparing different datasets. For example, given a vector containing sales figures, >>sales = [51.6 82.4 90.8 59.1 47.0]; for the five-year period >>x = 90:94; and a vector containing profits figures for the same five-year period, >>profits = [19.3 34.2 61.4 50.5 29.4]; >>area(x,sales,'FaceColor' ,[.5 .9 .6]); >>hold on; >>area(x,profits, 'FaceColor' ,[.9 .85 .7]);

42. Comparing Data Sets with Area Graphs

43. Bar plot >> x=-2.9:0.2:2.9; >>bar(x, exp(-x.*x),r);

44. Bar plot >> Y=randn(3,5); >>bar(Y);

45. Vertical bar plot >>y = 1988:1994; >>s = [ 8 12 20 22 18 24 27 ]; >>bar(y,s,'r'); Bar plot

46. Vertical bar plot >>y = 1988:1994; >>s = [ 8 12 20 22 18 24 27 ]; >>barh(y,s,‘g'); Bar plot

47. Bar plot >> Y=round(rand(5,3)*10); >>subplot(2,2,1); >>bar(Y, group); >>title Group; >>subplot(2,2,2); >>bar(Y, stack); >>title  Stack ; >>subplot(2,2,3); >>barh(Y, stack); >>title  Stack ; >>subplot(2,2,4); >>bar(Y, 1.5); >>title  Width =1.5 ;

48. Bar plot

49. Histogram plot >>x = randn(1,100);>>hist(x,10);

50. Histogram plot >>x = randn(1,100);>>hist(x,20);