Presentation is loading. Please wait.

Presentation is loading. Please wait.

MA/CS375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 4.

Similar presentations


Presentation on theme: "MA/CS375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 4."— Presentation transcript:

1 MA/CS375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 4

2 MA/CS375 Fall 2002 2 Plotting in Matlab

3 MA/CS375 Fall 2002 3 Example 5 (building and plotting a function of a vector) 1)create a vector x, with 50 equally spaced entries from 0 to 1.0 2)create a vector f, with entries of cosine evaluated at entries of 2*pi*x 3)plot f as a function of x, using + symbols

4 MA/CS375 Fall 2002 4 Example 5 (figure created by Matlab)

5 MA/CS375 Fall 2002 5 Example 5 (building and plotting a function of a vector) 1)create a vector x, with 50 equally spaced entries from 0 to 1.0 2)create a vector f, with entries of cos evaluated at entries of x 3)plot f as a function of x, using a blue line

6 MA/CS375 Fall 2002 6 Example 5 (figure created by Matlab)

7 MA/CS375 Fall 2002 7 Example 6 (building and plotting two functions of a vector) 1)create a vector x, with 50 entries from 0.0 to 1.0 2)create a vector f, with cos(2*pi*x). 3)create a vector g with entries sin(2*pi*x) 4)plot f as a function of x, using a blue line 5)on same graph plot g as a function of x, using red + symbols.

8 MA/CS375 Fall 2002 8 Example 6

9 MA/CS375 Fall 2002 9 Close Up of Example 6 code Instruct Matlab to keep the current graph window and its contents for the next plot.

10 MA/CS375 Fall 2002 10 Close Up of Example 6 code Instruct Matlab that you have finished plotting in the current graph window.

11 MA/CS375 Fall 2002 11 Quick Reference For Plot (Taken from Matlab: > help plot) Various line types, plot symbols and colors may be obtained with PLOT(X,Y,S) where S is a character string made from one element from any or all the following 3 colunms: y yellow. point - solid m magenta o circle: dotted c cyan x x-mark-. dashdot r red + plus -- dashed g green* star b blues square w white d diamond k black v triangle (down) ^ triangle (up) < triangle (left) > triangle (right) p pentagram h hexagram

12 MA/CS375 Fall 2002 12 Adding a Title, Labeling Axes and Legends Ok – so we have made a cool graph But it isn’t much use to anybody else unless you label everything in sight! The following functions will modify the current figure: title, xlabel, ylabel, legend

13 MA/CS375 Fall 2002 13 Example 7 The label commands

14 MA/CS375 Fall 2002 14 Details: Set up the legend box with descriptions of each curve: >> legend('f=cos(2*pi*x)', 'g=sin(2*pi*x)'); Label the axis >> xlabel('x'); Label the y-axis >> ylabel('f,g'); Give the graph a title >> title('The very boring graphs');

15 MA/CS375 Fall 2002 15

16 MA/CS375 Fall 2002 16 Modifying the Figure Properties So I am not so pleased by the default fonts used by Matlab. It is easy to change the font: In the figure window click on the text object you wish to change

17 MA/CS375 Fall 2002 17

18 MA/CS375 Fall 2002 18 Click on “Edit/Current Object Properties”

19 MA/CS375 Fall 2002 19 I prefer a larger Arial font

20 MA/CS375 Fall 2002 20

21 MA/CS375 Fall 2002 21 The Final Product

22 MA/CS375 Fall 2002 22 Alternative Ways To Change Fonts..

23 MA/CS375 Fall 2002 23

24 MA/CS375 Fall 2002 24 Individual Exercise 1)Create two curves on the same graph: F = 1/(1+x^2) G = exp(x^3) 2)Plot the points at 33 points equally spaced between 0 and 1 3)Use black *’s for F and green o’s for G 4)Label the horizontal and vertical axes 5)Create a title (including your name) 6)Create a legend 7)Make sure the font’s are legible for my old eyes (also figure out how to change the axis fonts) 8)Print out your graph and hand it in.

25 MA/CS375 Fall 2002 25 Plotting Two-Dimensional Data

26 MA/CS375 Fall 2002 26 Example 7 (Plotting Two-dimensional Data) 1)create two vectors x1d and y1d, with 20 entries from 0.0 to 1.0 2)create matrices of values using the x1d and y1d to distribute points in the unit square with 20 points in the x and y directions. 3)plot results in a graph.

27 MA/CS375 Fall 2002 27 Results From Example 7

28 MA/CS375 Fall 2002 28 Where are we going with this? We can evaluate a function at the two dimensional points (x2d,y2d) We can plot contours of this function where: a contour is a curve in the domain of the function where the value of the function is constant.

29 MA/CS375 Fall 2002 29 Example 8 (plotting contours of a two-dimensional function)

30 MA/CS375 Fall 2002 30 Example 9 (plotting two-dimensional function as a surface)

31 MA/CS375 Fall 2002 31 Example 9 cont. (plotting two-dimensional function as a smooth surface)

32 MA/CS375 Fall 2002 32 Summary of Lecture 4 We have learnt how to: – plot a graph – plot multiple graphs in the same window – improve the fonts – label everything in sight…. – plot contours of a two-dimensional function – plot a two-dimensional function as a surface


Download ppt "MA/CS375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 4."

Similar presentations


Ads by Google