Lecture 3 for Math 398 Section 952: Graphics in Matlab

Similar documents
A Tour of Matlab for Math 496, Section 6

MATLAB Laboratory 09/23/10 Lecture. Chapters 5 and 9: Plotting

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

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

FF505/FY505 Computational Science. MATLAB Graphics. Marco Chiarandini

Math Sciences Computing Center. University ofwashington. September, Fundamentals Making Plots Printing and Saving Graphs...

W1005 Intro to CS and Programming in MATLAB. Plo9ng & Visualiza?on. Fall 2014 Instructor: Ilia Vovsha. hgp://

Dr. Iyad Jafar. Adapted from the publisher slides

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

AMS 27L LAB #2 Winter 2009

CSE 123. Plots in MATLAB

INTERNATIONAL EDITION. MATLAB for Engineers. Third Edition. Holly Moore

GRAPHICS AND VISUALISATION WITH MATLAB

EGR 102 Introduction to Engineering Modeling. Lab 05B Plotting

Introduction to MATLAB

MAT 275 Laboratory 1 Introduction to MATLAB

Introduction to MATLAB: Graphics

Introduction to Matlab for Engineers

1 >> Lecture 4 2 >> 3 >> -- Graphics 4 >> Zheng-Liang Lu 184 / 243

6 Appendix B: Quick Guide to MATLAB R

Mechanical Engineering Department Second Year (2015)

Plotting x-y (2D) and x, y, z (3D) graphs

EXERCISES Introduction to MATLAB: Graphics

MATLAB Tutorial. Primary Author: Shoumik Chatterjee Secondary Author: Dr. Chuan Li

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

Name: Math Analytic Geometry and Calculus III - Spring Matlab Project - due on Wednesday, March 30

Computing Fundamentals Plotting

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

Prof. Manoochehr Shirzaei. RaTlab.asu.edu

Lab of COMP 406 Introduction of Matlab (II) Graphics and Visualization

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

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

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

Graded Assignment 2 Maple plots

Plotting - Practice session

Introduction to Simulink

Matlab Handout Nancy Chen Math 19 Fall 2004

Maple Commands for Surfaces and Partial Derivatives

Contents. Implementing the QR factorization The algebraic eigenvalue problem. Applied Linear Algebra in Geoscience Using MATLAB

APPM 2460 PLOTTING IN MATLAB

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

By Edward Grossman Edited and Updated by Mark Turner

INTRODUCTION TO MATLAB PLOTTING WITH MATLAB

What is MATLAB? It is a high-level programming language. for numerical computations for symbolic computations for scientific visualizations

Introduction to MATLAB Practical 1

Getting Started with MATLAB

y= sin( x) y= cos( x)

MATLAB basic guide to create 2D and 3D Plots. Part I Introduction

TOPIC 6 Computer application for drawing 2D Graph

MATLAB BASICS. < Any system: Enter quit at Matlab prompt < PC/Windows: Close command window < To interrupt execution: Enter Ctrl-c.

The College of Staten Island

Lecture 6: Plotting in MATLAB

CCNY. BME 2200: BME Biostatistics and Research Methods. Lecture 4: Graphing data with MATLAB

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

For your convenience Apress has placed some of the front matter material after the index. Please use the Bookmarks and Contents at a Glance links to

More on Plots. Dmitry Adamskiy 30 Nov 2011

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX

MATH 2221A Mathematics Laboratory II

MATLAB. Input/Output. CS101 lec

Calculus III. 1 Getting started - the basics

PC-MATLAB PRIMER. This is intended as a guided tour through PCMATLAB. Type as you go and watch what happens.

1 Introduction to Matlab

Table of Contents. Introduction.*.. 7. Part /: Getting Started With MATLAB 5. Chapter 1: Introducing MATLAB and Its Many Uses 7

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

Basic Graphs. Dmitry Adamskiy 16 November 2011

CSE/NEUBEH 528 Homework 0: Introduction to Matlab

Computer Programming in MATLAB

Use Geometry Expressions to create and graph functions, and constrain points to functions.

3 An Introductory Demonstration Execute the following command to view a quick introduction to Matlab. >> intro (Use your mouse to position windows on

ECE 3793 Matlab Project 1

MATLAB Guide to Fibonacci Numbers

Pre-Lab Excel Problem

Parametric Curves and Polar Coordinates

Parametric Curves and Polar Coordinates

Introduction to the MATLAB SIMULINK Program

MAT 343 Laboratory 4 Plotting and computer animation in MATLAB

Introduction to Matlab Graeme Chandler

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

Goals: Course Unit: Describing Moving Objects Different Ways of Representing Functions Vector-valued Functions, or Parametric Curves

How to learn MATLAB? Some predefined variables

Laboratory 1 Introduction to MATLAB for Signals and Systems

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

Introduction to MATLAB

Technology Assignment: Scatter Plots

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

Introduction to MATLAB

% Close all figure windows % Start figure window

Fondamenti di Informatica Examples: Plotting 2013/06/13

Introduction to Python Practical 1

2.0 MATLAB Fundamentals

Basic Plotting. All plotting commands have similar interface: Most commonly used plotting commands include the following.

Chapter 2 Vectors and Graphics

10.1 Curves Defined by Parametric Equations

Introduction to MATLAB

Math 1525 Excel Lab 1 Introduction to Excel Spring, 2001

NatSciLab - Numerical Software Introduction to MATLAB

Graphics Example a final product:

Getting Started with MATLAB

3D plot of a surface in Matlab

Eric W. Hansen. The basic data type is a matrix This is the basic paradigm for computation with MATLAB, and the key to its power. Here s an example:

Transcription:

Lecture 3 for Math 398 Section 952: Graphics in Matlab Thomas Shores Department of Math/Stat University of Nebraska Fall 2002 A good deal of this material comes from the text by Desmond Higman and Nicholas Higman, Matlab Guide, SIAM, Philadelphia, 2000. Two Dimensional Graphics Basic Graphics Start Matlab. We ll plot as usual, but get help to guide us along. The plot command has many options. We ll hit the highlights. We ll also keep a help window open so we can peruse the help files as we go. After we open it, we ll move it to a corner. helpwin Now click on plot in the Help Window and examine the possibilities for the 1-3 character string S. x = 0:0.01:1; % create array of abscissas and supress output y1 = 4*x.*(1- x); plot(x, y1, r+: ) A plot with multiple curves is possible without doing a hold on : plot(x, y1, r+:, x, y2, g ) We can make it fancier. For example xlabel( x ) ylabel( y ) title( Comparison of 4x(1-x) and sin(\pi x). ) As a matter of fact, you can massage your plot window quite a bit with the tools available in the tool bar. For example, click on the arrow icon and then draw an arrow on the inside of the curves pointing to the inner curve. Then click on the A icon (A for ascii) and click at the base of the arrow. Then type in 4*x*(1-x). There are lots of other things one can do to a graph from the graph window itself. You can even save your figures to many different formats. Click on the File button, then the menu choice Export. Select under Save as type: the choice Portable Document Format. Then browse to the directory you want, edit the name of the file, say to junk.pdf. Then click on Save. Now use the Windows Explorer to find the file you ve created and double click on it. Acrobat will now show you your picture. There are a number of alternates to the plot command as well. Look in the Help Window. There s even an ezplot which is a Maple rip-off (or is it the other way around?).try these: 1

ezplot( 4*x*(1-x) ) polar(x,y2) Interesting. Let s stretch it out. x = 0:0.01:60; polar(x,y2) Axes and Other Controls There are other ways to massage your graph. For example, start with ezplot( 4*x*(1-x) ) hold on ezplot( sin(pi*x) ) Not very good. Let s fiddle it a bit: axis equal axis off axis([0 1 0 1.2]) axis on Well, let s just do it again: x = 0:.01:1; y1 = 4*x*(1-x); plot(x,y1, --, x, y2, r: ) legend( 4x(1-x), sin(\pi x) ) title( \it Comparison of 4x(1-x) and sin(\pi x) ) What do you notice about the graph? Multiple Plots Here is the way to construct multiple plots, along with another variation on plot: subplot(2,2,1) plot(x,y1) subplot(222) fplot( sin(x), [0 1]) subplot(223) fplot( sin(round(2*pi*x)), [0 1], r-- ) subplot(224), polar(x,y2) 2

Three Dimensional Graphics Curves and Surfaces This gets a bit more complicated. Let s start with a 3-D parametric curve. t = -5: 0.005: 5; x = (1+t.^2).*sin(20*t); y = (1+t.^2).*cos(20*t); z = t; plot3(x,y,z) grid on xlabel( x(t) ), ylabel( y(t) ), zlabel( z(t) ) title ( A {\it plot3} example ) Now try the Tools button on the Figure window and click Rotate 3D. Then go to the figure with the cursor and move it about. For functions of two variables, there are many graphing possibilities. Try the Help window for graph3d. One possibility is simply to do the graph. For example, suppose we want to see a surface graph of f(x, y) = sin(3y x 2 + 1) + cos(2y 2 2x) on the square 1 y 1, 2 x 2. The first problem is to generate a suitable mesh of x- and y-coordinates. Do the following: x = -2:.01:2; y = -1:.01:1; [X,Y] = meshgrid(x,y); Z = sin(3*y - X.^2 + 1) + cos(2*y.^2-2*x); subplot(311) plot3(x, Y, Z) subplot(312) mesh(x, Y, Z) Contour Graphs There is another approach, namely the idea of level curves subplot(313) contour(x,y,z,20) There is also an ezcontour that does things automatically subplot(312) ezcontour( sin(3*y-x^2+1)+cos(2*y^2-2*x),[-2 2-1 1]) Some Specialized Graphs One can do bar graphs, pie graphs and area graphs. We ll just do a simple bar graph with the following calculations: 3

Y = [7 6 5; 6 8 1; 4 5 9; 2 3 4; 9 7 2] subplot(2,2,1) bar(y) title( bar(..., grouped ) ) subplot(2,2,2) bar(0:5:20,y) title( bar(..., grouped ) ) subplot(2,2,3) bar(y, stacked ) title( bar(..., stacked ) ) subplot(2,2,4) barh(y) title( barh ) Handle Graphics Getting a Handle on Things Matlab graphics are strongly object oriented. Graphics builds everything from objects, organized into a hierarchy which is tree structured with the root object as the top parent. Every object has properties, that control its appearance and behavior. For example, close all graphics windows and type clear plot(1:10, o- ) h = findobj What is returned are the handles (this is like a pointer or index) to all current objects. Of course, the first handle refers to root. The second is that of the subobject figure that we drew, etc. To get all the types, type get(h, type ) To see the properties of, say the axes, type set(h(3)) This is a huge subject, and we ll just do one very simple application. Suppose we want to work with two figures. Here s how, from the object point of view. fig1 = h(2) fig2 = figure % create a new figure and get it s handle as fig2 ezplot( x*sin(x), [0 10]) grid Now suppose you want to address the first figure; make it active by the command: figure(fig1) 4

grid There is another, more GUI oriented, way to examine and manipulate objects and properties: either click on the Edit button in the figure in question, then click on Figure Properties, or type this command: propedit(fig1) Either way, you get a Property window. Now suppose you want to endow the window containing your figure with a title. Click on the Title tab, then simply type in your new title and click on Apply. Once open, you can use the propedit window to edit any object. Click on the down arrow of the Edit Properties For box and select the object axis. Now click on the labels tab, and change the Figure title to whatever you want. Browse around a bit, and you ll find just about any property that you would want to modify. Animation One can animate by either saving a sequence of figures and replaying them as a movie, or by manipulating the XData, YDate and ZData properties of objects. Here is the movie approach: figure for j = 1:20 ezsurf( sin(x*y), [-2-5+0.5*j 2-5+0.5*j -2 2]); M(j) = getframe; end delete(gcf) disp( Here comes the movie ) movie(m) The second type of animation can be obtained, e.g., by using the comet function: x = -20:.01:20; y=x.*sin(x); comet(x,y) End of Lesson 5