Additional Plot Types and Plot Formatting

Similar documents
Matlab Tutorial 1: Working with variables, arrays, and plotting

Mechanical Engineering Department Second Year (2015)

PROGRAMMING WITH MATLAB WEEK 6

MATLAB Introduction to MATLAB Programming

INC151 Electrical Engineering Software Practice. MATLAB Graphics. Dr.Wanchak Lenwari :Control System and Instrumentation Engineering, KMUTT 1

Logical Subscripting: This kind of subscripting can be done in one step by specifying the logical operation as the subscripting expression.

Computer Programming in MATLAB

Department of Chemical Engineering ChE-101: Approaches to Chemical Engineering Problem Solving MATLAB Tutorial Vb

INTRODUCTION TO MATLAB PLOTTING WITH MATLAB

Chapter 3: Introduction to MATLAB Programming (4 th ed.)

Classes 7-8 (4 hours). Graphics in Matlab.

Introduction to MATLAB

STAT 391 Handout 1 Making Plots with Matlab Mar 26, 2006

Overview. Lecture 13: Graphics and Visualisation. Graphics & Visualisation 2D plotting. Graphics and visualisation of data in Matlab

Introduction to MATLAB: Graphics

Dr Richard Greenaway

Prof. Manoochehr Shirzaei. RaTlab.asu.edu

DSP Laboratory (EELE 4110) Lab#1 Introduction to Matlab

12 whereas if I terminate the expression with a semicolon, the printed output is suppressed.

Purpose of the lecture MATLAB MATLAB

Getting Started. Chapter 1. How to Get Matlab. 1.1 Before We Begin Matlab to Accompany Lay s Linear Algebra Text

What is Matlab? A software environment for interactive numerical computations

Basic Graphs. Dmitry Adamskiy 16 November 2011

Introduction to Matlab to Accompany Linear Algebra. Douglas Hundley Department of Mathematics and Statistics Whitman College

QUICK INTRODUCTION TO MATLAB PART I

PART 1 PROGRAMMING WITH MATHLAB

Interactive Computing with Matlab. Gerald W. Recktenwald Department of Mechanical Engineering Portland State University

fplot Syntax Description Examples Plot Symbolic Expression Plot symbolic expression or function fplot(f) fplot(f,[xmin xmax])

Graphics and plotting techniques

The Department of Engineering Science The University of Auckland Welcome to ENGGEN 131 Engineering Computation and Software Development

GUI Alternatives. Syntax. Description. MATLAB Function Reference plot. 2-D line plot

You can change the line style by adding some information in the plot command within single quotation marks.

2D LINE PLOTS... 1 The plot() Command... 1 Labeling and Annotating Figures... 5 The subplot() Command... 7 The polarplot() Command...

Introduction to Matlab for Engineers

1 Introduction to Matlab

MATLAB primer for CHE 225

Chapter 2 (Part 2) MATLAB Basics. dr.dcd.h CS 101 /SJC 5th Edition 1

Graphics Example a final product:

Dr. Iyad Jafar. Adapted from the publisher slides

CSE 123. Plots in MATLAB

MATLAB Fundamentals. Berlin Chen Department of Computer Science & Information Engineering National Taiwan Normal University

Lab #1 Revision to MATLAB

Basic Beginners Introduction to plotting in Python

Programming 1. Script files. help cd Example:

Chapter 2. MATLAB Fundamentals

ECE 202 LAB 3 ADVANCED MATLAB

This module aims to introduce Precalculus high school students to the basic capabilities of Matlab by using functions. Matlab will be used in

Introduction to Matlab

Introduction to Scientific Programming in MATLAB

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

Armstrong Atlantic State University Engineering Studies MATLAB Marina 2D Plotting Primer

1. Register an account on: using your Oxford address

Appendix A. Introduction to MATLAB. A.1 What Is MATLAB?

A General Introduction to Matlab

MATLAB Tutorial III Variables, Files, Advanced Plotting

MATLAB Modul 2. Introduction to Computational Science: Modeling and Simulation for the Sciences, 2 nd Edition

BioFuel Graphing instructions using Microsoft Excel 2003 (Microsoft Excel 2007 instructions start on page mei-7)

MATLAB Guide to Fibonacci Numbers

Scientific Computing with MATLAB 2. Graphics for Research & Publication

Microsoft Word for Report-Writing (2016 Version)

Chemistry 30 Tips for Creating Graphs using Microsoft Excel

AMS 27L LAB #2 Winter 2009

INTRODUCTION TO MATLAB

Matlab Tutorial and Exercises for COMP61021

Matlab Tutorial for COMP24111 (includes exercise 1)

18.02 Multivariable Calculus Fall 2007

Pre-Lab Excel Problem

ME422 Mechanical Control Systems Matlab/Simulink Hints and Tips

Chapter 3: Rate Laws Excel Tutorial on Fitting logarithmic data

Models for Nurses: Quadratic Model ( ) Linear Model Dx ( ) x Models for Doctors:

Graphics in MATLAB. Responsible teacher: Anatoliy Malyarenko. November 10, Abstract. Basic Plotting Commands

MATLAB Functions and Graphics

Plotting - Practice session

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

DataPlotClasses for REALBasic

SES123 Computer Methods Lab Procedures

Introduction to PartSim and Matlab

Getting Started with DADiSP

FF505/FY505 Computational Science. MATLAB Graphics. Marco Chiarandini

MATLAB PROGRAMMING LECTURES. By Sarah Hussein

Math 375 Natalia Vladimirova (many ideas, examples, and excersises are borrowed from Profs. Monika Nitsche, Richard Allen, and Stephen Lau)

TOPIC 6 Computer application for drawing 2D Graph

Creating a Basic Chart in Excel 2007

MATLAB Tutorial. 1. The MATLAB Windows. 2. The Command Windows. 3. Simple scalar or number operations

Torsional-lateral buckling large displacement analysis with a simple beam using Abaqus 6.10

Chemistry Excel. Microsoft 2007

ENV Laboratory 2: Graphing

Computing Fundamentals Plotting

PERI INSTITUTE OF TECHNOLOGY DEPARTMENT OF ECE TWO DAYS NATIONAL LEVEL WORKSHOP ON COMMUNICATIONS & IMAGE PROCESSING "CIPM 2017" Matlab Fun - 2

Page 1 of 7 E7 Spring 2009 Midterm I SID: UNIVERSITY OF CALIFORNIA, BERKELEY Department of Civil and Environmental Engineering. Practice Midterm 01

What is MATLAB? What is MATLAB? Programming Environment MATLAB PROGRAMMING. Stands for MATrix LABoratory. A programming environment

APPM 2460 PLOTTING IN MATLAB

PyPlot. The plotting library must be imported, and we will assume in these examples an import statement similar to those for numpy and math as

Technology Assignment: Scatter Plots

Part #6. A0B17MTB Matlab. Miloslav Čapek Filip Kozák, Viktor Adler, Pavel Valtr

Functions of Two Variables

ENED 1090: Engineering Models I Homework Assignment #2 Due: Week of September 16 th at the beginning of your Recitation Section

Lecture 6: Plotting in MATLAB

Basic plotting commands Types of plots Customizing plots graphically Specifying color Customizing plots programmatically Exporting figures

Lecturer: Keyvan Dehmamy

Transcription:

Additional Plot Types and Plot Formatting The xy plot is the most commonly used plot type in MAT- LAB Engineers frequently plot either a measured or calculated dependent variable, say y, versus an independent variable, say x MATLAB has huge array of graphics functions and there are many variations and options associated with plot() To find out more type:» help plot Special Forms of Plot Linear axes for both x and y are not always the most useful Depending upon the functional form we are plotting we may wish to use a logarithmic scale (base 10) for x or y, or both axes When a log axes is used the variable may range over many orders of magnitude, yet still show detail at the smaller values Table 2.4: Common variations of the plot command Command plot(x,y) semilogx(x,y) semilogy(x,y) loglog(x,y) Explanation Linear plot of y versus x Linear y versus log of x Log of y versus linear of x Log of y versus log of x Chapter 2: Additional Plot Types and Plot Formatting 2 19

Example: Plotting y = x 2 for 0 x 20» x = 0:.5:20;» y = x.^2;» subplot(2,2,1) % address plot in row 1/column 1» plot(x,y),grid,title('y = x^2 as linear/linear')» subplot(2,2,2) % address plot in row 1/column 21» semilogx(x,y),grid,title('y = x^2 as linear/log')» subplot(2,2,3) % address plot in row 2/column 1» semilogy(x,y),grid,title('y = x^2 as log/linear')» subplot(2,2,4) % address plot in row 2/column 2» loglog(x,y),grid,title('y = x^2 as log/log') Chapter 2: Additional Plot Types and Plot Formatting 2 20

Multiple (Overlay) Plots Using the basic command plot() we can easily plot multiple curves on the same graph The most direct way is to simply supply plot() with additional arguments, e.g., plot(x1,y1,x2,y2,...) Another way is to use the hold command plot(x1,y1) hold %turns plot holding on for the current %figure plot(x2,y2) hold %turns plot holding off for current figure Example: Plotting a family of polynomials, say for n = 1234,,, y = x n, 1 x 1» x = -1:.01:1;» plot(x,x),axis('square'),grid» hold Current plot held» plot(x,x.^2)» plot(x,x.^3)» plot(x,x.^4)» title('plots of y = x^n for n = 1, 2, 3, & 4','fontsize',16)» ylabel('y','fontsize',14), xlabel('x','fontsize',14) Chapter 2: Multiple (Overlay) Plots 2 21

Line and Mark Styles A wide variety of line and mark styles can be obtained by including a character string argument to plot() plot(x,y,s) where s is a character string ( a string ) composed of at most one element from each column of Table 2.5 The basic variations are line color, line style, and mark styles Chapter 2: Multiple (Overlay) Plots 2 22

Table 2.5: Graphics line style, line color, and mark options Line Color Marker (symbol) Style Line Style y yellow. point - solid m magenta o circle : dotted c cyan x x-mark -. dashdot r red + plus -- dashed g green b blue w white k black As an example, * star s square d diamond v triangle (down) ^ triangle (up) < triangle (left) > triangle (right) p pentagram h hexagram plot(x,y,'c+:') plots a cyan dotted line with a plus at each data point, while plot(x,y,'bd') plots blue diamond at each data point but does not draw any line Chapter 2: Multiple (Overlay) Plots 2 23

Example: Plotting a family of polynomials (continued). Here we will improve upon a previous multiple plot by coding the line types using markers (symbols) and MATLAB s legend command.» x = -1:.01:1;» plot(x,x),axis('square'),grid» hold Current plot held» plot(x,x.^2,'--')» plot(x,x.^3,':')» plot(x,x.^4,'-.')» legend('y = x','y = x^2','y = x^3','y = x^4')» title('plots of y = x^n for n = 1, 2, 3, & 4','fontsize',16)» ylabel('y','fontsize',14)» xlabel('x','fontsize',14) Chapter 2: Multiple (Overlay) Plots 2 24

Axis Scaling When creating plots in MATLAB the axes are initially automatically scaled Sometimes custom axis scaling is more desirable The axis command, which has a large variety of options (type help axis), allows the axis scaling to be changed following graph generation via axis([x_min,x_max,y_min,y_max]); Another useful command in this area is zoom command Chapter 2: Multiple (Overlay) Plots 2 25

The zoom command allows the user to zoom into an area of an existing graph by drawing a zoom rectangle with the mouse To turn zoom off for a particular figure window you type zoom again Subplots The subplot command allows a given figure window in MATLAB to be broken into a rectangular array of plots, each addressed with the standard plot commands The command subplot(m,n,p) or subplot(mnp) splits the graph (figure) window into an array of plots m-rows by n-columns, and addresses the pth subplot The subplot index p counts from left to right beginning with the upper left plot and ending with the lower right plot A 2x2 Array of Subplots subplot(221) subplot(223) subplot(222) subplot(224) The example on page 2-20 uses the subplot command Chapter 2: Multiple (Overlay) Plots 2 26

Problem Solving Applied The text has an excellent problem solving example that produces user defined plots of velocity and acceleration for an aircraft powered by a advanced turboprop engine called the unducted fan To provide an alternative example in the lecture notes we will solve text problem 9 on page 67 (you have been asked to solve problem 8) Problem Statement Generate a table with the conversions from Celsius to Rankin. Allow the user to enter the starting temperature and increment between table lines. Print 25 lines in the table. The conversions we need to solve the problem are: T F = T R 459.67 9 T F = --T 5 c + 32 Chapter 2: Problem Solving Applied 2 27

Input/Output Description Starting Temp. in Celsius Temp. Increment in Celsius A 25 line table of Celsius temps. co-listed with Rankin temps. Hand Example Consider 10 C From the two conversion equations given above Algorithm Development T R 459.67 9 --T 5 C + 32 We need to write a MATLAB.m file that will request the starting temperature and step size as inputs; we will use the input function for this To display the calculated values we will use disp = 9 T R = --T 5 C + 32 + 459.67 9 T R = -- 10 + 491.67 = 509.67 5 Chapter 2: Problem Solving Applied 2 28

%*********************cel2rank.m********************** % A MATLAB script file for generating a table of values % representing generator conversion from Celsius to Rankin. % Version 1.0 by Mark Wickert, September 1997. % start_temp = input('enter the starting temperature in Celsius: '); temp_step = input('enter the table temperature step in Celsius: '); % Perform calculations index = 1:25; T_Celsius = start_temp + (index-1)*temp_step; T_Rankin = 9/5*T_Celsius + 32 + 459.67; % Format data for plotting (quick easy way) disp([' Index#' ' T_Celsius' ' T_Rankin']) disp([index' T_Celsius' T_Rankin']) %*************End script file cel2rank.m*************** Testing A command window dialog session that sweeps through 10 C» cel2rank Enter the starting temperature in Celsius: 0 Enter the table temperature step in Celsius: 5 Index# T_Celsius T_Rankin 1.0000 0 491.6700 2.0000 5.0000 500.6700 3.0000 10.0000 509.6700 4.0000 15.0000 518.6700 5.0000 20.0000 527.6700 6.0000 25.0000 536.6700 7.0000 30.0000 545.6700 The Value Pre-calculated Checks Chapter 2: Problem Solving Applied 2 29

8.0000 35.0000 554.6700 9.0000 40.0000 563.6700 10.0000 45.0000 572.6700 11.0000 50.0000 581.6700 12.0000 55.0000 590.6700 13.0000 60.0000 599.6700 14.0000 65.0000 608.6700 15.0000 70.0000 617.6700 16.0000 75.0000 626.6700 17.0000 80.0000 635.6700 18.0000 85.0000 644.6700 19.0000 90.0000 653.6700 20.0000 95.0000 662.6700 21.0000 100.0000 671.6700 22.0000 105.0000 680.6700 23.0000 110.0000 689.6700 24.0000 115.0000 698.6700 25.0000 120.0000 707.6700 Chapter 2: Problem Solving Applied 2 30