MATLAB Session for CS4514

Similar documents
4452 Mathematical Modeling Lecture 4: Lagrange Multipliers

Introduction To Files In Pascal

Unit 5 Vocabulary. A function is a special relationship where each input has a single output.

COMPUTER SCIENCE 123. Foundations of Computer Science. 6. Tuples

Lecture 10 Evolutionary Computation: Evolution strategies and genetic programming

Agilent Mass Hunter Software

Fig.25: the Role of LEX

Lab 1 - Counter. Create a project. Add files to the project. Compile design files. Run simulation. Debug results

Reducing a DFA to a Minimal DFA

Spring 2018 Midterm Exam 1 March 1, You may not use any books, notes, or electronic devices during this exam.

Fall 2018 Midterm 1 October 11, ˆ You may not ask questions about the exam except for language clarifications.

- 2 U NIX FILES 1. Explin different file types vilble in UNIX or P OSIX s ystem. ( 08 mrks) ( My-08/Dec-08/My-10/My- 12) 2. Wht is n API? How is it di

PYTHON PROGRAMMING. The History of Python. Features of Python. This Course

Functor (1A) Young Won Lim 10/5/17

File Manager Quick Reference Guide. June Prepared for the Mayo Clinic Enterprise Kahua Deployment

EasyMP Multi PC Projection Operation Guide

Epson iprojection Operation Guide (Windows/Mac)

Dr. D.M. Akbar Hussain

Fall 2017 Midterm Exam 1 October 19, You may not use any books, notes, or electronic devices during this exam.

EasyMP Network Projection Operation Guide

pdfapilot Server 2 Manual

McAfee Network Security Platform

Functor (1A) Young Won Lim 8/2/17

Geometric transformations

Midterm 2 Sample solution

NOTES. Figure 1 illustrates typical hardware component connections required when using the JCM ICB Asset Ticket Generator software application.

vcloud Director Service Provider Admin Portal Guide vcloud Director 9.1

In the last lecture, we discussed how valid tokens may be specified by regular expressions.

Introduction to Julia for Bioinformatics

Unit #9 : Definite Integral Properties, Fundamental Theorem of Calculus

OUTPUT DELIVERY SYSTEM

Dynamic Programming. Andreas Klappenecker. [partially based on slides by Prof. Welch] Monday, September 24, 2012

Lecture Overview. Knowledge-based systems in Bioinformatics, 1MB602. Procedural abstraction. The sum procedure. Integration as a procedure

Agenda & Reading. Class Exercise. COMPSCI 105 SS 2012 Principles of Computer Science. Arrays

MA1008. Calculus and Linear Algebra for Engineers. Course Notes for Section B. Stephen Wills. Department of Mathematics. University College Cork

Stack. A list whose end points are pointed by top and bottom

George Boole. IT 3123 Hardware and Software Concepts. Switching Algebra. Boolean Functions. Boolean Functions. Truth Tables

Simrad ES80. Software Release Note Introduction

10/9/2012. Operator is an operation performed over data at runtime. Arithmetic, Logical, Comparison, Assignment, Etc. Operators have precedence

CS 241. Fall 2017 Midterm Review Solutions. October 24, Bits and Bytes 1. 3 MIPS Assembler 6. 4 Regular Languages 7.

Matrices and Systems of Equations

VMware Horizon JMP Server Installation and Setup Guide. Modified on 06 SEP 2018 VMware Horizon 7 7.6

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών

From Dependencies to Evaluation Strategies

Systems I. Logic Design I. Topics Digital logic Logic gates Simple combinational logic circuits

Math 142, Exam 1 Information.

CS201 Discussion 10 DRAWTREE + TRIES

Assignment 4. Due 09/18/17

What do all those bits mean now? Number Systems and Arithmetic. Introduction to Binary Numbers. Questions About Numbers

Digital Design. Chapter 1: Introduction. Digital Design. Copyright 2006 Frank Vahid

Stained Glass Design. Teaching Goals:

L2-Python-Data-Structures

Tool Vendor Perspectives SysML Thus Far

Section 3.1: Sequences and Series

a < a+ x < a+2 x < < a+n x = b, n A i n f(x i ) x. i=1 i=1

1 Drawing 3D Objects in Adobe Illustrator

McAfee Network Security Platform

View, evaluate, and publish assignments using the Assignment dropbox.

Reference types and their characteristics Class Definition Constructors and Object Creation Special objects: Strings and Arrays

E201 USB Encoder Interface

Quiz2 45mins. Personal Number: Problem 1. (20pts) Here is an Table of Perl Regular Ex

COMMON HALF YEARLY EXAMINATION DECEMBER 2018

Easy Interactive Tools Ver.3.0 Operation Guide

CPSC 213. Polymorphism. Introduction to Computer Systems. Readings for Next Two Lectures. Back to Procedure Calls

Data sharing in OpenMP

2 Computing all Intersections of a Set of Segments Line Segment Intersection

TO REGULAR EXPRESSIONS

Scanner Termination. Multi Character Lookahead. to its physical end. Most parsers require an end of file token. Lex and Jlex automatically create an

CS 340, Fall 2014 Dec 11 th /13 th Final Exam Note: in all questions, the special symbol ɛ (epsilon) is used to indicate the empty string.

CSc 453. Compilers and Systems Software. 4 : Lexical Analysis II. Department of Computer Science University of Arizona

9 4. CISC - Curriculum & Instruction Steering Committee. California County Superintendents Educational Services Association

Implementing Automata. CSc 453. Compilers and Systems Software. 4 : Lexical Analysis II. Department of Computer Science University of Arizona

Representation of Numbers. Number Representation. Representation of Numbers. 32-bit Unsigned Integers 3/24/2014. Fixed point Integer Representation

CS321 Languages and Compiler Design I. Winter 2012 Lecture 5

Integration. September 28, 2017

Section 10.4 Hyperbolas

Scanning Theory and Practice

CMSC 331 First Midterm Exam

Summer Review Packet For Algebra 2 CP/Honors

Engineer To Engineer Note

What do all those bits mean now? Number Systems and Arithmetic. Introduction to Binary Numbers. Questions About Numbers

9.1 apply the distance and midpoint formulas

Outline. Tiling, formally. Expression tile as rule. Statement tiles as rules. Function calls. CS 412 Introduction to Compilers

CMPSC 470: Compiler Construction

Questions About Numbers. Number Systems and Arithmetic. Introduction to Binary Numbers. Negative Numbers?

such that the S i cover S, or equivalently S

UNIT 11. Query Optimization

5 Regular 4-Sided Composition

L. Yaroslavsky. Fundamentals of Digital Image Processing. Course

Small Business Networking

Lecture T4: Pattern Matching

License Manager Installation and Setup

Small Business Networking

Definition of Regular Expression

LCI/USB LonWorks Commissioning Interface

vcloud Director Tenant Portal Guide vcloud Director 9.1

CSE 401 Midterm Exam 11/5/10 Sample Solution

McAfee Network Security Platform

Small Business Networking

Agilent G2724AA Spectrum Mill Extractor for Applied Biosystems/MDS Sciex QSTAR Data Files Quick Start Guide

Transcription:

MATLAB Session for CS4514 Adrin Her her @wpi.edu Computing & Communictions Center - November 28, 2006- Prt of the notes re from Mtlb documenttion 1 MATLAB Session for CS4514 1. Mtlb Bsics Strting Mtlb Mtlb Help Mtlb Vribles Numbers Opertors Functions Mtrices Writing script Plotting Dt Importing Dt 2. Processing experimentl dt slides 32-end Importing Dt in Mtlb codes: code1.m Processing Dt code2.m Plotting Dt A. Files: typeperf1.csv, typeperf2.csv, etc B. Files: logfile1.dt, logfile2.dt, etc 2

Wht is Mtlb? MATLAB is high-performnce lnguge for technicl computing. It integrtes computtion, visuliztion, nd progrmming in n esy-touse environment where problems nd solutions re expressed in fmilir mthemticl nottion. MATLAB stnds for mtrix lbortory. MATLAB is n interctive system whose bsic dt element is n mtrix (rry) tht does not require dimensioning. This llows you to solve mny technicl computing problems, especilly those with mtrix nd vector formultions, in frction of the time it would tke to write progrm in sclr non-interctive lnguge such s C or Fortrn. 3 Strting Mtlb Windows: Strt menu Mtlb Mtlb Unix: Terminl window type mtlb Menu Current Directory Workspce Window Commnd Window History Window 4

Mtlb Help 1. Using HELP menu MATLAB Help HELP Using Help Browser 2. >> helpdesk Opens the Help browser. 3. >> help commndnme/toolboxnme/functionnme Ex: >> help sin 4. >> doc commndnme/toolboxnme/functionnme displys the detiled info in the Help browser. Ex: >> doc sin Other commnds: 5. >> lookfor = helpdesk -> serch 5 I. Mtlb Progrmming Mtlb Vribles Opertors Functions.. 6

Mtlb Vribles A MATLAB vrible is essentilly tg tht you ssign to vlue in memory. MATLAB does not require ny type declrtions or dimension sttements. When MATLAB encounters new vrible nme, it utomticlly cretes the vrible nd lloctes the pproprite mount of storge. If the vrible lredy exists, MATLAB chnges its contents. Vrible nmes consist of letter, followed by ny number of letters, digits, or underscores. MATLAB uses only the first 31 chrcters of vrible nme. MATLAB is cse sensitive; it distinguishes between uppercse nd lowercse letters. MATLAB stores vribles in prt of memory clled workspce. To view wht is stored in vrible type its nme. Types of Vribles: MATLAB provides three bsic types of vribles: Locl Vribles Globl Vribles Persistent Vribles 7 Mtlb Vribles Rules for vrible nmes: Mke Sure Vrible Nmes Are Vlid Don't Use Function Nmes for Vribles Check for Reserved Keywords Avoid Using i nd j for Vribles How to remove vrible from workspce: Syntx: vrilenme=vlue; Exmple: >> =5; >> b=7; >> c=+b >> method= liner >> cler vriblenme >> cler - removes ll vribles from the workspce (!!!!) ns = defult vrible, when the result is not ssign to vrible Exercise: 1. Define 1=8 nd b2=8, c1=1+b2 2. Other commnds: vrible= input( prompt ) (>>help input) >> 3=input( 3= ) 8

Opertors Expressions use fmilir rithmetic opertors nd precedence rules. 9 Mtlb Functions 1. Stndrd elementry mthemticl functions >> help elfun Trigonometric (sin, cos) Exponentil (exp, log) Complex (bs, ngle) Rounding nd reminder (round) 2. Elementry mtrices nd mtrix mnipultion. >> help elmt 3. Specilized mth functions. >> help specfun 10

Sttistics men, std, min, mx Given: vector x Syntx: M = men(x) S = std(x) min_x = min(x) mx_x=mx(x) - verge or men vlue - returns the stndrd devition - the smllest element in x - returns the lrgest element in x Exmple: open the file mysttistics.m mysttistics.m mysttistics1.m Advnced: Sttistics for multidimensionl dt sets Sttistics toolbox 11 Mtrices Opertors Functions.. 12

Mtrix & bsic mtrix functions Define mtrix: 1. Type the mtrix 2. Use Specilized Mtrix Functions Mtrix Mnipultion Mtrix Functions 13 Mtrix: Define mtrix 1. Type the mtrix Seprte the elements of row with blnks or comms. Use semicolon, ;, to indicte the end of ech row. Surround the entire list of elements with squre brckets, [ ]. 3 S = 10 0 10 0 30 0 30 27 1. >> S=[3-10 0; -10 0 30; 0 30-27] Bsic mtrix informtion: size (size of mtrix) >> [m,n] = size(x) 14

Mtrix: Accessing Mtrix Elements individul element >> A(2,2) ns = 20 1 A = 11 2 20 3 30 column >> A(:,2) row >> A(2,:) group of elements >> A(2,1:3) ns = : (colon) ll elements 2 20 ns = 11 20 30 ns = 11 20 30 first element : step: lst element 15 Mtrix: Opertions A+B A-B A*B A/B A\B A^B A' A.*B A./B A.\B A.^B A.' 16

Mtrix: Opertions 1 2 3 10 20 30 A = 2 3 1, 11 21 31 B =, 2 2 2 1 2 3 >> A=[1 2 3; 2 3 1; 2 2 2]; >> B= [10 20 30; 11 21 31; 1 2 3]; >> A*B ns = 35 68 101 54 105 156 44 86 128 A = 11 21 31 A * B = 11 21 31 12 22 32 b b b 11 21 31 13 23 33, 12 22 32 b b b b B = b b 12 22 32 13 23 33 11 21 31 b b b 13 23 33 b b b 12 22 32 b b b 13 23 33, >> A.*B ns = 10 40 90 22 63 31 2 4 6 17 IV. Mtlb Progrmming How to write progrm (M-files) Script Function How to plot dt 18

M-files Files tht contin code in the MATLAB lnguge re clled M-files. You crete M-files using text editor. Use M-file s ny other MATLAB function or commnd. A M-file is plin text file. Two kinds of M-files: Scripts do not ccept input rguments or return output rguments operte on dt in the workspce. Functions cn ccept input rguments nd return output rguments internl vribles re locl to the function. >> edit filenme >> edit exswitch 19 Mtlb - Plotting plot Sintx: plot(y); plot(x,y); plot(x,y,s) The plot function hs different forms, depending on the input rguments. If y is vector, plot(y) produces piecewise liner grph of the elements of y versus the index of the elements of y. If you specify two vectors s rguments, plot(x,y) produces grph of y versus x. 20

Mtlb - Plotting plot(x,y, s); s llows to plot : colors, symbols, different lines b blue. point - solid g green o circle : dotted r red x x-mrk -. dshdot c cyn + plus -- dshed m mgent * str (none) no line y yellow s squre k blck d dimond. plot (x,y,'c+:') plots cyn dotted line with plus t ech dt point; 21 Mtlb - Plotting cler t=0:0.01:10; % time seconds signlsin=sin(2*pi*t); % signl1 - frequency =1 Hz signlcos=0.5*cos(2*pi*t); % signl2 - frequency =1 Hz figure plot(t,signlsin); hold on plot(t,signlcos, '-*r'); plot2signls.m xlbel('time'); ylbel('signl'); legend('sin', 'Cos'); title('two Signls','FontSize',12) Other commnds: xlbel figure ylbel legend, title 22

Mtlb - Plotting 1 0.8 0.6 Two Signls Sin Cos 0.4 0.2 signl 0-0.2-0.4-0.6-0.8-1 0 1 2 3 4 5 6 7 8 9 10 time 23 Visuliztion - Interctive editing (optionl) show plot tools 24

Visuliztion (optionl) plot, plotyy, stem, subplot plot(y) plot(x1,y1,...) plot(x1,y1,linespec,propertynme',propertyvlue,...) plotyy (X1,Y1,X2,Y2) plots Y1 versus X1 with y-xis lbeling on the left nd plots Y2 versus X2 with y-xis lbeling on the right. stem (X,Y) plots the dt sequence Y t the vlues specified in X. suplot (m,n,p), breks the Figure window into n m-by-n mtrix of smll xes, selects the p-th xes for for the current plot 25 Visuliztion %%%%% plot commnds %%%%%%%%%%%%%%% t=1:1:20; x=sin(t/5); y=0.01*x.*exp(-t); see: testplot.m figure subplot(2,2,1) plot(t,x,'--rs','linewidth',2, MrkerEdgeColor','k',... 'MrkerFceColor','g','MrkerSize',6); title('plot 1'); subplot(2,2,2) stem(t,x,'--rs','linewidth',2); title('plot 2') subplot(2,2,3); br(t,x); title('plot 3') subplot(2,2,4) plotyy(t,x, t,y); title('plotyy') 26

Visuliztion (optionl) Line Plots Br Plots 3D Surfce Vector Fields 27 Publishing script to HTML 28

Importing nd Exporting Dt using the Import Wizrd sve, lod dlmred, dlmwrite xlsred, xlswrite fopen,, fscnf, fprintf importdt 29 Importing Dt 1. Using the Import Wizrd with Text Dt File Import Dt or >> uiimport 2 Supported File Formts Wizrd: missing dt: NN (Not--Number.) 30

Importing nd Exporting Dt 2 Supported File Formts 31 Processing Experimentl Dt for the Project 1. Dt Preprtion 2. Import Dt in Mtlb 3. Process Dt 4. Plot Dt A. Files: typeperf1.csv, typeperf2.csv, etc B. Files: logfile1.dt, logfile2.dt, etc code1.m code2.m 32

1. Dt Preprtion 1. Open s Text (typeperf.csv) 2. Editor window: Edit Find nd Replce Remove double quottion mrks 3. File Sve s (typeperfm.csv) 33 2. Import Dt in Mtlb A = importdt( typeperfm.csv ); % lod dt into structure Structure A with two fields: A.dt (numeric dt) A.textdt (text dt) 34

2. Import Dt in Mtlb A = importdt( typeperfm.csv ); Col 1 Col 2 Col 3 Col 4 A.textdt (text dt) 35 3. Process Dt min sec msec timedte=a.textdt(2:end,1); % time dt timeutc=dtenum(timedte); % trnsform time to UTC relutctime=timeutc-timeutc(1); % define reltive time T=dtestr(relUTCTime, 'MMSSFFF'); % time in minutes, seconds, mseconds 36

4. Plot Dt 40 30 Figure1 typeperf1m.csv typeperf2m.csv col 3 20 10 0 20 40 60 80 100 120 140 160 180 Time 1.1 x 107 Figure2 1.1 col 4 1.1 1.1 1.1 0 20 40 60 80 100 120 140 160 180 Time Figure3 80 60 col 8 40 20 0 0 20 40 60 80 100 120 140 160 180 Time 37 1. Dt Preprtion 1. Open s Text (logfile.dt) 2. Editor window: Edit Find nd Replce Remove [00-01-36-0D-CE-5D] 3. File Sve s (logfilem.dt) 38

2. Import Dt in Mtlb Row no dtexp=dlmred('logfilem.dt', '', 1, 0); Col no 3. Process Dt timeutc=dtexp(:,1); reltime=timeutc-timeutc(1); 39 3. Plot Dt & Extrct Info 40

Processing Experimentl Dt for the Project 1. Dt Preprtion 2. Import Dt in Mtlb 3. Process Dt 4. Plot Dt A. Files: typeperf1.csv, typeperf2.csv, etc B. Files: logfile1.dt, logfile2.dt, etc code1.m code2.m 41