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

Similar documents
INTRODUCTION TO MATLAB PLOTTING WITH MATLAB

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

Basic Graphs. Dmitry Adamskiy 16 November 2011

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

INTRODUCTION TO MATLAB

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

Prof. Manoochehr Shirzaei. RaTlab.asu.edu

Getting Started with MATLAB

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

Mechanical Engineering Department Second Year (2015)

Introduction to Matlab

Introduction to MATLAB

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

An Introduction to MATLAB II

Introduction to MATLAB

QUICK INTRODUCTION TO MATLAB PART I

Introduction to MATLAB

MATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP)

Lecturer: Keyvan Dehmamy

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

A very brief Matlab introduction

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

Introduction to MATLAB

Introduction to MATLAB

Introduction to Matlab

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY

Introduction to MATLAB

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

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

CSE/NEUBEH 528 Homework 0: Introduction to Matlab

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

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

PART 1 PROGRAMMING WITH MATHLAB

What is Matlab? A software environment for interactive numerical computations

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

Introduction to MATLAB LAB 1

MATLAB Guide to Fibonacci Numbers

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

Dr. Iyad Jafar. Adapted from the publisher slides

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

MATH (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab

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

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

Introduction to MatLab. Introduction to MatLab K. Craig 1

Chapter 2. MATLAB Fundamentals

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

Introduction to Matlab. Summer School CEA-EDF-INRIA 2011 of Numerical Analysis

1 Introduction to Matlab

Programming in Mathematics. Mili I. Shah

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

Objectives. 1 Running, and Interface Layout. 2 Toolboxes, Documentation and Tutorials. 3 Basic Calculations. PS 12a Laboratory 1 Spring 2014

A Brief Introduction to MATLAB

INTRODUCTION TO NUMERICAL ANALYSIS

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

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

Evolutionary Algorithms. Workgroup 1

Introduction to Matlab

AMS 27L LAB #2 Winter 2009

Introduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures

Introduction to MATLAB Programming. Chapter 3. Linguaggio Programmazione Matlab-Simulink (2017/2018)

Table of Contents. Basis CEMTool 7 Tutorial

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

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX

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

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

OUTLINES. Variable names in MATLAB. Matrices, Vectors and Scalar. Entering a vector Colon operator ( : ) Mathematical operations on vectors.

Introduction to MATLAB

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

A Very Brief Introduction to Matlab

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

MATLAB The first steps. Edited by Péter Vass

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

Computer Programming in MATLAB

Getting started with MATLAB

Introduction to Matlab

Laboratory 1 Octave Tutorial

Purpose of the lecture MATLAB MATLAB

Matlab Programming MET 164 1/24

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

Matlab Tutorial: Basics

LabVIEW MathScript Quick Reference

Here is a quick introduction to Matlab and a couple of its symbolic and control functions.

Physics 326G Winter Class 2. In this class you will learn how to define and work with arrays or vectors.

2.0 MATLAB Fundamentals

Lecture 2 Introduction to MATLAB. Dr.Tony Cahill

EEE161 Applied Electromagnetics Laboratory 1

MatLab Just a beginning

Finding, Starting and Using Matlab

1. Register an account on: using your Oxford address

Lecture 1: What is MATLAB?

Introduction to Engineering gii

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

Objectives. 1 Basic Calculations. 2 Matrix Algebra. Physical Sciences 12a Lab 0 Spring 2016

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

! The MATLAB language

Introduction to Matlab. WIAA Technical Workshop #2 10/20/2015

Introduzione a MatLab. Prof. Sebastiano Battiato

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

Modeling and Simulating Social Systems with MATLAB

Transcription:

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 for scientific visualizations It is a high-level programming language

Characteristics of MATLAB Programming language based (principally) on matrices. Slow (compared with fortran or C) because it is an interpreted language,i.e.not pre-compiled. Avoid for loops; instead use vector form whenever possible. Automatic memory management, i.e., you don't have to declare arrays in advance. Intuitive, easy to use. Shorter program development time than traditional programming languages such as Fortran and C. Can be converted into C code via MATLAB compiler for better efficiency. Many application-specific toolboxes available.

Start menu Matlab MATLAB שורת הפקוד ה << >> date

Getting Help >> help date >> helpwin date helpwin gives you the same information as help, but in a different window.

Getting Help >> doc date >> lookfor date % search for keywords that best describe the function >> Ctrl+C % stop Matlab from running >> clc % clear screen

Special characters >> % default command prompt % % comment - MATLAB simply ignores anything to the right of this sign (till the end of the line). >> % my comment ; % semicolon at the end of the line will prevent MATLAB from echoing the information you type on the screen. >> a=20 >> B=20;

Creating Variables Matlab as a calculator: >>2+5 >>7*10+8 >>5^2 ans - "answer", used in MATLAB as the default variable.

Defining Your Own Variables When Matlab comes across a new variable name it automatically creates it. Begins with a LETTER, e.g., A2z. Can be a mix of letters, digits, and underscores (e.g., vector_a, but not vector-a) Not longer than 31 characters. No spaces Different mixes of capital and small letters = different variables. For example: "A_VaRIAbLe", "a_variable", "A_VARIABLE", and "A_variablE >> String='this is a string'

Listing & Clearing Variables >> a=10 >> b = 20 >> the_average = (a + b ) / 2 >> whos >> clear %clear variables from memory

Creating vectors Column separator: space/coma (,) Row separator: Semicolon (;) Creating sequences: From : jump: till

Creating Matrices Matrices must be rectangular. Creating random matrices: 2-by-4 random matrix (2 rows and 4 columns).

Creating Matrices You can combine existing vectors as matrix elements: You can combine existing matrices as matrix elements:

Indexing Into a Matrix >> mat_from_mat(8) >> mat_from_mat(4,2)=0 >> mat_from_mat The row number is first, followed by the column number.

Linear Algebra Operations

Matrix Multiplication Inner dimensions must be equal Dimension of resulting matrix = outermost dimensions of multiplied matrices Resulting elements = dot product of the rows of the 1st matrix with the columns of the 2nd matrix

Vector Multiplication Type the following: >>a=[2 3] >>b=[3 2] >>a*b >>a.*b >>a.*b' >>a*b'

Example: Solving Equations Solve this set of simultaneous equations

Array Operations

Boolean Operators & Indexing

String Arrays Created using single quote delimiter (') Each character is a separate matrix element (16 bits of memory per character) Indexing same as for numeric arrays

String Array Concatenation

Working with String Arrays

Line Plots in Two Dimensions Plot (x,y) makes a two-dimensional line plot for each point in X and its corresponding point in Y: (X(1),Y(1)), (X(2),Y(2)), (X(3),Y(3)), etc., and then connect all these points together with line. Example: >> x=1:1:5; >>y=[2 7 0-8 6]; >> plot (x,y); >> xlabel ('label for x-axis') >> ylabel ('label for y-axis') >> title ('title')

Multiple Plots Check the following: x_points = [-10 :.05 : 10]; plot(x_points, exp(x_points)); grid on hold on plot(x_points, exp(.95.* x_points), 'm'); plot(x_points, exp(.85.* x_points), 'g'); plot(x_points, exp(.75.* x_points), 'p'); xlabel('x-axis'); ylabel('y-axis'); title('comparing Exponential Functions'); legend ('1', '2', '3', '4') y-axis 2.5 x 104 2 1.5 1 0.5 Comparing Exponential Functions 0-10 -5 0 5 10 x-axis 1 2 3 4

Subplots multiple plots in the same window, each with their own axes. Subplot (M,N,P) M rows N - columns P number of subplot in the figure Subplot (2,2,1)

More about figures Figure % Open a new figure without closing old figures Figure (i) % Open the i-th figure Close all % close all open figures axis ([xmin xmax ymin ymax]) % sets scaling for the x- and y-axes on the current plot.

Special Graph Annotations (TeX)

Plot Editor Toolbar

Exercise Create the following: 2 1.5 Merav's graph sin(x) log(x) 1 y 0.5 0-0.5-1 1 1.5 2 2.5 3 3.5 4 4.5 5 x x = (1, 1.05, 1.1, 1.15 5) Y=sin(x) Z=log(x) Put your name in the title Hint: check the doc linespec.

Solution >>x=1:0.05:5; >>y=sin(x); >>z=log(x); >> hold on >> plot (x,y,'-.r*') >> plot (x,z,'-.go') >> hold off >> title ('Merav''s graph'); >> xlabel ('x') >> ylabel ('y') >> legend ('sin(x)', 'log(x)');

More exercise Make a 3 three-dimensional graph of (x,y,z) use Matlab help. Make two separate 2-D graphs, with separate axis, in the same window: y vs. x, and z vs. x. 1 sin(x) 1.8 log(x) 3D graph 0.8 0.6 0.4 1.6 1.4 1.2 2 1.5 y=sin(x) 0.2 0-0.2 z 1 0.8 z 1 0.5-0.4-0.6-0.8-1 1 2 3 4 5 x 0.6 0.4 0.2 0 1 2 3 4 5 x 0 1 0.5 0 y -0.5-1 1 2 x 3 4 5

Solution 3-D graph: >> plot3(x,y,z) >> grid >> xlabel ('x') >> ylabel('y') >> zlabel('z') >> title ('3D graph') Subplots >> subplot (1,2,1); >> plot(x,y); >> title ('sin(x)'); >> xlabel('x'); >> ylabel('y=sin(x)'); >> grid; >> subplot (1,2,2); >> plot(x,z); >> xlabel('x'); >> title ('log(x)'); >> grid; >> ylabel ('z');

Surface Mesh plots 1) Generate a grid of points in the xy-plane using the meshgrid command. 2) Evaluate the three-dimensional function at these points. 3) Create the surface plot with the mesh command. Meshgrid - returns all possible combinations of (x,y) points, where x is taken from X and y is taken from Y, in the form of two matrices. you will see in the generated surface mesh plot a bunch of rectangles, of width and length equal to the regular spacing values for X and Y, and the height of the corners of the rectangles will be equal to the value of the function at the rectangles' corner points)

1. >> x_points = [-10 : 1 : 10]; >> y_points = [-10 : 4 : 10]; >> [X, Y] = meshgrid(x_points,y_points); 2. >> Z = X.^2 + Y.^2; 3. >> mesh(x,y,z); >> xlabel('x-axis'); >> ylabel('y-axis'); >> zlabel('z-axis'); z-axis 200 180 160 140 120 100 80 60 40 20 0 10 X: -9 Y: -10 Z: 181 5 0 y-axis -5-10 -10-8 -6-4 -2 x-axis 0 2 4 6 8 10