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

Size: px
Start display at page:

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

Transcription

1 MATLAB basic guide to create 2D and 3D Plots Part I Introduction This guide will walk you through the steps necessary to create, using MATLAB, a Three dimensional surface, a Two dimensional contour plot or a graph combining both. But before getting to that point we need to go through some basics that will help us getting to the final objective. First start your MATLAB program, and the window that you will see is similar to the following figure. This is the MATLAB desktop. The MATLAB desktop is divided into three windows. To the left you have the Workspace window, here you will see all the variables you are working with when running a program. Typically by default this window shows the files in the current directory, click on the tab corresponding to Workspace. Below you will see the command history window, and the bigger window as seen corresponds to the command window. Most of the time is necessary to write a program rather than just writing few commands, at least this will be our situation. Thus under these circumstances it is better to work with the MATLAB editor. To open the editor you need to click on the first icon shown on the command bar. Click on this icon to open the editor.

2 Once you open the editor a new window will open. This is the editor that we will use to write our programs. Let s start with a simple program. Since we are going to be creating plots we will start by writing a program to plot a function such as f (x) =.3x 4 1.2x 3 2x 2 + 3x. In addition let s say that we want to create this plot for x ϵ [- 3; 5] in steps of.05. Copy the text below and paste it to your MATLAB editor, then save the program as program1 or give any name you prefer and run it. See figure below program to locate saving and running icons. Program 1 clc % clears the command window clear all %clears all variables from workspace % Since we want to have x varying from -3 to 5 we can use the following % instruction that creates a vector with elements going from -3 to 5 in % increments of 0.05 x = -3:.05:5.5; % Now we define a variable that will play the role of f(x) let's say y y =.3*x.^4-1.2*x.^3-2*x.^2 + 3*x; % As you can see, since x is a vector when we calculate say x to the power % 4 we need to do it for each element of the vector x, this is done in % MATLAB language by putting a period between the variable and the % operation that needs to be performed. plot(x,y); % plots in the horizontal axis vector x and in the vertical axis %vector y grid on %adds a grid to the plot

3 Click on this icon to save program. Click on this icon to execute program. As you can see, any text written after a percentage sign (%) is understood by MATLAB as a comment and it is written in green letters. Now if you go to the MATLAB desktop you will see that all variables that we used in the program are listed in the workspace window along with all the elements and dimensions of these variables, see the figure below. As seen, x and y are both vectors with 1 row and 171 columns. After writing our first program we continue with another programming structure named loop. Loops are programming structures that are used very often. Loops are used to repeat a set of instructions a determined number of times. Sometimes it is the computer that knows how many times, not you, but it is still known. To apply this concept of loops to an example we consider a situation in which we want to know what number we obtain by adding the first 100 integer positive numbers, i.e For this example we use a for loop.

4 As you can see when you run this example, if you place a semicolon (;) after a variable, the variable is not written on the command window, on the other hand if you do not type a semicolon the value of the variable will appear on the command window, as seen with the last instruction in our following program. Program 2 clc % clears the command window clear all %clears all variables from workspace %for is the instruction used to start the loop Sum = 0; for i=1:100 %i is the variable that we use to run the numbers increasing %from 1 to 100 in increments of 1 Sum = Sum + i; %Sum is the variable that stores the summation we are %trying to determine end %end is the instruction used to close the loop Sum Let s write another example of a program in which we use loops and in addition we use also vectors. The program we will write now is aimed to produce the first 100 numbers of the Fibonacci sequence. As you know the Fibonacci sequence is a series in which, excepting the first two elements, the following number is always the sum of the two preceding ones: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144 And in addition, the ratio between two consecutive elements of the sequence approaches For this program we will use two vectors, the first vector will store the first 100 elements of the Fibonacci sequence while the second will store the ratio between two consecutive elements of the sequence. Program 3 clc % clears the command window clear all %clears all variables from workspace FibSeq(1) = 0; %First number of sequence FibSeq(2) = 1; %Second number of sequence for i = 3:100 %in this case we start the loop at 3 because the first %element we are going to determine is the third one, we %already have the first 2 elements FibSeq(i) = FibSeq(i-1) + FibSeq(i-2); ratio(i-2)= (FibSeq(i)/FibSeq(i-1));%The variable ratio stores the %ratio of the last two elements of the sequence end plot(ratio(1:20)); %Now we plot the first 20 elements of the variable %ratio to demonstrate that it approaches grid on; The variable FibSeq is a vector of 100 elements and stores every element of the Fibonacci sequence. You can double click on this variable on the Workspace window and it will show all 100 elements of the vector or you

5 can simply type FibSeq on the Command window and all 100 elements will be also listed. On the other hand, the variable ratio stored the ratio between the last two elements of the sequence. As a historical note, Leonardo Pisano Bigollo was the mathematician who created this sequence, his father was Guglielmo Bonacci, and that is why Leonardo was known as Fibonacci (since the Italian word for son is figlio, thus Fi(glio di)bonacci, son of Bonacci) [1]. Continuing with our examples, let s write now a program in which we use nested loops. A nested loop is a loop within a loop, an inner loop within the body of an outer one. The way nested loops operate is by having the first pass of the outer loop triggering the inner loop, which executes to completion. Then the second pass of the outer loop triggers the inner loop again. This process repeats until the outer loop finishes. A break within either the inner or outer loop will interrupt the process. Then in our example we will use nested loops to give animation to the plot we created in the first program. To produce this animation we will change the value of x that we evaluate in f(x) by one position [f (x i ) = f (x i+1 )] and then assigning the first value of f (x) to the last f (x), i.e., f (x last ) = f (x 1 ). Then we repeat this process a number of times, therefore we will need an outer loop to have this sequence repeated several times.

6 Program 4 clc % clears the command window clear all %clears all variables from workspace % Since we want to have x varying from -3 to 5 we can use the following % instruction that creates a vector with elements going from -3 to 5 in % increments of 0.05 x = -3:.05:5.5; % Now we define a variable that will play the role of f(x) let's say y y =.3*x.^4-1.2*x.^3-2*x.^2 + 3*x; % As you can see, since x is a vector when we calculate say x to the power % 4 we need to do it for each element of the vector x, this is done in % MATLAB language by putting a period between the variable and the % operation that needs to be performed. [Rows Cols] = size(y); %The command size returns the number of rows and %columns of a variable. for j=1:600 %This outer loop will control the number of times the graph is %plotted, in this case 600 times y(cols) = y(1);%assign the value of f(x1) to f(xlast) for i=1:cols-1 %This inner loop is used to change the value of y by one position %It runs from 1 to the number of elements in the vector %minus 1 (Cols - 1) y(i) = y(i+1);%change the value of y by one position end %close the inner loop figure (1) %Figure (1) is the label we use for the plot we will create plot(x,y); % plots in the horizontal axis vector x and in the vertical axis vector y grid on %adds a grid to the plot pause(.01) %This instruction delays the execution of the loop by.01 seconds, %in this way we give the appearance of an animation to the %plot that repeats 600 times end %close the outer loop

7 MATLAB basic guide for ME3560 Part II Three Dimensional Plots Once we have learned how to create a 2 D graph, we proceed to learn how to generate a 3 D or a contour plot using MATLAB. When creating a 2 D graph for y = f (x), it was necessary to first generate the values of x that were going to be used to evaluate y. In a similar way, when creating a 3 D or a contour plot described by an expression such as z = f (x, y) it is necessary to first create all the x and y values that are to be used to determine z. Now, in the 2 D case since f (x) is function of only one variable (x), and both x and f (x) are vectors. For the 3 D case, since z is function of two variables then x, y, and z are described by matrices. The instructions we will use to create 3 D and contour plots are surf and contour, respectively. The format for these commands is similar: surf(x,y,z) or contour(x,y,z). surf(x,y,z) creates a shaded surface using Z for the color data as well as surface height. X and Y are matrices defining the x and y components of a surface. X and Y must be the same size as Z and must increase monotonically. contour(x,y,z) draws contour plots of Z. X and Y specify the x and y axis limits. X and Y are matrices which must be the same size as Z, thus specifying a surface, as defined by the surf function. X and Y must increase monotonically. The coordinates (x, y) to be used in the determination of z = f (x, y) can be created using nested loops but much easier approach is by using the command meshgrid : [X,Y] = meshgrid(x,y) transforms the domain specified by vectors x and y into arrays X and Y, which can be used to evaluate functions of two variables and three-dimensional mesh/surface plots. The rows of the output array X are copies of the vector x; columns of the output array Y are copies of the vector y. These three new commands (surf, contour, and meshgrid) are the basic instructions we need to know for our surface and contour plots, and we will apply them now in an example. Let s say that we want to construct a 3D plot [figure (1)], a contour plot [figure (2)], and a 3D and contour plots together in the same figure [figure (3)] of a paraboloid described by the expression z = 3x y 2 where xϵ[-5;5] and y ϵ[-3;3]. We are going to use increments of 0.05 in both variables.

8 Program 5 clc clear all x = -5:.05:5; %x is a vector containing the x-coordinates that are going %to be used to evauate z y = -3:.05:3; %y is a vector containing the y-coordinates that are going %to be used to evaluate z [X,Y] = meshgrid(x,y); %The instruction meshgrid creates, using vectors %x and y two matrices X and Y containing the %coordinates of the mesh over which we will evaluate %z. Z = 3*X.^ *Y.^2; %Matrix Z contains the value of z when evaluated at %each one of the points defined by X and Y figure (1) surf(x,y,z) %Plots the values contained in matrices X, Y, and Z in a 3D figure figure (2) contour(x,y,z) %Creates a contour plot of Z on a system of coordinates %defined by matrices X,Y. figure (3) surfc(x,y,z) %Plots the values contained in matrices X, Y, and Z in a 3D figure % and plots on the same graph the contours, therefore this % instruction combines surf and contour instructions After you have run the previous program try writing after the commands surf and surfc the following two instructions: shading interp rotate3d And run the code again to see what you obtain. This short tutorial will prepare us for the exercises we need to study in Chapter VI. At that point in the semester we will go over one more tutorial directly related to our course to then solve some examples using Fluid Mechanics theory along with MATLAB. [1] Magno Alessandro Marzo, L Invenzione dei Soldi, p. 169, 2013.

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

MATLAB Tutorial. Primary Author: Shoumik Chatterjee Secondary Author: Dr. Chuan Li MATLAB Tutorial Primary Author: Shoumik Chatterjee Secondary Author: Dr. Chuan Li 1 Table of Contents Section 1: Accessing MATLAB using RamCloud server...3 Section 2: MATLAB GUI Basics. 6 Section 3: MATLAB

More information

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

INTERNATIONAL 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 information

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial

Constraint-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 information

Introduction to MATLAB Practical 1

Introduction 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 information

C =

C = file:///c:/documents20and20settings/ravindra/desktop/html/exercis... 1 of 5 10/3/2008 3:17 PM Lab Exercise 2 - Matrices Hyd 510L, Fall, 2008, NM Tech Programmed by J.L. Wilson, Sept, 2008 Problem 2.1 Create

More information

Matlab notes Matlab is a matrix-based, high-performance language for technical computing It integrates computation, visualisation and programming usin

Matlab notes Matlab is a matrix-based, high-performance language for technical computing It integrates computation, visualisation and programming usin Matlab notes Matlab is a matrix-based, high-performance language for technical computing It integrates computation, visualisation and programming using familiar mathematical notation The name Matlab stands

More information

Prof. Manoochehr Shirzaei. RaTlab.asu.edu

Prof. 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 information

Introduction to Matlab

Introduction 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 information

Matlab Review. Dr. Mark Glauser, Created by: David Marr. Mechanical Engineering Syracuse University. Matlab Review p.

Matlab Review. Dr. Mark Glauser, Created by: David Marr. Mechanical Engineering Syracuse University. Matlab Review p. Matlab Review p.1 Matlab Review Dr. Mark Glauser, Created by: David Marr drmarr@syr.edu Mechanical Engineering Syracuse University General Info Matlab Review p.2 The Command Window is where you type in

More information

MATLAB Tutorial III Variables, Files, Advanced Plotting

MATLAB Tutorial III Variables, Files, Advanced Plotting MATLAB Tutorial III Variables, Files, Advanced Plotting A. Dealing with Variables (Arrays and Matrices) Here's a short tutorial on working with variables, taken from the book, Getting Started in Matlab.

More information

Introduction to MATLAB

Introduction to MATLAB Computational Photonics, Seminar 0 on Introduction into MATLAB, 3.04.08 Page Introduction to MATLAB Operations on scalar variables >> 6 6 Pay attention to the output in the command window >> b = b = >>

More information

PROGRAMMING WITH MATLAB WEEK 6

PROGRAMMING 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 information

Matlab Practice Sessions

Matlab Practice Sessions Matlab Practice Sessions 1. Getting Started Startup Matlab Observe the following elements of the desktop; Command Window Current Folder Window Command History Window Workspace Window Notes: If you startup

More information

3D plot of a surface in Matlab

3D 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 information

Desktop Command window

Desktop Command window Chapter 1 Matlab Overview EGR1302 Desktop Command window Current Directory window Tb Tabs to toggle between Current Directory & Workspace Windows Command History window 1 Desktop Default appearance Command

More information

PC-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. 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

INTRODUCTION TO NUMERICAL ANALYSIS

INTRODUCTION 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 information

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

MATLAB 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 information

MATLAB TUTORIAL WORKSHEET

MATLAB TUTORIAL WORKSHEET MATLAB TUTORIAL WORKSHEET What is MATLAB? Software package used for computation High-level programming language with easy to use interactive environment Access MATLAB at Tufts here: https://it.tufts.edu/sw-matlabstudent

More information

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

MATLAB BASICS. < Any system: Enter quit at Matlab prompt < PC/Windows: Close command window < To interrupt execution: Enter Ctrl-c. MATLAB BASICS Starting Matlab < PC: Desktop icon or Start menu item < UNIX: Enter matlab at operating system prompt < Others: Might need to execute from a menu somewhere Entering Matlab commands < Matlab

More information

A very brief Matlab introduction

A very brief Matlab introduction A very brief Matlab introduction Siniša Krajnović January 24, 2006 This is a very brief introduction to Matlab and its purpose is only to introduce students of the CFD course into Matlab. After reading

More information

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

What 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 information

EE 216 Experiment 1. MATLAB Structure and Use

EE 216 Experiment 1. MATLAB Structure and Use EE216:Exp1-1 EE 216 Experiment 1 MATLAB Structure and Use This first laboratory experiment is an introduction to the use of MATLAB. The basic computer-user interfaces, data entry techniques, operations,

More information

Chapter 1 Introduction to MATLAB

Chapter 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 information

Matlab Tutorial: Basics

Matlab Tutorial: Basics Matlab Tutorial: Basics Topics: opening matlab m-files general syntax plotting function files loops GETTING HELP Matlab is a program which allows you to manipulate, analyze and visualize data. MATLAB allows

More information

FDP on Electronic Design Tools - Computing with MATLAB 13/12/2017. A hands-on training session on. Computing with MATLAB

FDP on Electronic Design Tools - Computing with MATLAB 13/12/2017. A hands-on training session on. Computing with MATLAB A hands-on training session on Computing with MATLAB in connection with the FDP on Electronic Design Tools @ GCE Kannur 11 th 15 th December 2017 Resource Person : Dr. A. Ranjith Ram Associate Professor,

More information

Introduction to Matlab for Engineers

Introduction 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 information

MATLAB Introduction to MATLAB Programming

MATLAB 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 information

Plotting - Practice session

Plotting - 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 information

A Short Tutorial on Matlab ( by T. Co, 2003,2004 )

A Short Tutorial on Matlab ( by T. Co, 2003,2004 ) A Short Tutorial on Matlab ( by T. Co, 2003,2004 ) Part I. BASICS I. Assigning Values to Variables, Vectors and Matrices Use the equality symbol, e.g. A=3 Variables are case sensitive: temperature is not

More information

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

Graphics 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 information

Introduction to Matlab. By: Dr. Maher O. EL-Ghossain

Introduction to Matlab. By: Dr. Maher O. EL-Ghossain Introduction to Matlab By: Dr. Maher O. EL-Ghossain Outline: q What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display Facilities Flow Control

More information

ENGR 1181 MATLAB 09: For Loops 2

ENGR 1181 MATLAB 09: For Loops 2 ENGR 1181 MATLAB 09: For Loops Learning Objectives 1. Use more complex ways of setting the loop index. Construct nested loops in the following situations: a. For use with two dimensional arrays b. For

More information

Computer exercise 1 Introduction to Matlab.

Computer exercise 1 Introduction to Matlab. Chalmers-University of Gothenburg Department of Mathematical Sciences Probability, Statistics and Risk MVE300 Computer exercise 1 Introduction to Matlab. Understanding Distributions In this exercise, you

More information

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

Lab 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 information

Lab of COMP 406. MATLAB: Quick Start. Lab tutor : Gene Yu Zhao Mailbox: or Lab 1: 11th Sep, 2013

Lab of COMP 406. MATLAB: Quick Start. Lab tutor : Gene Yu Zhao Mailbox: or Lab 1: 11th Sep, 2013 Lab of COMP 406 MATLAB: Quick Start Lab tutor : Gene Yu Zhao Mailbox: csyuzhao@comp.polyu.edu.hk or genexinvivian@gmail.com Lab 1: 11th Sep, 2013 1 Where is Matlab? Find the Matlab under the folder 1.

More information

Lecture 3 for Math 398 Section 952: Graphics in Matlab

Lecture 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 information

! The MATLAB language

! The MATLAB language E2.5 Signals & Systems Introduction to MATLAB! MATLAB is a high-performance language for technical computing. It integrates computation, visualization, and programming in an easy-to -use environment. Typical

More information

What is Matlab? The command line Variables Operators Functions

What is Matlab? The command line Variables Operators Functions What is Matlab? The command line Variables Operators Functions Vectors Matrices Control Structures Programming in Matlab Graphics and Plotting A numerical computing environment Simple and effective programming

More information

MATLAB SUMMARY FOR MATH2070/2970

MATLAB 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 information

MATLAB for beginners. KiJung Yoon, 1. 1 Center for Learning and Memory, University of Texas at Austin, Austin, TX 78712, USA

MATLAB for beginners. KiJung Yoon, 1. 1 Center for Learning and Memory, University of Texas at Austin, Austin, TX 78712, USA MATLAB for beginners KiJung Yoon, 1 1 Center for Learning and Memory, University of Texas at Austin, Austin, TX 78712, USA 1 MATLAB Tutorial I What is a matrix? 1) A way of representation for data (# of

More information

W1005 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. 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 information

FF505/FY505 Computational Science. MATLAB Graphics. Marco Chiarandini

FF505/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 information

Experiment 1: Introduction to MATLAB I. Introduction. 1.1 Objectives and Expectations: 1.2 What is MATLAB?

Experiment 1: Introduction to MATLAB I. Introduction. 1.1 Objectives and Expectations: 1.2 What is MATLAB? Experiment 1: Introduction to MATLAB I Introduction MATLAB, which stands for Matrix Laboratory, is a very powerful program for performing numerical and symbolic calculations, and is widely used in science

More information

An Introduction to MATLAB. Lab tutor : Dennis Yang LIU Lab 1: Sept. 11, 2014

An Introduction to MATLAB. Lab tutor : Dennis Yang LIU   Lab 1: Sept. 11, 2014 Lab 1 of COMP 319 An Introduction to MATLAB Lab tutor : Dennis Yang LIU Email: csygliu@comp.polyu.edu.hk Lab 1: Sept. 11, 2014 1 Outline of Lab 1 Introduction to the Lab Matlab overview Basic manipulation

More information

Tutorials for the User-Friendly EST Software

Tutorials for the User-Friendly EST Software Tutorials for the User-Friendly EST Software Installing the Program 1) To begin installation, run the setup.exe file. 2) Agree to install the Runtime Compiler for Matlab as it is essential to running the

More information

Introduction to Matlab. By: Hossein Hamooni Fall 2014

Introduction to Matlab. By: Hossein Hamooni Fall 2014 Introduction to Matlab By: Hossein Hamooni Fall 2014 Why Matlab? Data analytics task Large data processing Multi-platform, Multi Format data importing Graphing Modeling Lots of built-in functions for rapid

More information

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

Math Sciences Computing Center. University ofwashington. September, Fundamentals Making Plots Printing and Saving Graphs... Introduction to Plotting with Matlab Math Sciences Computing Center University ofwashington September, 1996 Contents Fundamentals........................................... 1 Making Plots...........................................

More information

Introduction to Matlab

Introduction to Matlab Technische Universität München WT 21/11 Institut für Informatik Prof Dr H-J Bungartz Dipl-Tech Math S Schraufstetter Benjamin Peherstorfer, MSc October 22nd, 21 Introduction to Matlab Engineering Informatics

More information

Matlab Lecture 1 - Introduction to MATLAB. Five Parts of Matlab. Entering Matrices (2) - Method 1:Direct entry. Entering Matrices (1) - Magic Square

Matlab Lecture 1 - Introduction to MATLAB. Five Parts of Matlab. Entering Matrices (2) - Method 1:Direct entry. Entering Matrices (1) - Magic Square Matlab Lecture 1 - Introduction to MATLAB Five Parts of Matlab MATLAB is a high-performance language for technical computing. It integrates computation, visualization, and programming in an easy-touse

More information

TILING PROBLEMS: FROM DOMINOES, CHECKERBOARDS, AND MAZES TO DISCRETE GEOMETRY

TILING PROBLEMS: FROM DOMINOES, CHECKERBOARDS, AND MAZES TO DISCRETE GEOMETRY TILING PROBLEMS: FROM DOMINOES, CHECKERBOARDS, AND MAZES TO DISCRETE GEOMETRY BERKELEY MATH CIRCLE 1. Looking for a number Consider an 8 8 checkerboard (like the one used to play chess) and consider 32

More information

Compact Matlab Course

Compact Matlab Course Compact Matlab Course MLC.1 15.04.2014 Matlab Command Window Workspace Command History Directories MLC.2 15.04.2014 Matlab Editor Cursor in Statement F1 Key goes to Help Information MLC.3 15.04.2014 Elementary

More information

Colorado State University Department of Mechanical Engineering. MECH Laboratory Exercise #1 Introduction to MATLAB

Colorado State University Department of Mechanical Engineering. MECH Laboratory Exercise #1 Introduction to MATLAB Colorado State University Department of Mechanical Engineering MECH 417 - Laboratory Exercise #1 Introduction to MATLAB Contents 1) Vectors and Matrices... 2 2) Polynomials... 3 3) Plotting and Printing...

More information

An Introduction to MATLAB II

An Introduction to MATLAB II Lab of COMP 319 An Introduction to MATLAB II Lab tutor : Gene Yu Zhao Mailbox: csyuzhao@comp.polyu.edu.hk or genexinvivian@gmail.com Lab 2: 16th Sep, 2013 1 Outline of Lab 2 Review of Lab 1 Matrix in Matlab

More information

MATLAB An introductory tutorial

MATLAB An introductory tutorial MATLAB An introductory tutorial By Carin Nilsson Dept. of Physical Geography and Ecosystems Analysis (taken from the tutorials for course NGE604 Climate Systems) And Chantal Donnelly (Dept. of Water Resources

More information

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

Classes 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 information

More on Plots. Dmitry Adamskiy 30 Nov 2011

More 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 information

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #16 Loops: Matrix Using Nested for Loop

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #16 Loops: Matrix Using Nested for Loop Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #16 Loops: Matrix Using Nested for Loop In this section, we will use the, for loop to code of the matrix problem.

More information

GRAPHICS AND VISUALISATION WITH MATLAB

GRAPHICS 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 information

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB 1 Introduction to MATLAB A Tutorial for the Course Computational Intelligence http://www.igi.tugraz.at/lehre/ci Stefan Häusler Institute for Theoretical Computer Science Inffeldgasse

More information

The 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 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 information

Attia, John Okyere. Control Statements. Electronics and Circuit Analysis using MATLAB. Ed. John Okyere Attia Boca Raton: CRC Press LLC, 1999

Attia, John Okyere. Control Statements. Electronics and Circuit Analysis using MATLAB. Ed. John Okyere Attia Boca Raton: CRC Press LLC, 1999 Attia, John Okyere. Control Statements. Electronics and Circuit Analysis using MATLAB. Ed. John Okyere Attia Boca Raton: CRC Press LLC, 1999 1999 by CRC PRESS LLC CHAPTER THREE CONTROL STATEMENTS 3.1 FOR

More information

Matlab Tutorial and Exercises for COMP61021

Matlab Tutorial and Exercises for COMP61021 Matlab Tutorial and Exercises for COMP61021 1 Introduction This is a brief Matlab tutorial for students who have not used Matlab in their programming. Matlab programming is essential in COMP61021 as a

More information

2.0 MATLAB Fundamentals

2.0 MATLAB Fundamentals 2.0 MATLAB Fundamentals 2.1 INTRODUCTION MATLAB is a computer program for computing scientific and engineering problems that can be expressed in mathematical form. The name MATLAB stands for MATrix LABoratory,

More information

MAT 275 Laboratory 3 Numerical Solutions by Euler and Improved Euler Methods (scalar equations)

MAT 275 Laboratory 3 Numerical Solutions by Euler and Improved Euler Methods (scalar equations) MATLAB sessions: Laboratory 3 1 MAT 275 Laboratory 3 Numerical Solutions by Euler and Improved Euler Methods (scalar equations) In this session we look at basic numerical methods to help us understand

More information

6 Appendix B: Quick Guide to MATLAB R

6 Appendix B: Quick Guide to MATLAB R 6 Appendix B: Quick Guide to MATLAB R 6.1 Introduction In this course we will be using the software package MATLAB R. Version 17.12.0, Release R2011a has been installed in Foster 100, the labs on the third

More information

CSE/NEUBEH 528 Homework 0: Introduction to Matlab

CSE/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 information

Matlab Tutorial for COMP24111 (includes exercise 1)

Matlab Tutorial for COMP24111 (includes exercise 1) Matlab Tutorial for COMP24111 (includes exercise 1) 1 Exercises to be completed by end of lab There are a total of 11 exercises through this tutorial. By the end of the lab, you should have completed the

More information

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

UNIVERSITI 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 information

MATLAB Basics. Configure a MATLAB Package 6/7/2017. Stanley Liang, PhD York University. Get a MATLAB Student License on Matworks

MATLAB Basics. Configure a MATLAB Package 6/7/2017. Stanley Liang, PhD York University. Get a MATLAB Student License on Matworks MATLAB Basics Stanley Liang, PhD York University Configure a MATLAB Package Get a MATLAB Student License on Matworks Visit MathWorks at https://www.mathworks.com/ It is recommended signing up with a student

More information

Matlab Tutorial. The value assigned to a variable can be checked by simply typing in the variable name:

Matlab Tutorial. The value assigned to a variable can be checked by simply typing in the variable name: 1 Matlab Tutorial 1- What is Matlab? Matlab is a powerful tool for almost any kind of mathematical application. It enables one to develop programs with a high degree of functionality. The user can write

More information

MAT 343 Laboratory 4 Plotting and computer animation in MATLAB

MAT 343 Laboratory 4 Plotting and computer animation in MATLAB MAT 4 Laboratory 4 Plotting and computer animation in MATLAB In this laboratory session we will learn how to. Plot in MATLAB. The geometric properties of special types of matrices (rotations, dilations,

More information

HW 4 HINTS. 1. Chapter 6

HW 4 HINTS. 1. Chapter 6 HW 4 HINTS 1. Chapter 6 ***IMPORTANT GENERAL GUIDELINE*** When running commands inside loops and conditional statements, in general ALL output should be suppressed by placing a semicolon at the of the

More information

CS/NEUR125 Brains, Minds, and Machines. Due: Wednesday, March 8

CS/NEUR125 Brains, Minds, and Machines. Due: Wednesday, March 8 CS/NEUR125 Brains, Minds, and Machines Lab 6: Inferring Location from Hippocampal Place Cells Due: Wednesday, March 8 This lab explores how place cells in the hippocampus encode the location of an animal

More information

EGR 102 Introduction to Engineering Modeling. Lab 10A Nested Programming II Iterative Nesting

EGR 102 Introduction to Engineering Modeling. Lab 10A Nested Programming II Iterative Nesting EGR 102 Introduction to Engineering Modeling Lab 10A Nested Programming II Iterative Nesting 1 Overview 1. Nested loops 2. Nested loop: Creating Arrays 3. Nested Loops: 2 Variable functions 4. Nested Loops

More information

Computing Fundamentals Plotting

Computing 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 information

MAT 275 Laboratory 3 Numerical Solutions by Euler and Improved Euler Methods (scalar equations)

MAT 275 Laboratory 3 Numerical Solutions by Euler and Improved Euler Methods (scalar equations) MAT 275 Laboratory 3 Numerical Solutions by Euler and Improved Euler Methods (scalar equations) In this session we look at basic numerical methods to help us understand the fundamentals of numerical approximations.

More information

LAB 1 General MATLAB Information 1

LAB 1 General MATLAB Information 1 LAB 1 General MATLAB Information 1 General: To enter a matrix: > type the entries between square brackets, [...] > enter it by rows with elements separated by a space or comma > rows are terminated by

More information

On Your Own. ). Another way is to multiply the. ), and the image. Applications. Unit 3 _ _

On Your Own. ). Another way is to multiply the. ), and the image. Applications. Unit 3 _ _ Applications 1 a 90 clockwise rotation matrix: - b As can be seen by the diagram, the image of P is Q and the image of R is P The coordinate of Q can be found by symmetry y R 1 P, Thus, the 45 clockwise

More information

A Very Brief Introduction to Matlab

A Very Brief Introduction to Matlab A Very Brief Introduction to Matlab by John MacLaren Walsh, Ph.D. for ECES 63 Fall 26 October 3, 26 Introduction To MATLAB You can type normal mathematical operations into MATLAB as you would in an electronic

More information

v Importing Rasters SMS 11.2 Tutorial Requirements Raster Module Map Module Mesh Module Time minutes Prerequisites Overview Tutorial

v Importing Rasters SMS 11.2 Tutorial Requirements Raster Module Map Module Mesh Module Time minutes Prerequisites Overview Tutorial v. 11.2 SMS 11.2 Tutorial Objectives This tutorial teaches how to import a Raster, view elevations at individual points, change display options for multiple views of the data, show the 2D profile plots,

More information

Programming 1. Script files. help cd Example:

Programming 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 information

Short Version of Matlab Manual

Short Version of Matlab Manual Short Version of Matlab Manual This is an extract from the manual which was used in MA10126 in first year. Its purpose is to refamiliarise you with the matlab programming concepts. 1 Starting MATLAB 1.1.1.

More information

Introduction to MATLAB LAB 1

Introduction 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 information

Math 241: Matlab Notes. Dr. Randall Paul

Math 241: Matlab Notes. Dr. Randall Paul Math 241: Matlab Notes Dr. Randall Paul March 5, 2006 Contents 1 Basic Commands 2 1.1 Introduction.................................... 2 1.2 Matlab as Calculator............................... 2 1.3 Formatting

More information

Chapter 4. Part 1 AutoCAD Basics

Chapter 4. Part 1 AutoCAD Basics Chapter 4. Part 1 AutoCAD Basics Chapter Objectives Describe the AutoCAD screen layout. Perform an AutoCAD drawing setup, including setting units, limits, layers, linetypes, and lineweights. Explain the

More information

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

Matlab 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 information

An Introduction to Numerical Methods

An Introduction to Numerical Methods An Introduction to Numerical Methods Using MATLAB Khyruddin Akbar Ansari, Ph.D., P.E. Bonni Dichone, Ph.D. SDC P U B L I C AT I O N S Better Textbooks. Lower Prices. www.sdcpublications.com Powered by

More information

CE890 / ENE801 Lecture 1 Introduction to MATLAB

CE890 / ENE801 Lecture 1 Introduction to MATLAB CE890 / ENE801 Lecture 1 Introduction to MATLAB CE890: Course Objectives Become familiar with a powerful tool for computations and visualization (MATLAB) Promote problem-solving skills using computers

More information

PASS Sample Size Software

PASS Sample Size Software Chapter 941 Introduction In PASS, it is easy to study power and sample size calculations for a range of possible parameter values. When at least 2 input parameters vary, you can create stunning 3D power

More information

Mechanical Engineering Department Second Year (2015)

Mechanical 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 information

Dynamic Programming. An Introduction to DP

Dynamic Programming. An Introduction to DP Dynamic Programming An Introduction to DP Dynamic Programming? A programming technique Solve a problem by breaking into smaller subproblems Similar to recursion with memoisation Usefulness: Efficiency

More information

How to Use MATLAB. What is MATLAB. Getting Started. Online Help. General Purpose Commands

How to Use MATLAB. What is MATLAB. Getting Started. Online Help. General Purpose Commands How to Use MATLAB What is MATLAB MATLAB is an interactive package for numerical analysis, matrix computation, control system design and linear system analysis and design. On the server bass, MATLAB version

More information

Introduction to MATLAB

Introduction to MATLAB Quick Start Tutorial Introduction to MATLAB Hans-Petter Halvorsen, M.Sc. What is MATLAB? MATLAB is a tool for technical computing, computation and visualization in an integrated environment. MATLAB is

More information

Getting started with MATLAB

Getting started with MATLAB Sapienza University of Rome Department of economics and law Advanced Monetary Theory and Policy EPOS 2013/14 Getting started with MATLAB Giovanni Di Bartolomeo giovanni.dibartolomeo@uniroma1.it Outline

More information

Introduction to Programming in MATLAB

Introduction 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 information

Numerical Methods Lecture 1

Numerical Methods Lecture 1 Numerical Methods Lecture 1 Basics of MATLAB by Pavel Ludvík The recommended textbook: Numerical Methods Lecture 1 by Pavel Ludvík 2 / 30 The recommended textbook: Title: Numerical methods with worked

More information

Finding MATLAB on CAEDM Computers

Finding MATLAB on CAEDM Computers Lab #1: Introduction to MATLAB Due Tuesday 5/7 at noon This guide is intended to help you start, set up and understand the formatting of MATLAB before beginning to code. For a detailed guide to programming

More information

MATLAB Guide to Fibonacci Numbers

MATLAB 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 information

MATH 2221A Mathematics Laboratory II

MATH 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 information