MatLab – Palm Chapter 5 2-D & 3-D Plots

Slides:



Advertisements
Similar presentations
Lecture 5.
Advertisements

CSE 123 Plots in MATLAB. Easiest way to plot Syntax: ezplot(fun) ezplot(fun,[min,max]) ezplot(fun2) ezplot(fun2,[xmin,xmax,ymin,ymax]) ezplot(fun) plots.
Introduction to Engineering MATLAB – 11 Plotting - 4 Agenda Multiple curves Multiple plot.
Introduction to Graphing Using MATLAB. Line Graphs  Useful for graphing functions  Useful for displaying data trends over time  Useful for showing.
Matlab Graphics S. Awad, Ph.D. M. Corless, M.S.E.E. E.C.E. Department University of Michigan-Dearborn Introduction to Matlab: 2D Graphics.
MATLAB’s extensive, device-independent plotting capabilities are one of its most powerful features. They make it very easy to plot any data at any time.
MatLab – Palm Chapter 4, Part 3 For and While Loops
MATLAB - Lecture 22A Two Dimensional Plots / Chapter 5 Topics Covered:
EGR106 Week 6 MATLAB FILES Two Dimensional Plots Multiple Plots
Exam #3 Review: Comprehensive Exam Class 14.2 Palm Matlab Book Ch. 1-5.
EGR106 Week 5 MATLAB FILES Two Dimensional Plots Multiple Plots Plot Formatting Homework.
MATLAB Week 3 17 November Outline Graphics – Basic plotting – Editing plots from GUI – Editing plots from m-file – Advanced plotting commands.
EGR106 Week 4 Two Dimensional Plots Multiple Plots Plot Formatting Homework.
Introduction to MATLAB for Engineers, Third Edition Chapter 5 Advanced Plotting PowerPoint to accompany Copyright © The McGraw-Hill Companies, Inc.
An introduction to Plotting in MATLAB Rikard Johansson Department of Biomedical Engineering (IMT) Linköping University
EPSII 59:006 Spring Outline Managing Your Session File Usage  Saving Workspace  Loading Data Files  Creating M-files More on Matrices Review.
Designing Effective Graphics Using MATLAB The Cain Project in Engineering and Professional Communication ENGINEERING SERIES.
For loop Khairul anwar.
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
SUNY-New Paltz Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz “Lecture 5”
Plotting II: By the end of this class you should be able to: Create a properly formatted engineering graph Create graphs of a function Place multiple plots.
PLOTS AND FIGURES DAVID COOPER SUMMER Plots One of the primary uses for MATLAB is to be able to create publication quality figures from you data.
ENG College of Engineering Engineering Education Innovation Center 1 2D Plots 1 in MATLAB Topics Covered: 1.Plotting basic 2-D plots The plot()
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers Chapter 5 Advanced.
1 Advanced Plotting ผศ. ดร. อนันต์ ผลเพิ่ม Anan Phonphoem
CMPS 1371 Introduction to Computing for Engineers PLOTTING.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers Chapter 5 Advanced.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers Chapter 5 Advanced.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® Chapter 5 Advanced.
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.
ENG 1181 College of Engineering Engineering Education Innovation Center MATLAB – 2D Plots 1 Go to the class drive: ---> MatLab - Graphing ---> Seed Files.
Barak Shenhav Early Evolution Course 11 Feb 2001 MATLAB Visualization, Functions & Debugging.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers Chapter 5 Advanced.
EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,
2D Plots 2 ENGR 1181 MATLAB 13. Plotting in the Real World 2D plots generated by MATLAB can be used in a variety of fields, including the one shown here,
ELG 3120 Lab 2 TAs Wei Zhang Ozgur Ekici (Section A) (Section B)
1 Lecture 5 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Introduction to Engineering MATLAB – 9 Plotting - 2 Agenda Formatting plots.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers Chapter 5 Advanced.
MATLAB ® for Engineers, Holly Moore Fourth Edition, Global Edition © Pearson Education Limited 2015 All rights reserved. Figure 5.1 Simple Plot of Time.
Figures & Axes, Printing & Saving. Outline Announcements –Homework I on web, due Wed. 5PM by –No lecture on Fri. 10/26, rescheduled to Wed. 10/31.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Lab 2 : potting to Matlab Networks.
Figures & Axes, Printing & Saving. Outline Announcements –Homework I on web, due Wed. 5PM by e- mail A word on HWI and cookies What happens when you plot.
EGR 106 – Week 5 – 2-D Plots Question : Why do engineers use plots? Answer : To analyze, visualize, and present data. Matlab has many useful plotting options.
Session III Plotting in MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU MATLAB Tutorials.
Creating a Plot The plot function can take one or more inputs; e.g. plot (x, y) or plot (y) Note that in the two-argument version, the vectors x and.
Plots and Graphics.
Computer Application in Engineering Design
Plotting Chapter 5.
3D-Graphs A 3D surface is defined as: z = f(x, y)
Lecture 25.
Ch3 Graphics Overview of Plotting Editing Plots
Lecture 25: Exploring data
Matlab for Engineering Applications
Net 222: Communications and networks fundamentals (Practical Part)
Introduction to MATLAB 7
MATLAB How to use (using M-files) Double click this icon
Warmup NO CALCULATORS Convert into radians or degrees.
MATLAB How to use (using M-files) Double click this icon
MatLab – Palm Chapter 5 Curve Fitting
MatLab – 2D Plots 2 MATLAB has many built-in functions and commands to create various types of plots. Instructor notes: We start with an example of some.
Plotting Data with MATLAB
MATLAB How to use (using M-files)
CSCI N317 Computation for Scientific Applications Unit 1 – 5 MATLAB
Introduction to Matlab
Plotting Signals in MATLAB
Designing Effective Graphics Using MATLAB
How to Use MATLAB A Brief Introduction.
Introduction to Matlab
Presentation transcript:

MatLab – Palm Chapter 5 2-D & 3-D Plots Class 13.1 Palm Chapter: 5.1-5.4 & 5.8 9/20/2018 ENGR 111A Fall 2004

RAT 13.1 As in INDIVIDUAL you have 2 minutes to answer the following question. What is the result of the following subplot and plot commands: x = [0:5]; y = x.^2; subplot(2,2,4) plot(x,y) Answer: Creates a plot of y vs. x on a figure window with four “panes”. This plot would be in the lower, right pane of the figure window. 9/20/2018 ENGR 111A Fall 2004

Solution 9/20/2018 ENGR 111A Fall 2004

Learning Objectives for Today’s Class Students should be able to: Use the 2-D (X-Y) Plotting Functions. Make Subplots and Overlay Plots. Use Special Plot Functions. Use the Plot Editor. Use the 3-D (X-Y-Z) Plot Functions. 9/20/2018 ENGR 111A Fall 2004

Good Plotting Practices Each axis must be labeled with the name of quantity plotted and units Axes should have tick marks at regular, convenient intervals Label multiple lines or include legend Use a title if needed Plot each measured data point with a symbol Use lines between data points to improve readability, but with caution Do not plot points if the curve is generated from a continuous function All fonts must be 8pt or greater at the final printed size GOOD NEWS: Matlab does most of this automatically! 9/20/2018 ENGR 111A Fall 2004

Example Plots Matlab Default Mixed fonts Plot markers on curve Smaller fonts, but uniform size 9/20/2018 ENGR 111A Fall 2004

Important Plot Commands plot(xdata,ydata,’csl’,’prop1’,val1,…) grid on; grid off title(‘Put title here’) xlabel(‘Use ^ for superscripts’) ylabel(‘Use _ for subscripts’) legend(‘Line 1’, ‘Line 2’, …) axis – lots of variants. axis square, axis equal, axis auto axis([xmin, xmax, ymin, ymax]) See online HELP 9/20/2018 ENGR 111A Fall 2004

In-Class Exercise 13.1-1 (10-min) Individually solve T5.1-1 A. First, using plot() commands. B. Using fplot() (see page 266). Remember to label axes, pay attention to fonts, etc. Experiment with various axis and grid commands. Also try semilogy(), semilogx(), and loglog()instead of plot() 9/20/2018 ENGR 111A Fall 2004

Solution using plot() x = 0:0.1:35; y = 0.4*sqrt(1.8*x); plot(x, y, ‘r-’) axis([0 35 0 3.5]) title(‘Rocket trajectory’) xlabel(‘Distance [miles]’) ylabel(‘Height [miles]’) grid on 9/20/2018 ENGR 111A Fall 2004

Solution 9/20/2018 ENGR 111A Fall 2004

Solution using fplot() f = ‘0.4 * sqrt(1.8*x)’ fplot(f, [0 35]) axis([0 35 0 3.5]) title(‘Rocket trajectory’) xlabel(‘Distance [miles]’) ylabel(‘Height [miles]’) grid on 9/20/2018 ENGR 111A Fall 2004

5.2 Subplots and Overlay Plots (p. 271) subplot(rows, cols, plot_num) hold on; hold off text(xpos, ypos, ‘text label’) print fname.ps % creates % postscript file Also use edit-copy figure Beware that what you see is not necessarily what you get 9/20/2018 ENGR 111A Fall 2004

In-Class Exercise 13.1-2 (10-min) Individually work T5.2-2 on p. 280 Pay attention to the section Hints for Improving Plots on p. 281-282. 9/20/2018 ENGR 111A Fall 2004

Solution x = [0 1 2 3 4 5]; y1 = [11 13 8 7 5 9]; y2 = [2 4 5 3 2 4]; plot(x, y1, 'ko-') hold on plot(x, y2, 'kd--') legend('Data set 1', 'Data set 2') xlabel('Independent variable [--]') ylabel('Dependent variable [--]') 9/20/2018 ENGR 111A Fall 2004

Solution, continued 9/20/2018 ENGR 111A Fall 2004

5.3 Special Plot Types (p. 282) loglog(x, y, ‘csl’) semilogx(x, y, ‘csl’) semilogy(x, y, ‘csl’) plotyy(x1, y1, ‘csl’, x2, y2, ‘csl’) 9/20/2018 ENGR 111A Fall 2004

Matlab Handles Handle: an index that relates to an object so that its properties can be changed. h = plot(x,y) set(h) will list all the things that can be set get(h) will list all current settings set(h,‘Property’, value) changes settings 9/20/2018 ENGR 111A Fall 2004

Automatic handles Just like ans stores answers in a default variable, figure handles are stored automatically. gca “get current axes” : handle to the current set of axes. gcf “get current figure” : handle to the current figure. 9/20/2018 ENGR 111A Fall 2004

Labeling plotyy() axes ax = plotyy(x1, y1, x2, y2) axes(ax(1)) ylabel(‘y1 label’) axes(ax(2)) ylabel(‘y2 label’) 9/20/2018 ENGR 111A Fall 2004

In-Class Exercise 13.1-3 (10-min) Individually solve T5.3-1 on p. 291 You may learn how to use the Plot Editor (section 5.4) on your own to edit your plots. 9/20/2018 ENGR 111A Fall 2004

Solution x = 0:0.01:1.5; yp = 2*x.^(-0.5); ye = 10.^(1-x); subplot(2,2,1) plot(x, yp, 'k-', x, ye, 'k--') axis([0 1.5 0 20]) xlabel('x') ylabel('y') text(0.1, 2, 'Power') text(0.3, 7, 'Exponential') set(gca,'XTick',[0.5:0.5:1.5]) subplot(2,2,2) semilogy(x, yp, 'k-', x, ye, 'k--') axis([0 1.5 0 20]) xlabel('x') ylabel('y') text(0.4, 0.6, 'Exponential') text(0.8, 3, 'Power') set(gca,'XTick',[0.5:0.5:1.5]) set(gca,'YTick',[1 10]) subplot(2,2,3) loglog(x, yp, 'k-', x, ye, 'k--') axis([0.01 1.5 0.1 20]) text(0.05, 2.5, 'Power') text(0.13, 10, 'Exponential') set(gca,'XTick',[0.01 0.1 1]) 9/20/2018 ENGR 111A Fall 2004

Solution, continued 9/20/2018 ENGR 111A Fall 2004

5.4 The Plot Editor (p. 292) Sometimes it may be easier to work on plots using the plot function, etc. The Plot Editor is a good way to move text around, alter plot scales, add tick marks, etc. Rotating plots is VERY tricky. Read through pages 292-298 and practice the various features. 9/20/2018 ENGR 111A Fall 2004

5.4 The Plot Editor (contd.) Practice copying a figure (use one that you have just created) and paste it in a Word file. Use the Copy Figure option in the Edit menu on the figure window. 9/20/2018 ENGR 111A Fall 2004

5.8 3-D Plots (p. 334) 3-D plots are a lot like 2-D plots; just add the z-axis parameters. There are three kinds of 3-D plots: Three Dimensional Line Plots (p. 334). Surface Mesh Plots (p. 335). Contour Plots (p. 337). 3-D plot functions are in Table 5.8-1 (p. 338). 9/20/2018 ENGR 111A Fall 2004

Surface plots For x = xmin : dx : xmax And y = ymin : dy : ymax Use [x, y] = meshgrid(x, y) to generate a grid to calculate z on Then use, for example: z = x.^2 + y.^2 mesh(x, y, z) % or surf(x, y, z) 9/20/2018 ENGR 111A Fall 2004

Contour plots To label contours, use clabel: x = xmin : dx : xmax y = ymin : dy : ymax [x, y] = meshgrid(x, y) z = ??? [cs, h] = contour(x, y, z) clabel(cs, h) 9/20/2018 ENGR 111A Fall 2004

In-Class Exercise 13.1-4 (10-min) Finally, work T5.8-1 on p. 339. Plot the data for x & y values from -5 to 5 in 0.5 increments and the z values from -20 to 125. Be sure to label the contours on the contour plot. 9/20/2018 ENGR 111A Fall 2004

Solution [x, y] = meshgrid(-5:0.5:5) z = (x-2).^2 + 2*x.*y + y.^2; subplot(2,2,1) surf(x,y,z) xlabel('x') ylabel('y') zlabel('z') axis([-5 5 -5 5 -20 125]) subplot(2,2,2) [cs,h] = contour(x,y,z) clabel(cs,h) 9/20/2018 ENGR 111A Fall 2004

Solution, continued 9/20/2018 ENGR 111A Fall 2004

Assignment 13.1 Individual assignment. Palm MatLab – Chapter 5 (starting on p. 344): # 19, 25, 50. Due: In one week. Reading Assignment – Sections 5.5 to 5.7. 9/20/2018 ENGR 111A Fall 2004