MATLAB INTRODUCTION. Risk analysis lab Ceffer Attila. PhD student BUTE Department Of Networked Systems and Services

Similar documents
Introduction to MATLAB

Chapter 1 Introduction to MATLAB

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY

What is Matlab? The command line Variables Operators Functions

Introduction to Matlab

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

Basic MATLAB Tutorial

Teaching Manual Math 2131

To start using Matlab, you only need be concerned with the command window for now.

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

MATLAB NOTES. Matlab designed for numerical computing. Strongly oriented towards use of arrays, one and two dimensional.

Some elements for Matlab programming

A Quick Tutorial on MATLAB. Zeeshan Ali

Introduction to PartSim and Matlab

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

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

Starting Matlab. MATLAB Laboratory 09/09/10 Lecture. Command Window. Drives/Directories. Go to.

Introduction to MatLab. Introduction to MatLab K. Craig 1

Introduction to MATLAB for Numerical Analysis and Mathematical Modeling. Selis Önel, PhD

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

INTRODUCTION TO MATLAB

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS

Introduction to Scientific Computing with Matlab

EE 216 Experiment 1. MATLAB Structure and Use

MatLab Just a beginning

A Brief Introduction to MATLAB Evans Library Research Support Workshops

Introduction to Engineering gii

A Tutorial on Matlab Ch. 3 Programming in Matlab

Functions of Two Variables

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

Due date for the report is 23 May 2007

Programming in MATLAB

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

Introduction to MATLAB for Engineers, Third Edition

Introduction to MATLAB

What is a Function? EF102 - Spring, A&S Lecture 4 Matlab Functions

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

Matlab Tutorial, CDS

Introduction to Programming

Introduction to MATLAB 7 for Engineers

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

Digital Image Analysis and Processing CPE

MATLAB. A Tutorial By. Masood Ejaz

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

Introduction to Matlab

Learning from Data Introduction to Matlab

PART 1 PROGRAMMING WITH MATHLAB

Introduction to MATLAB

SECTION 1: INTRODUCTION. ENGR 112 Introduction to Engineering Computing

Lab 1 - Worksheet Spring 2013

Numerical Methods Lecture 1

LabVIEW MathScript Quick Reference

Getting Started with MATLAB

Introduction to Programming

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

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

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

Lab 0a: Introduction to MATLAB

Lecturer: Keyvan Dehmamy

A = [1, 6; 78, 9] Note: everything is case-sensitive, so a and A are different. One enters the above matrix as

MATLAB: The greatest thing ever. Why is MATLAB so great? Nobody s perfect, not even MATLAB. Prof. Dionne Aleman. Excellent matrix/vector handling

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

1 Overview of the standard Matlab syntax

Introduction to Matlab. By: Hossein Hamooni Fall 2014

Programming in Mathematics. Mili I. Shah

MATLAB Operators, control flow and scripting. Edited by Péter Vass

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX

Getting started with MATLAB

MAT 343 Laboratory 2 Solving systems in MATLAB and simple programming

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

MATLAB Second Seminar

EGR 102 Introduction to Engineering Modeling. Lab 05A Managing Data

Consider this m file that creates a file that you can load data into called rain.txt

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

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

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

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

Quick MATLAB Syntax Guide

Page 1 of 7 E7 Spring 2009 Midterm I SID: UNIVERSITY OF CALIFORNIA, BERKELEY Department of Civil and Environmental Engineering. Practice Midterm 01

Chapter 7: Programming in MATLAB

MATLAB is a multi-paradigm numerical computing environment fourth-generation programming language. A proprietary programming language developed by

Introduction to Computer Programming with MATLAB Matlab Fundamentals. Selis Önel, PhD

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

Introduction and MATLAB Basics

A Guide to Using Some Basic MATLAB Functions

Introduction to MATLAB

STA 248 S: Some R Basics

A GUIDE FOR USING MATLAB IN COMPUTER SCIENCE AND COMPUTER ENGINEERING TABLE OF CONTENTS

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

Introduction to MATLAB Practical 1

Evolutionary Algorithms. Workgroup 1

Matlab Programming Introduction 1 2

Computational Finance

CS 2750 Machine Learning. Matlab Tutorial

LAB 1 General MATLAB Information 1

Math 2250 MATLAB TUTORIAL Fall 2005

CS129: Introduction to Matlab (Code)

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

Introduction to Matlab. CSE555 Introduction to Pattern Recognition Spring 2011 recitation

MATLAB Lecture 1. Introduction to MATLAB

Transcription:

MATLAB INTRODUCTION Risk analysis lab 2018 2018. szeptember 10., Budapest Ceffer Attila PhD student BUTE Department Of Networked Systems and Services ceffer@hit.bme.hu Előadó képe

MATLAB Introduction 2 Ceffer Attila BME HIT MATLAB introduction - Agenda Introduction, architecture Data types Basic arithmetic operations and functions Random number generation Plotting, visualization Programming fundamentals Work with external data files

Introduction Cleve Moler (University of New Mexico) started developing in the late '70s Recent versions: new release in every half year (R201x[a b]) Goal: to perform numerical calculations, mostly in engineering and research applications Besides being a tool, MATLAB is also a programming language and a software platform 3

Architecture Platform Built-in functions Toolboxes (e.g. Statistics and Machine Learning, Parallel Computing, Financial, Global Optimization, ) Both command line and GUI interfaces Data handling framework File I/O, database connection Advantages Easy to learn Rapid prototype developing No need to hassle with low level issues Fast computation, optimized to the latest hardwares (e.g. GPGPU support) 4

Window layout 5

Data representation Dynamic typing No need to declare types Type is assigned based on the right hand operand MATrix LABoratory Numerical data are represented as complex matrices Scalar values (1x1), vectors (1xN) Structs {'field1', value1, 'field2', value2, } Other types: e.g. strings, database connections 6

Basic operations (syntax) Defining variables Type MATLAB code Math Scalar (1x1 matrix) c = 5; Row vector (1xN matrix) v = [3 7 9]; Column vector (Nx1 matrix) w = [4; 6; 8]; Matrix (NxM) A = [1 2 3; 4 5 6; 7 8 9]; c 5 v 3 7 9 4 w 6 8 1 2 3 A 4 5 6 7 8 9 7

Indexing Basic operations (syntax) A = [1 2 3; 4 5 6; 7 8 9]; Starts from 1, not from 0 Select the whole row/column with operator : end keyword to index last row/column Select intervals: A(2:3,1) A A(1,1) 1 2 3 4 5 6 7 8 9 A(:,2) A(2,3) A(end,end) 8

Basic operations (syntax) Calling functions [d, e] = function_name(a, b, c); Output arguments Input arguments Arbitrary number of arguments User defined functions Some built-in functions min(x) Smallest elements in array ceil(x) Round toward pos. infinity max(x) Largest elements in array log(x) Natural logarithm abs(x) Absolute value sum(x) Sum of array elements sqrt(x) Square root mean(x) Average value of array exp(x) Exponential std(x) Standard deviation floor(x) Round toward neg. infinity eig(x) Eigenvalues and eigenvectors 9

Basic operations - initializers Initializing matrices (faster than the dynamic case) A = zeros(n, [m]); A = ones(n, [m]); A = eye(n, [m]); [N, M] = size(a); +, -, *, /, ^ operators No C stlye operators are provided like += or ++ A\B = A -1 B (solves Ax = b linear equation system) Logical expressions <, <=, ==, ~= (not!=), >=, >, ~, &, 10

Basic operations Comments a = 1; % one line comment Multi-line comments: between %{ and %} (separate line) Semicolon (;) at the end of the command If presented: perform the operation If not presented: perform the operation and display the result on the console 11

Random number generation Uniformly distributed pseudorandom numbers in the open interval (0,1) rand(n, [m]) Random numbers within a specific range [a, b] : Normally distributed numbers (standard normal) randn(n, [m]) Random numbers with specific mean (µ) and variance (σ): r a ( b a) r Other distributions random(name, param1, [param2], n, [m]) 'Binomial', n, p 'Exponential', mean 'Geomteric', p 'Poisson', lambda.. ab u r r n 12

Plotting New plot window: figure; plot(x, y, [x2, y2, ], [params]); x D, y R Only dots: plot(x, y, '*'); Multiple curves in one plot: hold on; plot(...); hold off; bar(x); hist(x); Adding features Grid: grid; Titles: title('abc'); xlabel('x'); ylabel('y'); legend('a', 'b', 'c'); Until opening a new window Exportable to static image files of various formats 13

Programming fundamentals Scripts Series of commands.m extension Executed by its filename (without extension) All variables will be global (workspace) Must be in the current folder Functions.m extension (must have the same name) Invoked by its name with providing the input variables All variables (including the input variables) will be local Must be in the current folder Best practice: in order to provide maximal maintainability and reusability put every functionality into separate functions and use a script as a main function 14

Programming fundamentals Function declaration function [r1, r2, r3] = myfunction(a, b, c) end (multiple and named return values no return statement needed, simply assign values to them) 15

Programming fundamentals Conditionals if expression1 elseif expression2 else end switch case expression1 case expression2 otherwise end 16

Programming fundamentals Loops Count-controlled loop v = 1:10; for i = v end Condition-controlled loop while expression end Terminate the loop: break; Continue with the next cycle: continue; 17

Debugging Live example Write running sum task in RiskLab Tasks 1 Error Breakpoints Stop on error 18

Work with data files Binary format for storing variables:.mat Global variables can be saved from / loaded to workspace From command line save('data.mat', 'a1', 'a2'); load 'data.mat'; Remove all variables: clear; (scripts should start with this to avoid interference ) Loading data from.csv or.xls format Manually in the variable editor (CTRL-C/V) Import wizard Programatically (repeatable) textscan(), textread(), xlsread(), xlswrite(), 19

Getting help Console On-line help command helpdesk Detailed toolbox documentation, function reference and forums on http://mathworks.com 20

Useful links MATLAB Help Function reference, tutorials, videos http://www.mathworks.com/help/matlab/ MATLAB Central Forums, file exchange http://www.mathworks.com/matlabcentral Getting started with MATLAB http://www.mathworks.com/help/matlab/getting-started-withmatlab.html 21

Questions? THANKS FOR YOUR ATTENTION! 22