Introduction to Matlab

Similar documents
ECE Lesson Plan - Class 1 Fall, 2001

Introduction to MATLAB

MATLAB = MATrix LABoratory. Interactive system. Basic data element is an array that does not require dimensioning.

Introduction to MATLAB

Desktop Command window

MATLAB Second Seminar

MatLab Just a beginning

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY

What We Will Learn Today

MATLAB. Devon Cormack and James Staley

ENGR 253 LAB #1 - MATLAB Introduction

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

An Introduction to MATLAB

Introduction to Matrix Operations in Matlab

Introduction to MATLAB

CM0340 Tutorial 2: More MATLAB

MATLAB The first steps. Edited by Péter Vass

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

CSCI 6906: Fundamentals of Computational Neuroimaging. Thomas P. Trappenberg Dalhousie University

Introduction to MATLAB

Matlab Tutorial: Basics

EGR 111 Introduction to MATLAB

Introduction to MATLAB LAB 1

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

Introduction to programming in MATLAB

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

Learning from Data Introduction to Matlab

Engineering Innovation Center MATLAB Basics

ECON 502 INTRODUCTION TO MATLAB Nov 9, 2007 TA: Murat Koyuncu

An Introduction to MATLAB See Chapter 1 of Gilat

Variable Definition and Statement Suppression You can create your own variables, and assign them values using = >> a = a = 3.

Introduction to Mathematical Programming

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

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

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

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

An Introductory Guide to MATLAB

Introduction to Scientific Computing with Matlab

2.0 MATLAB Fundamentals

How to program with Matlab (PART 1/3)

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

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

DSP First. Laboratory Exercise #1. Introduction to MATLAB

Ordinary Differential Equation Solver Language (ODESL) Reference Manual

Some elements for Matlab programming

Chapter 1 Introduction to MATLAB

What is Matlab? A software environment for interactive numerical computations

What is MATLAB and howtostart it up?

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

Introduction to MATLAB

Makefile Brief Reference

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

EE 301 Signals & Systems I MATLAB Tutorial with Questions

Matlab and Octave: Quick Introduction and Examples 1 Basics

Introduction to Matlab

University of Alberta

Introduction to Programming for Biology Research

INTRODUCTION TO MATLAB Part2 - Programming UNIVERSITY OF SHEFFIELD. July 2018

Introduction to Matlab. By: Hossein Hamooni Fall 2014

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

Introduction to Matlab

An Introduction to Matlab5

CITS2401 Computer Analysis & Visualisation

MATLAB Vocabulary. Gerald Recktenwald. Version 0.965, 25 February 2017

Introduction to MATLAB

MATLAB GUIDE UMD PHYS401 SPRING 2011

MATLAB TUTORIAL WORKSHEET

ENGR 105: Introduction to Scientific Computing. Dr. Graham. E. Wabiszewski

HERIOT-WATT UNIVERSITY DEPARTMENT OF COMPUTING AND ELECTRICAL ENGINEERING. B35SD2 Matlab tutorial 1 MATLAB BASICS

Introduction to Matlab

Getting To Know Matlab

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

Scientific Computing: Lecture 1

Eng Marine Production Management. Introduction to Matlab

Outline. User-based knn Algorithm Basics of Matlab Control Structures Scripts and Functions Help

Getting started with MATLAB

Introduction to MATLAB

function [s p] = sumprod (f, g)

MATLAB COURSE FALL 2004 SESSION 1 GETTING STARTED. Christian Daude 1

MATLAB GUIDE UMD PHYS375 FALL 2010

Computational Photonics, Summer Term 2014, Abbe School of Photonics, FSU Jena, Prof. Thomas Pertsch

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

Getting Started with MATLAB

Chapter 1: An Overview of MATLAB

Introduction to MATLAB

Matlab Primer. Lecture 02a Optical Sciences 330 Physical Optics II William J. Dallas January 12, 2005

Introduction to MatLab. Introduction to MatLab K. Craig 1

Introduction to Matlab. High-Level Computer Vision Summer Semester 2015

Introduction to MATLAB

Introduction to MATLAB

Introduction to MATLAB

Numerical Methods in Engineering Sciences

MATLAB/Octave Tutorial

Variables are used to store data (numbers, letters, etc) in MATLAB. There are a few rules that must be followed when creating variables in MATLAB:

Digital Image Analysis and Processing CPE

Introduction to Matlab

Math Scientific Computing - Matlab Intro and Exercises: Spring 2003

Unix Computer To open MATLAB on a Unix computer, click on K-Menu >> Caedm Local Apps >> MATLAB.

22-Functions Part 1 text: Chapter ECEGR 101 Engineering Problem Solving with Matlab Professor Henry Louie

Why use MATLAB? Mathematcal computations. Used a lot for problem solving. Statistical Analysis (e.g., mean, min) Visualisation (1D-3D)

Transcription:

Introduction to Matlab Weichung Wang 2003 NCTS-NSF Workshop on Differential Equations, Surface Theory, and Mathematical Visualization NCTS, Hsinchu, February 13, 2003 DE, ST, MV Workshop Matlab 1

Main Goals A brief Matlab introduction for beginners Warm-up for Prof. Karcher s courses DE, ST, MV Workshop Matlab 2

Start Matlab in Windows DE, ST, MV Workshop Matlab 4

Start Matlab in Unix shell In command line window, type > matlab > matlab -nojvm DE, ST, MV Workshop Matlab 5

What is Matlab? MATLAB == MATrix LABoratory Mathworks: http://www.mathworks.com Major software characteristics: matrix-based numeric computation high-level programming language graphics & visualization toolboxes provide application-specific functionality DE, ST, MV Workshop Matlab 6

What Is Matlab? (Cont.) Multi-platform support (PC / Macintosh / UNIX) Interfaces to other systems. Custom C, Fortran (MATLAB is callable) Extensive data I/O facility Matlab is case sensitive (mtxa ~= MTXA) DE, ST, MV Workshop Matlab 7

As a Calculator DE, ST, MV Workshop Matlab 8

Built-in Variables DE, ST, MV Workshop Matlab 9

Built-in Functions DE, ST, MV Workshop Matlab 10

Looking for Functions DE, ST, MV Workshop Matlab 11

On-line Help DE, ST, MV Workshop Matlab 12

Suppress Output With Semicolon DE, ST, MV Workshop Matlab 13

Multiple Statements Per Line DE, ST, MV Workshop Matlab 14

Vectors and Matrices DE, ST, MV Workshop Matlab 15

Matrix DE, ST, MV Workshop Matlab 16

Colon Notation DE, ST, MV Workshop Matlab 17

Colon Notation (Cont.) DE, ST, MV Workshop Matlab 18

Colon Notation (Cont.) DE, ST, MV Workshop Matlab 19

Complex Numbers DE, ST, MV Workshop Matlab 20

Complex Number (Cont.) DE, ST, MV Workshop Matlab 21

Complex Number (Cont.) DE, ST, MV Workshop Matlab 22

Manipulation of Matrices and Vectors DE, ST, MV Workshop Matlab 23

Vectorization DE, ST, MV Workshop Matlab 24

Vectorization (Cont.) DE, ST, MV Workshop Matlab 25

Array Operators DE, ST, MV Workshop Matlab 26

Array Operators (Cont.) DE, ST, MV Workshop Matlab 27

Array Operators (Cont.) DE, ST, MV Workshop Matlab 28

Plotting DE, ST, MV Workshop Matlab 29

Plotting (Cont.) DE, ST, MV Workshop Matlab 30

Case Study Examples by Prof. Hermann Karcher Set 1: FirstConventions.m (script) Change current directory to the directory containing the file FirstConventions.m DE, ST, MV Workshop Matlab 31

Script Give Orders by Command, Script, and Function Standard ASCII text files containing a sequence of normal MATLAB commands/statements. The command PlotSine causes the statements in the file named PlotSine.m to be parsed & executed in order. (Interpreter, not compiler.) % Comments start with "%" characte Variables in a script file are global. DE, ST, MV Workshop Matlab 32

Give Orders (cont.) Function Function files provide extensibility to MATLAB. Usually contains input and output. Variables in a function file are by default local. However, you can declare a variable to be global. DE, ST, MV Workshop Matlab 33

Flow Control Constructs Logic Control: if/ switch if I == J A(I,J) = 2; elseif abs(i-j) == 1 A(I,J) = -1; else A(I,J) = 0; end switch algorithm case 'ode23 str = '2nd/3rd order'; case {'ode15s', 'ode23s'} str = 'stiff system'; otherwise str = 'other algorithm'; end DE, ST, MV Workshop Matlab 34

Flow Control Constructs (cont.) Iterative Loops: for / while N = 10; for I = 1:N for J = 1:N A(I,J) = 1/(I+J-1); end end I = 1; N = 10; while I <= N end J = 1; while J <= N A(I,J) = 1/(I+J- 1); J = J+1; end I = I+1; DE, ST, MV Workshop Matlab 35

Structure of a Function M-file Keyword: function Function Name (same as file name.m) Output Argument(s) Input Argument(s) Online Help MATLAB Code function y = mean(x) % MEAN MEAN Average or or mean mean value. % For For vectors, MEAN(x) returns the the mean mean value. % For For matrices, MEAN(x) is is a row row vector % containing the the mean mean value of of each each column. [m,n] = size(x); if ifm == == 1 m = n; n; end end y = sum(x)/m;»output_value = mean(input_value) Command Line Syntax

Workspaces or Stacks in MATLAB MATLAB (or Base) Workspace: For command line and script file variables. Function Workspaces: Each function has its own workspace for local variables. Communicate to Function Workspace via inputs & outputs. (Promotes structured coding & prevents name conflicts.) Global Workspace: Global variables can be shared by multiple workspaces. (Must be initialized in all relevant workspaces.)

Inter-workspace Communication MATLAB Workspace Function inputs and outputs Function Workspace Initialize global variables in all relevant workspaces:»global variable_name Initialize global variables in the source workspace before referring to them from other workspaces. Global variables Global Workspace

Case Studies Examples by Prof. Hermann Karcher Set 2: ConCsqrt.m and Csqrt.m (both functions) DE, ST, MV Workshop Matlab 39

Some Suggestions Write comments % s=1 if scalar product(w,last) >=0 else s=-1 s=2*(real(w.*conj(last))>=0)-1; DE, ST, MV Workshop Matlab 40

Some Suggestions (Cont.) Give meaningful variable names and avoid single character variable names a=b*c; f=m*a; force = mass * acceleration; for ii=1:3 moment = ii^2; end; DE, ST, MV Workshop Matlab 41

Some Suggestions (Cont.) Indent codes Use Emacs (http://www.gnu.org/software/emacs/emacs.html) Learn by doing! DE, ST, MV Workshop Matlab 42

If You Were Sleeping It s OK. Just remember two commands: >> lookfor keyword >> help command DE, ST, MV Workshop Matlab 43

Happy coding! :-)

Reference Matlab Slides by Gerald Recktenwald http://www.prenhall.com/recktenwald. DE, ST, MV Workshop Matlab 45