{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture+05+Presentation

# Lecture+05+Presentation - 14:440 127 Introduction to...

This preview shows pages 1–12. Sign up to view the full content.

14:440: 127 Introduction to Computers for Engineers Lecture 5 Lecturer: Brenda Cortez Recitation Instructors: Yun, Bo, Karthik, Muhammad

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Rutgers School of Engineering 14:440:127 General Announcements HW01 - DONE & GRADED PROJ01 - DONE & GRADED BY TODAY EXAM01 - LAST DAY TODAY No office Hours on TUESDAYS o/w Open Door Policy active HW02 Assigned this Wednesday Missing something? I have a wallet, cell phone, and RUIDs in my office apps.rutgers.edu - try it out again and answer bi-weekly polls on Sakai 2
Rutgers School of Engineering 14:440:127 Topic for today: Plotting 2D, 3D, Meshgrid, Log plots Graphical Input Interpolation Regression Fitting Equation to Data 3

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
14:440:127 2D Plots What do you need? - X points - Y points >> xpoints = linspace(1,10,20); >> ypoints = rand (1,20)*10; Obviously size(x)==size(y) has to be true, so that you can have corresponding points. Now Plot! >> plot (xpoints, ypoints) 4 returns a vector of rand om numbers of size ( rows , cols ) from 0 to 1
14:440:127 Plot Labels & Grid >> xpoints2 = 1:5:50; >> ypoints2 = x .^ 3; >> plot (xpoints2, ypoints2) >> title ( ʻ X Cubed! ʼ ) >> xlabel ( ʻ X points ʼ ) >> ylabel ( ʻ Y points ʼ ) >> grid on 5 Only if you want to have a grid look, otherwise, the plot will be on a white background

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
14:440:127 Multiple Figures Sometimes, you need to visualize data in different windows, but at the same time, so you must create the figure separately and THEN plot. figure (1) plot (xpoints, ypoints) figure (2) plot (xpoints2, ypoints2) 6 If you want to overwrite a plot, simply use the figure ʼ s number: figure (1) plot (xpoints2, ypoints2)
14:440:127 Multiple graphs in ONE figure - Method 1 >> x1 = 1:0.1:10; >> x2 = 1.5:0.1:10; >> y1 = 3*x1 .^ 2; >> y2 = 3.5*x2 .^ (1.5); >> plot ( x1 , y1 , x2 , y2 ) 7 But we need to distinguish between the two, so we can use legend to distinguish. legend ('first line', 'second line')

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
14:440:127 Multiple Graphs in ONE figure - Method 2 >> x1 = 1:0.1:10; >> x2 = 1.5:0.1:10; >> y1 = 3*x1 .^ 2; >> y2 = 3.5*x2 .^ (1.5); >> plot (x1, y1) >> hold on >> plot (x2, y2) >> hold off 8 However, the legend command does not work too well.
14:440:127 Common Error Suppose you have your X and Y points and you do the following: plot (x) % OR plot (y) This will work, but it is wrong if you are trying to plot y against x. It works because: this plots x OR y against their indices Example: x=1:2:10; 9 1 3 5 7 9 the values in x 1 2 3 4 5 indices of the elements in x

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
14:440:127 Subplots To create the figure on which to plot using subplot you must first define the size of this figure, in other words, how many slots to plot on. Syntax: subplot ( rows , columns ) Examples: subplot ( 2 , 2 ) subplot ( 3 , 4 ) subplot ( 3 , 1 ) 10 loc=1 loc=2 loc=3 loc=4 loc=1 loc=2 loc=3 loc=4 loc=5 loc=6 loc=7 loc=8 loc=9 loc=10 loc=11 loc=12 loc=1 loc=2 loc=3
14:440:127 Subplots >> x = linspace(0,10,100); >> y1 = x; >> y2 = x.^2; >> y3 = x.^3; >> y4 = x.^4; % plotting on slot 1 of the plot window >> subplot (2,2,1); plot (x,y1);title('y=x'); % you can also do it this way >> subplot (2,2,1); >> plot(x,y1); >> title('y=x'); % but this saves space if you have a lot to plot >> subplot (2,2,2); plot (x,y2);title('y=x^2'); >> subplot (2,2,3); plot (x,y3);title('y=x^3'); >> subplot (2,2,4); plot (x,y4);title('y=x^4'); 11 Common Error: To plot before subplotting plot(x,y2) subplot(2,2,2) Common Error: To plot on a subplot that doesn ʼ t exist plot(x,y4) subplot(2,2, 5 )

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}