NatSciLab - Numerical Software Introduction to MATLAB
|
|
- Lee Nash
- 6 years ago
- Views:
Transcription
1 Outline NatSciLab - Numerical Software Introduction to MATLAB Onur Oktay Jacobs University Bremen Spring 2010
2 Outline 1.m files 2 Programming Branching (if, switch) Loops (for, while) 3 Anonymous functions 4 Basic Graphing Curve plotting (plot,plot3,contour) Surface plotting (surf, mesh) 5 Efficient coding - Vectorization
3 Outline 1.m files 2 Programming Branching (if, switch) Loops (for, while) 3 Anonymous functions 4 Basic Graphing Curve plotting (plot,plot3,contour) Surface plotting (surf, mesh) 5 Efficient coding - Vectorization
4 .m files An m-file is a plain text file that contains MATLAB commands, with the filename extension.m. There are 2 types of m-files, scripts and functions. You can start an m-file by typing >> edit filename An m-file should be saved in the current directory or in the path in order to be executed. The path is just a list of directories in which MATLAB will look for files. Use editpath command to see and change the path. There is no need to compile m-files.
5 Script.m files The contents of a script m-file are literally interpreted as if they were typed at the prompt. If you want to repeat a group of lines various times, it is more convenient to write and save those lines in a script than using the prompt. Type >> run filename at the command line to run the script filename.m Some good reasons to use scripts are - Revising a group of more than four or five lines. - Reproducing your work at a later time. - Running a CPU-intensive job in the background.
6 Function.m files Function m-files are used to write and store often complicated numerical functions. Each function starts with a line such as function [out1,out2] = myfun(in1,in2,in3) The variables in1, in2, in3 are input arguments, and out1, out2 are output arguments. You can have as many input and output arguments as you like. Most of the functions built into MATLAB (except core math functions) are themselves m-files, which you can read and copy.
7 Function.m files A simple example of a function m-file: quadformula.m function [x1,x2] = quadformula(a,b,c) d = sqrt(bˆ2-4 a c); x1 = (- b + d) / (2 a); x2 = (- b - d) / (2 a); On the prompt, type >> [r1,r2] = quadformula(1,-2,1) r1 = 1 r2 = 1
8 Function.m files - Subfunctions A single m-file may hold more than one function definition. The function header at the first line of an m-file defines the primary function. All others are subfunctions. function [x1,x2] = quadformula(a,b,c) % primary function d = discrim(a,b,c); x1 = (-b + d) / (2*a); x2 = (-b - d) / (2*a); end function D = discrim(a,b,c) % subfunction D = sqrt(bˆ2-4*a*c); end
9 Function.m files - defaults nargin: Number of input arguments. Set default values for the inputs that are not provided. nargout: Number of output arguments. Set default action if one or more outputs are not called. An example: sincab.m function y = sincab(t,a,b) if nargin< 2; a=1; end % default value a=1 if nargin< 3; b=2; end % default value b=2 y = sin(t.ˆa)./(t.ˆb); if nargout==0; % default action: plot if no output is called figure; plot(t,y); end end
10 Script or Function? Functions have their own local workspace. Scripts use the main workspace. Function Script Q1 No Yes Q2 No Yes Q1: Are the variables in the main workspace visible? Q2: When executed, do the variables created appear in the main workspace? Functions are faster than scripts. - Functions are compiled into memory when executed for the first time. Subsequent invocations skip this interpretation step. - No matter how many times you execute the same script, MATLAB must spend time parsing your syntax. Functions require all inputs and outputs to be stated. Use scripts for attention-free execution.
11 Outline 1.m files 2 Programming Branching (if, switch) Loops (for, while) 3 Anonymous functions 4 Basic Graphing Curve plotting (plot,plot3,contour) Surface plotting (surf, mesh) 5 Efficient coding - Vectorization
12 if/else structure if (condition 1 true) statement 1 elseif (condition 2 true) statement 2 elseif (condition 3 true) statement 3. else default statement end
13 factorialscript.m Example if isreal(x) % if x is not real error ( x cannot be a complex number ); elseif (x < 0) error ( x cannot be a negative number ); elseif (x > 1000) error( x is too large ); elseif (x > 0) & (x = round(x)) % if x is not equal to round(x) disp( decimal part of x will be ignored ); factorial = prod(1:x); else factorial = prod(1:x); end
14 switch/case structure switch variable case value1 statement 1 case value2 statement 2 case value3 statement 3. otherwise default statement end equivalent to if variable == value1; statement 1 elseif variable == value2; statement 2 elseif variable == value3; statement 3. else default statement end Note: Unlike the C language switch statement, the MATLAB switch does not fall through. If the first case statement is true, the other case statements do not execute.
15 switch/case switch mod(x,6) case 0 xnew = x/6; case {1, 5} xnew = xˆ2-1; case 4 xnew = x/2; otherwise xnew = xˆ2 + 2; end if (mod(x,6)==0) xnew = x/6; elseif (mod(x,6)==1) (mod(x,6)==5) xnew = xˆ2-1; elseif (mod(x,6)==4) xnew = x/2; else xnew = xˆ2 + 2; end
16 Loops: for & while structure for var = vector statement end Use if it is necessary to repeat the statement a fixed number of times. Example: find sum of all prime numbers < 100 x = 1:100; s = 0; for k = 1:100; s = s + x(k)*isprime(x(k)); end structure while (condition true) statement end Use if it is necessary to repeat the statement based on a condition. Example: find sum of all prime numbers < 100 x = 1; s = 0; while (x < 100) s = s + x * isprime(x); x=x+1; end
17 Loops: for & while Its a good idea to limit the number of repetitions to avoid infinite loops. Use for loops rather than while loops. Maxiter = 100; % Number of repetitions for n = 1:Maxiter x = pi sin(x); end Use break. A break immediately ends the loop, and jumps to the first line after the loop. n = 0; Maxiter = 100; % Number of repetitions while (err > 0.01) err = abs(pi sin(x) - x); x = pi sin(x); n = n+1; % loop counter if n>maxiter, break, end end
18 Outline 1.m files 2 Programming Branching (if, switch) Loops (for, while) 3 Anonymous functions 4 Basic Graphing Curve plotting (plot,plot3,contour) Surface plotting (surf, mesh) 5 Efficient coding - Vectorization
19 Anonymous functions We can quickly form functions at the command line. For example, let f(x) = 2e x x 2 cos(x) + 5x log(x) Usage g(x, y, z) = e xy/z y sin(z)/x + log(z). fhandle list)(expression) >> f 2*exp(x) (x.ˆ2).*cos(x) + 5*x.*log(x) ); >> g exp(x.*y)./z y.*sin(z)./ x + log(z) ); Alternatively, we can use inline >> f = inline( 2*exp(x) (x.ˆ2).*cos(x) + 5*x.*log(x), x ); >> g = inline( exp(x.*y)./z y.*sin(z)./ x + log(z), x, y, z ); Make your functions array-smart by inserting a dot before *, /,ˆ
20 Anonymous functions We cannot add or multiply anonymous functions. >> f+f returns an error message. x is a numerical array f(x) is a numerical array. We can, for example >> x = ones(2,3); y = rand(2,3); >> sumfxfy = f(x)+f(y); prodfxfy = f(x).*f(y); We can form anonymous functions with outside parameters >> h a*cos(x) + b*sin(x)); >> h(2) returns an error message if a and b are not defined. >> a=0.3; b=0.5; h(2) Multiple anonymous functions can be used together. For example, if π F(x, t) = e u2 /t sin(x u)du, 0 we can >> F );
21 Outline 1.m files 2 Programming Branching (if, switch) Loops (for, while) 3 Anonymous functions 4 Basic Graphing Curve plotting (plot,plot3,contour) Surface plotting (surf, mesh) 5 Efficient coding - Vectorization
22 Some Graphing Commands Curve graphing commands plot ezplot: plot for anonymous functions. plot3: plot curves in 3D space. Surface graphing commands surf, mesh: surface graphing in 3D. ezsurf, ezmesh: surface graphing for anonymous functions. colorbar, colormap: show/change color scaling. pcolor: top view of a colored surface. contour, ezcontour: contour plot of surfaces Figure properties and annotation figure: open a new empty figure window. hold on, hold off, grid on, grid off subplot: multiple graphs in one figure. axis, xlim, ylim: axis limits. title, xlabel, ylabel: graph and axis labels. legend: display/edit the legend for graphs with multiple curves.
23 plot plot uses line segments to connect points given by two vectors of the same length. Usage plot(x,y, color-style-marker ) x is a vector of length N, which keeps the x-coordinates. y is a vector of length N, which keeps the y-coordinates. color-style-marker [OPTIONAL] is a string that gives the color, style, marker type of the plot. Default value is b, if not provided. if x & y doesn t have the same length, plot(x,y) causes an error message. y can be a r N array. In this case, plot(x,y) plots each row of y versus x. x must always be a vector.
24 plot Here is a simple example. >> t = pi*(0:0.02:2); >> plot(t,sin(t)) Suppose you want to put a marker at each data point. >> plot(t,sin(t), o ) Also draw a cosine curve, make it red to distinguish. >> plot(t,cos(t), r ) The sine curve is erased. hold on to keep the previously drawn graphs. >> plot(t,sin(t), o ) >> hold on >> plot(t,cos(t), r ) >> hold off You can plot multiple curves at once: >> figure % forms a new empty figure >> plot(t, [t; t.ˆ2; t.ˆ3] ) MATLAB automatically assigns different colors to the curves.
25 plot - color, line style, marker Type Values Meanings Values Meanings Color c cyan g green m magenta b blue y yellow w white r red k black Line - solid : dotted style dashed.- dash-dot Marker + plus mark ˆ filled upward triangle type o unfilled circle v filled downward triangle * asterisk > filled right-pointing triangle x letter x < filled left-pointing triangle s filled square p filled pentagram d filled diamond h filled hexagram
26 ezplot For anonymous functions, we use ezplot. Usage ezplot(f, [xmin xmax]) f is an anonymous function handle. xmin, xmax [OPTIONAL] are x-axis boundaries of the graph. % plots f=f(x) on the given interval % if f=f(x,y) of 2 variables, plots the curve given by f(x, y) = 0. ezplot(x,y, [tmin,tmax]) x,y are anonymous functions of a single common variable t. tmin, tmax [OPTIONAL] are the limits of t. % plots the parametric curve x=x(t), y=y(t) for t [tmin,tmax] For example, >> f exp(3*sin(x)-cos(2*x)) ); >> ezplot(f, [0 4] ) % plots of f on [0,4]. >> g + y.ˆ4-1); >> ezplot( g, [-1 1] ) % plots the contour g(x, y) = 0 on [-1,1].
27 subplot We use subplot to form a single figure with multiple graphs. Usage subplot(m,n,k) m: number of rows in the figure. n: number of columns in the figure. k: position of the graph in the figure. Counting is done from left right, top bottom. For instance, subplot(3,4,1) subplot(3,4,2) subplot(3,4,3) subplot(3,4,4) subplot(3,4,5) subplot(3,4,6) subplot(3,4,7) subplot(3,4,8) subplot(3,4,9) subplot(3,4,10) subplot(3,4,11) subplot(3,4,12)
28 subplot and annotation Example: >> t = pi*(0:0.02:2); f = t.*sin(t); >> sin(x) + x.*cos(x) ); >> subplot(2,2,1) % start working on the 1st cell in the figure >> plot(t,f) >> axis( [0 2*pi -5 2] ) % set axis limits >> title( Graph of f(t) = t sin(t) ); % sets a title to the graph >> xlabel( time ); ylabel( velocity ); % label the axes >> >> subplot(2,2,3) % start working on the 3rd cell in the figure >> ezplot(f1,[0 2*pi]) >> xlabel( time ); ylabel( acceleration ); >> subplot(2,2,[2,4]) % merge 2nd & 4th cells >> plot3(cos(t),sin(t),sin(3*t))
29 surf, mesh surf (mesh) forms a 3D shaded surface (wireframed mesh) from a matrix of z-coordinates by linear interpolation. Usage surf(x,y,z) Z is a matrix defining the z-coordinates of a surface. X,Y [OPTIONAL] are matrices defining the x,y-coordinates. mesh has the same usage. X & Y can be vectors, length(x) = n and length(y) = m, where [m,n] = size(z). the vertices of the surface faces are (X(j), Y(i), Z(i,j)) triples. To form X & Y matrices for arbitrary domains, use meshgrid
30 ezsurf, ezmesh For anonymous functions, use ezsurf (ezmesh) Usage ezsurf(f, [xmin xmax ymin ymax]) f is an anonymous function handle. xmin, xmax, ymin, ymax [OPTIONAL] are boundaries of the xy-plane. Default values xmin = ymin = -2*pi, xmax = ymax = 2*pi, if not entered % plots f=f(x,y) on the given interval ezsurf(x,y,z, [tmin,tmax,smin,smax]) x,y,z are anonymous functions of two common variables t,s. tmin, tmax, smin, smax [OPTIONAL] are the limits of t,s. Default values tmin = smin = -2*pi, tmax = smax = 2*pi, if not entered % plots the parametric surface x = x(s,t), y = y(s,t), z = z(s,t) for t [tmin,tmax], s [smin,smax] ezmesh has the same usage.
31 Example >> figure; ezsurf [0 pi 0 2*pi] ) >> f sin(x.ˆ2+y) ); >> x = pi*(0:0.02:1); y = 2*x; >> [X,Y] = meshgrid(x,y); % form a grid of points in the xy-plane >> Z = f(x,y); >> figure; surf(x,y,z) >> colorbar % display the colorbar in the figure >> colormap gray % change the color scaling The coloring is determined by shading in between the data points: >> shading flat >> shading interp
32 surf - shading flat shading: each face/ mesh line has constant color determined by one boundary point. interpolated shading: the color is determined by interpolation of the boundary values. It makes smoother pictures, but can be very slow to render, particularly on printers. faceted shading: uses flat shading for the faces and black for the edges.
33 Outline 1.m files 2 Programming Branching (if, switch) Loops (for, while) 3 Anonymous functions 4 Basic Graphing Curve plotting (plot,plot3,contour) Surface plotting (surf, mesh) 5 Efficient coding - Vectorization
34 How to make your code run faster: Vectorization: Rewrite loops by indexing and matrix operations. Because Matlab is optimized for matrix operations. Matlab s core strength is the efficient handling of vector and matrix operations. Loops slow down Matlab. Pre-allocate memory hhen forming large arrays/matrices. For example, use zeros to make a matrix of the desired size. Because, repeatedly resizing arrays requires that MATLAB spend extra time looking for larger contiguous blocks of memory and then moving the array into those blocks. Use built-in functions. Use functions rather than scripts. Because, a function is parsed into the memory at the first time it is executed/modified. A script is parsed one line at a time, each time it is executed. Parsing/interpretation require extra time.
35 Vectorization - Indexing Example: x is a vector and we want to compute a matrix D = [d ij ] such that d ij = e x i sin x j. The standard programming involves two nested loops. >> n = length(x); >> D = zeros(n); % preallocate memory for D >> for j = 1:n >> for i = 1:n >> D(i,j) = exp(x(i))*sin(x(j)); >> end >> end We can vectorize as follows. >> n = length(x); >> ind = ones(n,1)*(1:n); % forms an nxn index matrix. >> X = x(ind); >> D = exp(x).*sin(x. );
36 Vectorization - Index Masks Example: A is a numerical array/matrix. We want to set A ij = 0 if A ij < 0.05 The standard programming involves two nested loops. >> [m n] = size(a); >> for j=1:m >> for k=1:n >> if abs(a(j,k))<0.05, A(j,k)=0, end >> end >> end We can vectorize as follows. >> mask = (abs(a)>=0.05); % form a logical index mask >> A = A.*mask;
37 Recommended Reading Scientific Computing with MATLAB and Octave by Quarteroni & Saleri, Chapter 3, Sections 3.1 and 3.4.
Logical Subscripting: This kind of subscripting can be done in one step by specifying the logical operation as the subscripting expression.
What is the answer? >> Logical Subscripting: This kind of subscripting can be done in one step by specifying the logical operation as the subscripting expression. The finite(x)is true for all finite numerical
More informationMechanical Engineering Department Second Year (2015)
Lecture 7: Graphs Basic Plotting MATLAB has extensive facilities for displaying vectors and matrices as graphs, as well as annotating and printing these graphs. This section describes a few of the most
More informationPROGRAMMING WITH MATLAB WEEK 6
PROGRAMMING WITH MATLAB WEEK 6 Plot: Syntax: plot(x, y, r.- ) Color Marker Linestyle The line color, marker style and line style can be changed by adding a string argument. to select and delete lines
More informationClasses 7-8 (4 hours). Graphics in Matlab.
Classes 7-8 (4 hours). Graphics in Matlab. Graphics objects are displayed in a special window that opens with the command figure. At the same time, multiple windows can be opened, each one assigned a number.
More informationWhat is MATLAB? What is MATLAB? Programming Environment MATLAB PROGRAMMING. Stands for MATrix LABoratory. A programming environment
What is MATLAB? MATLAB PROGRAMMING Stands for MATrix LABoratory A software built around vectors and matrices A great tool for numerical computation of mathematical problems, such as Calculus Has powerful
More informationINTRODUCTION TO MATLAB PLOTTING WITH MATLAB
1 INTRODUCTION TO MATLAB PLOTTING WITH MATLAB Plotting with MATLAB x-y plot Plotting with MATLAB MATLAB contains many powerful functions for easily creating plots of several different types. Command plot(x,y)
More information12 whereas if I terminate the expression with a semicolon, the printed output is suppressed.
Example 4 Printing and Plotting Matlab provides numerous print and plot options. This example illustrates the basics and provides enough detail that you can use it for typical classroom work and assignments.
More informationThe Department of Engineering Science The University of Auckland Welcome to ENGGEN 131 Engineering Computation and Software Development
The Department of Engineering Science The University of Auckland Welcome to ENGGEN 131 Engineering Computation and Software Development Chapter 7 Graphics Learning outcomes Label your plots Create different
More informationMATLAB SUMMARY FOR MATH2070/2970
MATLAB SUMMARY FOR MATH2070/2970 DUNCAN SUTHERLAND 1. Introduction The following is inted as a guide containing all relevant Matlab commands and concepts for MATH2070 and 2970. All code fragments should
More informationPART 1 PROGRAMMING WITH MATHLAB
PART 1 PROGRAMMING WITH MATHLAB Presenter: Dr. Zalilah Sharer 2018 School of Chemical and Energy Engineering Universiti Teknologi Malaysia 23 September 2018 Programming with MATHLAB MATLAB Environment
More informationfplot Syntax Description Examples Plot Symbolic Expression Plot symbolic expression or function fplot(f) fplot(f,[xmin xmax])
fplot Plot symbolic expression or function Syntax fplot(f) fplot(f,[xmin xmax]) fplot(xt,yt) fplot(xt,yt,[tmin tmax]) fplot(,linespec) fplot(,name,value) fplot(ax, ) fp = fplot( ) Description fplot(f)
More informationMatlab Tutorial 1: Working with variables, arrays, and plotting
Matlab Tutorial 1: Working with variables, arrays, and plotting Setting up Matlab First of all, let's make sure we all have the same layout of the different windows in Matlab. Go to Home Layout Default.
More informationBasic Graphs. Dmitry Adamskiy 16 November 2011
Basic Graphs Dmitry Adamskiy adamskiy@cs.rhul.ac.uk 16 November 211 1 Plot Function plot(x,y): plots vector Y versus vector X X and Y must have the same size: X = [x1, x2 xn] and Y = [y1, y2,, yn] Broken
More informationMATLAB Introduction to MATLAB Programming
MATLAB Introduction to MATLAB Programming MATLAB Scripts So far we have typed all the commands in the Command Window which were executed when we hit Enter. Although every MATLAB command can be executed
More information1. Register an account on: using your Oxford address
1P10a MATLAB 1.1 Introduction MATLAB stands for Matrix Laboratories. It is a tool that provides a graphical interface for numerical and symbolic computation along with a number of data analysis, simulation
More informationProf. Manoochehr Shirzaei. RaTlab.asu.edu
RaTlab.asu.edu Introduction To MATLAB Introduction To MATLAB This lecture is an introduction of the basic MATLAB commands. We learn; Functions Procedures for naming and saving the user generated files
More informationINTERNATIONAL EDITION. MATLAB for Engineers. Third Edition. Holly Moore
INTERNATIONAL EDITION MATLAB for Engineers Third Edition Holly Moore 5.4 Three-Dimensional Plotting Figure 5.8 Simple mesh created with a single two-dimensional matrix. 5 5 Element,5 5 The code mesh(z)
More informationINC151 Electrical Engineering Software Practice. MATLAB Graphics. Dr.Wanchak Lenwari :Control System and Instrumentation Engineering, KMUTT 1
INC151 Electrical Engineering Software Practice MATLAB Graphics Dr.Wanchak Lenwari :Control System and Instrumentation Engineering, KMUTT 1 Graphical display is one of MATLAB s greatest strengths and most
More information3D plot of a surface in Matlab
3D plot of a surface in Matlab 3D plot of a surface in Matlab Create a surface of function mesh Graphics 3-D line plot Graphics 3-D contour plot Draw contours in volume slice planes For 3-D shaded surface
More informationMath 375 Natalia Vladimirova (many ideas, examples, and excersises are borrowed from Profs. Monika Nitsche, Richard Allen, and Stephen Lau)
Natalia Vladimirova (many ideas, examples, and excersises are borrowed from Profs. Monika Nitsche, Richard Allen, and Stephen Lau) January 24, 2010 Starting Under windows Click on the Start menu button
More informationDSP Laboratory (EELE 4110) Lab#1 Introduction to Matlab
Islamic University of Gaza Faculty of Engineering Electrical Engineering Department 2012 DSP Laboratory (EELE 4110) Lab#1 Introduction to Matlab Goals for this Lab Assignment: In this lab we would have
More informationMATLAB Tutorial. 1. The MATLAB Windows. 2. The Command Windows. 3. Simple scalar or number operations
MATLAB Tutorial The following tutorial has been compiled from several resources including the online Help menu of MATLAB. It contains a list of commands that will be directly helpful for understanding
More informationSTAT 391 Handout 1 Making Plots with Matlab Mar 26, 2006
STAT 39 Handout Making Plots with Matlab Mar 26, 26 c Marina Meilă & Lei Xu mmp@cs.washington.edu This is intended to help you mainly with the graphics in the homework. Matlab is a matrix oriented mathematics
More informationThis module aims to introduce Precalculus high school students to the basic capabilities of Matlab by using functions. Matlab will be used in
This module aims to introduce Precalculus high school students to the basic capabilities of Matlab by using functions. Matlab will be used in subsequent modules to help to teach research related concepts
More informationMATLAB Functions and Graphics
Functions and Graphics We continue our brief overview of by looking at some other areas: Functions: built-in and user defined Using M-files to store and execute statements and functions A brief overview
More informationPyPlot. The plotting library must be imported, and we will assume in these examples an import statement similar to those for numpy and math as
Geog 271 Geographic Data Analysis Fall 2015 PyPlot Graphicscanbeproducedin Pythonviaavarietyofpackages. We willuseapythonplotting package that is part of MatPlotLib, for which documentation can be found
More informationIntroduction to Octave/Matlab. Deployment of Telecommunication Infrastructures
Introduction to Octave/Matlab Deployment of Telecommunication Infrastructures 1 What is Octave? Software for numerical computations and graphics Particularly designed for matrix computations Solving equations,
More informationDepartment of Chemical Engineering ChE-101: Approaches to Chemical Engineering Problem Solving MATLAB Tutorial Vb
Department of Chemical Engineering ChE-101: Approaches to Chemical Engineering Problem Solving MATLAB Tutorial Vb Making Plots with Matlab (last updated 5/29/05 by GGB) Objectives: These tutorials are
More informationProgramming 1. Script files. help cd Example:
Programming Until now we worked with Matlab interactively, executing simple statements line by line, often reentering the same sequences of commands. Alternatively, we can store the Matlab input commands
More informationIntroduction to Programming in MATLAB
Introduction to Programming in MATLAB User-defined Functions Functions look exactly like scripts, but for ONE difference Functions must have a function declaration Help file Function declaration Outputs
More informationUNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER
UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER BENC 2113 DENC ECADD 2532 ECADD LAB SESSION 6/7 LAB
More informationGraphics Example a final product:
Basic 2D Graphics 1 Graphics Example a final product: TITLE LEGEND YLABEL TEXT or GTEXT CURVES XLABEL 2 2-D Plotting Specify x-data and/or y-data Specify color, line style and marker symbol (Default values
More informationAppendix A. Introduction to MATLAB. A.1 What Is MATLAB?
Appendix A Introduction to MATLAB A.1 What Is MATLAB? MATLAB is a technical computing environment developed by The Math- Works, Inc. for computation and data visualization. It is both an interactive system
More informationWhat is MATLAB? It is a high-level programming language. for numerical computations for symbolic computations for scientific visualizations
What is MATLAB? It stands for MATrix LABoratory It is developed by The Mathworks, Inc (http://www.mathworks.com) It is an interactive, integrated, environment for numerical computations for symbolic computations
More information2D LINE PLOTS... 1 The plot() Command... 1 Labeling and Annotating Figures... 5 The subplot() Command... 7 The polarplot() Command...
Contents 2D LINE PLOTS... 1 The plot() Command... 1 Labeling and Annotating Figures... 5 The subplot() Command... 7 The polarplot() Command... 9 2D LINE PLOTS One of the benefits of programming in MATLAB
More informationOverview. Lecture 13: Graphics and Visualisation. Graphics & Visualisation 2D plotting. Graphics and visualisation of data in Matlab
Overview Lecture 13: Graphics and Visualisation Graphics & Visualisation 2D plotting 1. Plots for one or multiple sets of data, logarithmic scale plots 2. Axis control & Annotation 3. Other forms of 2D
More informationGraphics in MATLAB. Responsible teacher: Anatoliy Malyarenko. November 10, Abstract. Basic Plotting Commands
Graphics in MATLAB Responsible teacher: Anatoliy Malyarenko November 10, 2003 Contents of the lecture: Two-dimensional graphics. Formatting graphs. Three-dimensional graphics. Specialised plots. Abstract
More informationDr. Iyad Jafar. Adapted from the publisher slides
Computer Applications Lab Lab 6 Plotting Chapter 5 Sections 1,2,3,8 Dr. Iyad Jafar Adapted from the publisher slides Outline xy Plotting Functions Subplots Special Plot Types Three-Dimensional Plotting
More informationPyPlot. The plotting library must be imported, and we will assume in these examples an import statement similar to those for numpy and math as
Geog 271 Geographic Data Analysis Fall 2017 PyPlot Graphicscanbeproducedin Pythonviaavarietyofpackages. We willuseapythonplotting package that is part of MatPlotLib, for which documentation can be found
More informationComputer Programming in MATLAB
Computer Programming in MATLAB Prof. Dr. İrfan KAYMAZ Engineering Faculty Department of Mechanical Engineering Arrays in MATLAB; Vectors and Matrices Graphing Vector Generation Before graphing plots in
More informationLab of COMP 406 Introduction of Matlab (II) Graphics and Visualization
Lab of COMP 406 Introduction of Matlab (II) Graphics and Visualization Teaching Assistant: Pei-Yuan Zhou Contact: cspyzhou@comp.polyu.edu.hk Lab 2: 19 Sep., 2014 1 Review Find the Matlab under the folder
More informationMAT 275 Laboratory 1 Introduction to MATLAB
MATLAB sessions: Laboratory 1 1 MAT 275 Laboratory 1 Introduction to MATLAB MATLAB is a computer software commonly used in both education and industry to solve a wide range of problems. This Laboratory
More informationPurpose of the lecture MATLAB MATLAB
Purpose of the lecture MATLAB Harri Saarnisaari, Part of Simulations and Tools for Telecommunication Course This lecture contains a short introduction to the MATLAB For further details see other sources
More informationIntroduction to MATLAB
Introduction to MATLAB Violeta Ivanova, Ph.D. MIT Academic Computing violeta@mit.edu http://web.mit.edu/violeta/www/iap2006 Topics MATLAB Interface and Basics Linear Algebra and Calculus Graphics Programming
More informationPlotting - Practice session
Plotting - Practice session Alessandro Fanfarillo - Salvatore Filippone fanfarillo@ing.uniroma2.it May 28th, 2013 (fanfarillo@ing.uniroma2.it) Plotting May 28th, 2013 1 / 14 Plot function The basic function
More informationW1005 Intro to CS and Programming in MATLAB. Plo9ng & Visualiza?on. Fall 2014 Instructor: Ilia Vovsha. hgp://www.cs.columbia.
W1005 Intro to CS and Programming in MATLAB Plo9ng & Visualiza?on Fall 2014 Instructor: Ilia Vovsha hgp://www.cs.columbia.edu/~vovsha/w1005 Outline Plots (2D) Plot proper?es Figures Plots (3D) 2 2D Plots
More informationGetting Started with Matlab
Chapter Getting Started with Matlab The computational examples and exercises in this book have been computed using Matlab, which is an interactive system designed specifically for scientific computation
More informationMore on Plots. Dmitry Adamskiy 30 Nov 2011
More on Plots Dmitry Adamskiy adamskiy@cs.rhul.ac.uk 3 Nov 211 1 plot3 (1) Recall that plot(x,y), plots vector Y versus vector X. plot3(x,y,z), where x, y and z are three vectors of the same length, plots
More informationIntroduction to MATLAB Programming. Chapter 3. Linguaggio Programmazione Matlab-Simulink (2017/2018)
Introduction to MATLAB Programming Chapter 3 Linguaggio Programmazione Matlab-Simulink (2017/2018) Algorithms An algorithm is the sequence of steps needed to solve a problem Top-down design approach to
More informationIntroduction to Matlab to Accompany Linear Algebra. Douglas Hundley Department of Mathematics and Statistics Whitman College
Introduction to Matlab to Accompany Linear Algebra Douglas Hundley Department of Mathematics and Statistics Whitman College August 27, 2018 2 Contents 1 Getting Started 5 1.1 Before We Begin........................................
More informationComputing Fundamentals Plotting
Computing Fundamentals Plotting Salvatore Filippone salvatore.filippone@uniroma2.it 2014 2015 (salvatore.filippone@uniroma2.it) Plotting 2014 2015 1 / 14 Plot function The basic function to plot something
More informationIntroduction to MATLAB: Graphics
Introduction to MATLAB: Graphics Eduardo Rossi University of Pavia erossi@eco.unipv.it September 2014 Rossi Introduction to MATLAB Financial Econometrics - 2014 1 / 14 2-D Plot The command plot provides
More informationIntroduction to MATLAB LAB 1
Introduction to MATLAB LAB 1 1 Basics of MATLAB MATrix LABoratory A super-powerful graphing calculator Matrix based numeric computation Embedded Functions Also a programming language User defined functions
More informationIntroduction to Matlab
Introduction to Matlab The purpose of this intro is to show some of Matlab s basic capabilities. Nir Gavish, 2.07 Contents Getting help Matlab development enviroment Variable definitions Mathematical operations
More informationGetting Started with MATLAB
Getting Started with MATLAB Math 315, Fall 2003 Matlab is an interactive system for numerical computations. It is widely used in universities and industry, and has many advantages over languages such as
More informationConstraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial
1 Matlab Tutorial 2 Lecture Learning Objectives Each student should be able to: Describe the Matlab desktop Explain the basic use of Matlab variables Explain the basic use of Matlab scripts Explain the
More informationGetting Started. Chapter 1. How to Get Matlab. 1.1 Before We Begin Matlab to Accompany Lay s Linear Algebra Text
Chapter 1 Getting Started How to Get Matlab Matlab physically resides on each of the computers in the Olin Hall labs. See your instructor if you need an account on these machines. If you are going to go
More information1 Introduction to Matlab
1 Introduction to Matlab 1. What is Matlab? Matlab is a computer program designed to do mathematics. You might think of it as a super-calculator. That is, once Matlab has been started, you can enter computations,
More informationCSE 123. Plots in MATLAB
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 the expression fun(x) over the default domain -2pi
More informationDr Richard Greenaway
SCHOOL OF PHYSICS, ASTRONOMY & MATHEMATICS 4PAM1008 MATLAB 4 Visualising Data Dr Richard Greenaway 4 Visualising Data 4.1 Simple Data Plotting You should now be familiar with the plot function which is
More informationAMS 27L LAB #2 Winter 2009
AMS 27L LAB #2 Winter 2009 Plots and Matrix Algebra in MATLAB Objectives: 1. To practice basic display methods 2. To learn how to program loops 3. To learn how to write m-files 1 Vectors Matlab handles
More informationIntroduction to Simulink
Introduction to Simulink There are several computer packages for finding solutions of differential equations, such as Maple, Mathematica, Maxima, MATLAB, etc. These systems provide both symbolic and numeric
More informationIntroduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices
Introduction to Interactive Calculations Matlab is interactive, no need to declare variables >> 2+3*4/2 >> V = 50 >> V + 2 >> V Ans = 52 >> a=5e-3; b=1; a+b Most elementary functions and constants are
More informationMATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY
MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY What is MATLAB? MATLAB (MATrix LABoratory) developed by The Mathworks, Inc. (http://www.mathworks.com) Key Features: High-level language for numerical
More informationIntroduction to MatLab. Introduction to MatLab K. Craig 1
Introduction to MatLab Introduction to MatLab K. Craig 1 MatLab Introduction MatLab and the MatLab Environment Numerical Calculations Basic Plotting and Graphics Matrix Computations and Solving Equations
More informationMATLAB Tutorial EE351M DSP. Created: Thursday Jan 25, 2007 Rayyan Jaber. Modified by: Kitaek Bae. Outline
MATLAB Tutorial EE351M DSP Created: Thursday Jan 25, 2007 Rayyan Jaber Modified by: Kitaek Bae Outline Part I: Introduction and Overview Part II: Matrix manipulations and common functions Part III: Plots
More informationChapter 3: Introduction to MATLAB Programming (4 th ed.)
Chapter 3: Introduction to MATLAB Programming (4 th ed.) Algorithms MATLAB scripts Input / Output o disp versus fprintf Graphs Read and write variables (.mat files) User-defined Functions o Definition
More informationCreates a 1 X 1 matrix (scalar) with a value of 1 in the column 1, row 1 position and prints the matrix aaa in the command window.
EE 350L: Signals and Transforms Lab Spring 2007 Lab #1 - Introduction to MATLAB Lab Handout Matlab Software: Matlab will be the analytical tool used in the signals lab. The laboratory has network licenses
More informationProgramming in Mathematics. Mili I. Shah
Programming in Mathematics Mili I. Shah Starting Matlab Go to http://www.loyola.edu/moresoftware/ and login with your Loyola name and password... Matlab has eight main windows: Command Window Figure Window
More informationIntroduction to MATLAB
58:110 Computer-Aided Engineering Spring 2005 Introduction to MATLAB Department of Mechanical and industrial engineering January 2005 Topics Introduction Running MATLAB and MATLAB Environment Getting help
More informationMATLAB Guide to Fibonacci Numbers
MATLAB Guide to Fibonacci Numbers and the Golden Ratio A Simplified Approach Peter I. Kattan Petra Books www.petrabooks.com Peter I. Kattan, PhD Correspondence about this book may be sent to the author
More informationGUI Alternatives. Syntax. Description. MATLAB Function Reference plot. 2-D line plot
MATLAB Function Reference plot 2-D line plot GUI Alternatives Use the Plot Selector to graph selected variables in the Workspace Browser and the Plot Catalog, accessed from the Figure Palette. Directly
More informationMath 7 Elementary Linear Algebra PLOTS and ROTATIONS
Spring 2007 PLOTTING LINE SEGMENTS Math 7 Elementary Linear Algebra PLOTS and ROTATIONS Example 1: Suppose you wish to use MatLab to plot a line segment connecting two points in the xy-plane. Recall that
More informationFF505/FY505 Computational Science. MATLAB Graphics. Marco Chiarandini
FF505/FY505 Computational Science MATLAB Marco Chiarandini (marco@imada.sdu.dk) Department of Mathematics and Computer Science (IMADA) University of Southern Denmark Outline 1. 2D Plots 3D Plots 2 Outline
More informationQuick MATLAB Syntax Guide
Quick MATLAB Syntax Guide Some useful things, not everything if-statement Structure: if (a = = = ~=
More informationIntroduction to MATLAB
Introduction to MATLAB Violeta Ivanova, Ph.D. Office for Educational Innovation & Technology violeta@mit.edu http://web.mit.edu/violeta/www Topics MATLAB Interface and Basics Calculus, Linear Algebra,
More informationLaboratory 1 Octave Tutorial
Signals, Spectra and Signal Processing Laboratory 1 Octave Tutorial 1.1 Introduction The purpose of this lab 1 is to become familiar with the GNU Octave 2 software environment. 1.2 Octave Review All laboratory
More informationIntroduction to PartSim and Matlab
NDSU Introduction to PartSim and Matlab pg 1 PartSim: www.partsim.com Introduction to PartSim and Matlab PartSim is a free on-line circuit simulator that we use in Circuits and Electronics. It works fairly
More informationAdditional Plot Types and Plot Formatting
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
More informationDATA PLOTTING WITH MATLAB
DATA PLOTTING WITH MATLAB Prof. Marco Pilotti marco.pilotti@ing.unibs.it Dr. Giulia Valerio giulia.valerio@ing.unibs.it Giulia Valerio 7Marzo 2014 1 1. WHY MATLAB? WHY MATLAB? Matlab is a high-level programming
More informationChapter 1 Introduction to MATLAB
Chapter 1 Introduction to MATLAB 1.1 What is MATLAB? MATLAB = MATrix LABoratory, the language of technical computing, modeling and simulation, data analysis and processing, visualization and graphics,
More informationGRAPHICS AND VISUALISATION WITH MATLAB
GRAPHICS AND VISUALISATION WITH MATLAB UNIVERSITY OF SHEFFIELD CiCS DEPARTMENT Des Ryan & Mike Griffiths September 2017 Topics 2D Graphics 3D Graphics Displaying Bit-Mapped Images Graphics with Matlab
More informationIntroduction to MATLAB Practical 1
Introduction to MATLAB Practical 1 Daniel Carrera November 2016 1 Introduction I believe that the best way to learn Matlab is hands on, and I tried to design this practical that way. I assume no prior
More informationCSE/NEUBEH 528 Homework 0: Introduction to Matlab
CSE/NEUBEH 528 Homework 0: Introduction to Matlab (Practice only: Do not turn in) Okay, let s begin! Open Matlab by double-clicking the Matlab icon (on MS Windows systems) or typing matlab at the prompt
More informationFall 2014 MAT 375 Numerical Methods. Introduction to Programming using MATLAB
Fall 2014 MAT 375 Numerical Methods Introduction to Programming using MATLAB Some useful links 1 The MOST useful link: www.google.com 2 MathWorks Webcite: www.mathworks.com/help/matlab/ 3 Wikibooks on
More informationLecture 3 for Math 398 Section 952: Graphics in Matlab
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
More informationIntroduction to Matlab for Engineers
Introduction to Matlab for Engineers Instructor: Thai Nhan Math 111, Ohlone, Spring 2016 Introduction to Matlab for Engineers Ohlone, Spring 2016 1/19 Today s lecture 1. The subplot command 2. Logarithmic
More informationPart #6. A0B17MTB Matlab. Miloslav Čapek Filip Kozák, Viktor Adler, Pavel Valtr
A0B17MTB Matlab Part #6 Miloslav Čapek miloslav.capek@fel.cvut.cz Filip Kozák, Viktor Adler, Pavel Valtr Department of Electromagnetic Field B2-626, Prague Learning how to Visualizing in Matlab #1 Debugging
More informationMATH 2221A Mathematics Laboratory II
MATH A Mathematics Laboratory II Lab Assignment 4 Name: Student ID.: In this assignment, you are asked to run MATLAB demos to see MATLAB at work. The color version of this assignment can be found in your
More informationMATLAB Laboratory 09/23/10 Lecture. Chapters 5 and 9: Plotting
MATLAB Laboratory 09/23/10 Lecture Chapters 5 and 9: Plotting Lisa A. Oberbroeckling Loyola University Maryland loberbroeckling@loyola.edu L. Oberbroeckling (Loyola University) MATLAB 09/23/10 Lecture
More informationPart V Appendices c Copyright, Todd Young and Martin Mohlenkamp, Department of Mathematics, Ohio University, 2017
Part V Appendices c Copyright, Todd Young and Martin Mohlenkamp, Department of Mathematics, Ohio University, 2017 Appendix A Glossary of Matlab Commands Mathematical Operations + Addition. Type help plus
More informationIntroduction to Matlab
Introduction to Matlab Enrique Muñoz Ballester Dipartimento di Informatica via Bramante 65, 26013 Crema (CR), Italy enrique.munoz@unimi.it Contact Email: enrique.munoz@unimi.it Office: Room BT-43 Industrial,
More informationGraphics and plotting techniques
Davies: Computer Vision, 5 th edition, online materials Matlab Tutorial 5 1 Graphics and plotting techniques 1. Introduction The purpose of this tutorial is to outline the basics of graphics and plotting
More information1 >> Lecture 4 2 >> 3 >> -- Graphics 4 >> Zheng-Liang Lu 184 / 243
1 >> Lecture 4 >> 3 >> -- Graphics 4 >> Zheng-Liang Lu 184 / 43 Introduction ˆ Engineers use graphic techniques to make the information easier to understand. ˆ With graphs, it is easy to identify trends,
More informationEL2310 Scientific Programming
(pronobis@kth.se) Overview Overview Wrap Up More on Scripts and Functions Basic Programming Lecture 2 Lecture 3 Lecture 4 Wrap Up Last time Loading data from file: load( filename ) Graphical input and
More informationINTRODUCTION TO NUMERICAL ANALYSIS
INTRODUCTION TO NUMERICAL ANALYSIS Cho, Hyoung Kyu Department of Nuclear Engineering Seoul National University 0. MATLAB USAGE 1. Background MATLAB MATrix LABoratory Mathematical computations, modeling
More informationLabVIEW MathScript Quick Reference
Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics LabVIEW MathScript Quick Reference Hans-Petter Halvorsen, 2012.06.14 Faculty of Technology, Postboks
More informationUser Defined Functions
User Defined Functions 120 90 1 0.8 60 Chapter 6 150 0.6 0.4 30 0.2 180 0 210 330 240 270 300 Objectives Create and use MATLAB functions with both single and multiple inputs and outputs Learn how to store
More informationInteractive Computing with Matlab. Gerald W. Recktenwald Department of Mechanical Engineering Portland State University
Interactive Computing with Matlab Gerald W. Recktenwald Department of Mechanical Engineering Portland State University gerry@me.pdx.edu Starting Matlab Double click on the Matlab icon, or on unix systems
More informationPC-MATLAB PRIMER. This is intended as a guided tour through PCMATLAB. Type as you go and watch what happens.
PC-MATLAB PRIMER This is intended as a guided tour through PCMATLAB. Type as you go and watch what happens. >> 2*3 ans = 6 PCMATLAB uses several lines for the answer, but I ve edited this to save space.
More information