Stokes Modelling Workshop

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

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

A very brief Matlab introduction

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

Introduction to MATLAB

Lecturer: Keyvan Dehmamy

STAT/MATH 395 A - PROBABILITY II UW Winter Quarter Matlab Tutorial

A Brief Introduction to MATLAB

Laboratory 1 Octave Tutorial

MATLAB Lesson I. Chiara Lelli. October 2, Politecnico di Milano

Introduction to Matlab

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

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures

Introduction to Matlab

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

MATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix.

This is a basic tutorial for the MATLAB program which is a high-performance language for technical computing for platforms:

ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah)

MATLAB TUTORIAL WORKSHEET

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

Dr Richard Greenaway

Outline. CSE 1570 Interacting with MATLAB. Outline. Starting MATLAB. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

An Introduction to MATLAB II

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

Getting started with MATLAB

Finding, Starting and Using Matlab

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

Chapter 3. built in functions help feature elementary math functions data analysis functions random number functions computational limits

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY

MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras

Matlab Tutorial, CDS

Introduction to Engineering gii

Introduction to MATLAB. Computational Probability and Statistics CIS 2033 Section 003

Introduction to MATLAB LAB 1

MATLAB Premier. Middle East Technical University Department of Mechanical Engineering ME 304 1/50

MATLAB Tutorial EE351M DSP. Created: Thursday Jan 25, 2007 Rayyan Jaber. Modified by: Kitaek Bae. Outline

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

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS

Chapter 1 Introduction to MATLAB

What is Matlab? A software environment for interactive numerical computations

How to learn MATLAB? Some predefined variables

Matlab (Matrix laboratory) is an interactive software system for numerical computations and graphics.

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

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

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline (Cont d) MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An

Matlab Workshop I. Niloufer Mackey and Lixin Shen

Introduction to MATLAB

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX

1 Introduction to MATLAB

An Introductory Tutorial on Matlab

MATLAB Premier. Asst. Prof. Dr. Melik DÖLEN. Middle East Technical University Department of Mechanical Engineering 10/30/04 ME 304 1

Introduction to MATLAB

Matlab Tutorial. Get familiar with MATLAB by using tutorials and demos found in MATLAB. You can click Start MATLAB Demos to start the help screen.

Introduction to MATLAB

Matlab 1: Get Started

MATLAB Introductory Course Computer Exercise Session

Grace days can not be used for this assignment

Introduction in MATLAB (TSRT04)

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

EE 301 Signals & Systems I MATLAB Tutorial with Questions

Mathworks (company that releases Matlab ) documentation website is:

Lecture 1: What is MATLAB?

Introduzione a MatLab. Prof. Sebastiano Battiato

Introduction to MATLAB. Simon O Keefe Non-Standard Computation Group

ČVUT v Praze in Prague. Introduction to MATLAB

Matlab Introduction. Scalar Variables and Arithmetic Operators

A Brief MATLAB Tutorial

CSE/NEUBEH 528 Homework 0: Introduction to Matlab

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

Introduction to MATLAB Practical 1

A General Introduction to Matlab

CSE/Math 485 Matlab Tutorial and Demo

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

Introduction to MATLAB

Fall 2014 MAT 375 Numerical Methods. Introduction to Programming using MATLAB

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

Introduction to MATLAB Programming

Chapter 1 MATLAB Preliminaries

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

Introduction to GNU-Octave

Some elements for Matlab programming

A Guide to Using Some Basic MATLAB Functions

Desktop Command window

CSE/Math 456 and CSE/Math 550 Matlab Tutorial and Demo

PART 1 PROGRAMMING WITH MATHLAB

! The MATLAB language

Matlab and Octave: Quick Introduction and Examples 1 Basics

A QUICK INTRODUCTION TO MATLAB

A Quick Tutorial on MATLAB. Zeeshan Ali

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

AMATH 352: MATLAB Tutorial written by Peter Blossey Department of Applied Mathematics University of Washington Seattle, WA

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

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

1. Register an account on: using your Oxford address

Short Introduction into MATLAB

Introduction to MATLAB programming: Fundamentals

Signals and Systems Profs. Byron Yu and Pulkit Grover Fall Homework 1

A QUICK INTRODUCTION TO MATLAB. Intro to matlab getting started

Basics: vectors, matrices, arrays

Repetition Structures Chapter 9

Transcription:

Stokes Modelling Workshop 14/06/2016 Introduction to Matlab www.maths.nuigalway.ie/modellingworkshop16/files 14/06/2016 Stokes Modelling Workshop Introduction to Matlab 1 / 16

Matlab As part of this crash course you will learn how to use Matlab (for MATrix LABoratory ). Matlab is an extraordinarily useful tool for all kinds of analysis and design. Start the Matlab program by clicking on the Matlab symbol. The Matlab command window will appear. You will see that the window has several panes. We will be entering commands into the Command Window. Defined variables appear in the Workspace window (upper left side) and previous commands appear in the Command History window (lower left). It is possible to use the command window as a normal caculator. We can for instance write >> 2+4 >> 2^4 ans = ans = 6 16 14/06/2016 Stokes Modelling Workshop Introduction to Matlab 2 / 16

Elementary functions Type >> help in the command window and you will get a list useful functions, such as sin, cos, tan, exp, abs, log, sqrt, round It is also possible to write >> help ops >> doc ops which gives you a list of useful operators, such as +, -, *, ^, /, \,.*,./ The most comprehensive help is given if you write helpdesk. 14/06/2016 Stokes Modelling Workshop Introduction to Matlab 3 / 16

Special variables and constants Some operators ans Most recent answer. Inf Infinity eps Floating-point relative accuracy. NaN Not a number i,j Imaginary unit. pi 3.141592653589793 Time clock Wall clock. etime Elapsed time function. cputime Ellapse CPU time. tic, toc Stopwatch timer function date Calendar. 14/06/2016 Stokes Modelling Workshop Introduction to Matlab 4 / 16

Vectors Create a row vector v with elements 1, 3, 4, 6 >> v = [1,3,4,6] v = 1 3 4 6 and create a column vector v with elements 1, 3, 4, 6 >> v1 = [1;3;4;6] >> w = v v1 = w = 1 1 3 3 4 4 6 6 Notitce that the transpose operator is thus given by. 14/06/2016 Stokes Modelling Workshop Introduction to Matlab 5 / 16

Vectors Create a row vector v with elements 1, 2,..., 7 >> v = 1:7 v = 1 2 3 4 5 6 7 and create a row vector v with elements 1.1, 1.3,..., 1.9 write >> v = 1.1:0.2:1.9 v = 1.1000 1.3000 1.5000 1.7000 1.9000 14/06/2016 Stokes Modelling Workshop Introduction to Matlab 6 / 16

Matrices To create a 2 3 matrix M with elements 1, 3, 4, 6, 7, 9 write either >> M = [1,3,4;6,7,9] M = 1 3 4 6 7 9 or >> M = [1 3 4 6 7 9] M = 1 3 4 6 7 9 or 14/06/2016 Stokes Modelling Workshop Introduction to Matlab 7 / 16

Matrices >> M(1,1) = 1; M(1,2) = 3; M(1,3) = 4; M(2,1) = 6; M(2,2) = 7; M(2,3) = 9; >> M M = 1 3 4 6 7 9 or >> M(1,:) = [1,3,4]; M(2,:) = [6,7,9]; >> M M = 1 3 4 6 7 9 or 14/06/2016 Stokes Modelling Workshop Introduction to Matlab 8 / 16

Matrices >> M(:,1) = [1;6]; M(:,2) = [3;7]; M(:,3) = [4;9]; >> M M = 1 3 4 6 7 9 To create a 3 3 identity matrix Id write >> Id = eye(3) Id = 1 0 0 0 1 0 0 0 1 14/06/2016 Stokes Modelling Workshop Introduction to Matlab 9 / 16

Boolean operators and functions Some operators < less than > greater than <= less than or equal to >= greater than or equal to & logical AND logical OR ~ logical NOT xor logical EXCLUSIVE OR Functions all find True if all elements of a vector is true. Find indicies of nonzero elements. 14/06/2016 Stokes Modelling Workshop Introduction to Matlab 10 / 16

M-File scripts When using Matlab as mathematical computing tool, and not only a calculator, it is more convenient to write your code in a file that can be saved, instead of in the command window. By doing this you can return to the code at a later time. The extension of executable files in matlab is.m. Scripts are the simplest kind of M-file because they have no input or output arguments. They are useful for automating series of Matlab commands, such as computations that you have to perform repeatedly from the command line. To open a new file chose File New M-File from the Menu bar and start typing your Matlab code. As always: Don t forget to save!! 14/06/2016 Stokes Modelling Workshop Introduction to Matlab 11 / 16

if...else...end Consider the following piece of code v = [4,6]; if v(1) > v(2), largest_value = v(1); else largest_value = v(2); end What does the code do if v = [4,4] instead? 14/06/2016 Stokes Modelling Workshop Introduction to Matlab 12 / 16

for...end Consider the code v = 1:2:9; for k = 1:length(v), s(k) = v(k)^2; end This gives us the vector of squares of 1, 3, 5, 7, 9 >> s s = 1 9 25 49 81 There is another way to create this vector >> s = v.^2 s = 1 9 25 49 81 14/06/2016 Stokes Modelling Workshop Introduction to Matlab 13 / 16

plot Plotting graphs is very important for anybody working in any applied science. Matlab is very good for this purpose. The function PLOT(X,Y,S) plots vector Y versus vector X, where S is a character string describing the way in which the data is shown. If X or Y is a matrix, then the vector is plotted versus the rows or columns of the matrix, whichever line up. If X is a scalar and Y is a vector, disconnected line objects are created and plotted as discrete points vertically at X. To find lot of information on how to plot your data type help plot or doc plot. 14/06/2016 Stokes Modelling Workshop Introduction to Matlab 14 / 16

plot Consider the following x = 0:4*pi/100:4*pi; y1 = sin(x); y2 = 2*sin(x); y3 = sin(2*x); figure(7),hold on plot(x,y1, k, LineWidth,2) plot(x,y2, r--, LineWidth,2) plot(x,y3, b:, LineWidth,2) xlabel( x ),ylabel( y_1, y_2, y_3 ) axis([0 4*pi -2.5 2.5]) box on hold off 14/06/2016 Stokes Modelling Workshop Introduction to Matlab 15 / 16

plot This code gives the following figure 14/06/2016 Stokes Modelling Workshop Introduction to Matlab 16 / 16