StatLab Workshop Yale University Maximiliano Appendino, Economics October 18 th, 2013.

Slides:



Advertisements
Similar presentations
Introduction to Matlab
Advertisements

Introduction to Matlab
Tutorial on Matlab and OpenCV Rui Ma TA of CMPT 414 May 14, 2013 Office hours: Fridays 11:00-12:00, CSIL TA Office 1 (ASB 9838)
Introduction to Programming using Matlab Session 2 P DuffourJan 2008.
Lab # 03- SS Basic Graphic Commands. Lab Objectives: To understand M-files principle. To plot multiple plots on a single graph. To use different parameters.
MATLAB – A Computational Methods By Rohit Khokher Department of Computer Science, Sharda University, Greater Noida, India MATLAB – A Computational Methods.
Introduction to MATLAB The language of Technical Computing.
Introduction to Matlab
Matlab Programming Huajun Wang Department of Earth Sciences, Zhejiang University Jan 25,2012.
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 10.
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
Getting started with Matlab Numerical Methods Appendix B help/techdoc/learn_matlab/learn_matlab.html.
Introduction to Matlab Οικονομίδης Δημήτρης
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
What is MATLAB ? MATrix LABratory –Originally, it was a front-end to FORTRAN matrix routines developed in the U. of New Mexico and Stanford –Today.
Martin Ellison University of Warwick and CEPR Bank of England, December 2005 Introduction to MATLAB.
Nonparametric Econometrics1 Intro to Matlab for Data Analysis and Statistical Modeling.
Introduction to Matlab 1. Outline: What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators Plotting Flow Control Using of M-File Writing.
Introduction to MATLAB
Data, graphics, and programming in R 28.1, 30.1, Daily:10:00-12:45 & 13:45-16:30 EXCEPT WED 4 th 9:00-11:45 & 12:45-15:30 Teacher: Anna Kuparinen.
Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
INTRODUCTION TO MATLAB LAB# 01
Matlab Basics Tutorial. Vectors Let's start off by creating something simple, like a vector. Enter each element of the vector (separated by a space) between.
What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation tools. Others include Maple Mathematica MathCad.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
CMPS 1371 Introduction to Computing for Engineers MatLab.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
Basics of MATLAB By DR. Wafaa Shabana
Matlab 14.html Cost: $100 Available in labs on Windows and Unix machines.
ME6104: CAD. Module 4. ME6104: CAD. Module 4. Systems Realization Laboratory Module 4 Matlab ME 6104 – Fundamentals of Computer-Aided Design.
Introduction to Matlab. Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
Introduction to Matlab. What is Matlab? A software environment for interactive numerical computations Examples:  Matrix computations and linear algebra.
INTRODUCTION TO MATLAB MATLAB is a software package for computation in engineering, science, and applied mathemat-ics. It offers a powerful programming.
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
Introduction to Matlab
Matlab Introduction  Getting Around Matlab  Matrix Operations  Drawing Graphs  Calculating Statistics  (How to read data)
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
Introduction to Matlab Patrice Koehl Department of Biological Sciences National University of Singapore
Matlab for Engineers Matlab Environment Chapter 2.
CSE 455 : Computer Vision MATLAB 101 Getting Started with MATLAB.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Tutorial 2 : Matlab - Getting Started.
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Introduction to Matlab Engr. Mian Shahzad Iqbal LAB NO.2
An Introduction to Programming in Matlab Emily Blumenthal
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
Release Numbers MATLAB is updated regularly
Introduction to Matlab
Introduction to Mat lab
Lecture: MATLAB Chapter 1 Introduction
Statistical Computing in MATLAB
MATLAB DENC 2533 ECADD LAB 9.
Introduction to Matlab
Matlab Workshop 9/22/2018.
StatLab Matlab Workshop
Matlab review Matlab is a numerical analysis system
MATH 493 Introduction to MATLAB
Use of Mathematics using Technology (Maltlab)
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
Communication and Coding Theory Lab(CS491)
Demo of Basic Matlab Features
Matlab Basics Tutorial
Presentation transcript:

StatLab Workshop Yale University Maximiliano Appendino, Economics October 18 th, 2013

What is Matlab? Matlab is a matrix-based tool for numerical computations Powerful Easy to use Programming language Interactive environment Lots of available toolboxes

Getting Help Useful links: Mathworks' Getting Started Matlab Center Kermit Sigmon’s Matlab Primer Many others Google your question Matlab’s help Online Statlab Consultants: Max Perez Leon, Zhentao Shi

Acquiring Matlab ITS Software Library & Resources: Free for students: Matlab R2013a Available in Statlab locations The Center for Science and Social Science Information 219 Prospect St, Basement Kline Biology Tower Rosenkranz Hall 115 Prospect St, Room 01

Launching Matlab Double-click the “MATLAB R2013a” icon on the desktop Or click the start bottom, type MATLAB and enter Usual Interface: Command Window Workplace.MAT files Command history Current Folder

Interface Can be used as a calculator “help” gives you a list of all topics “help topic” informs you about the particular topic Example: >> help >> help stats >> help normcdf

Entering Matrices Entered manually: >> A = [ ; ; ] Generate it by built-in functions Loaded from a file.MAT or Menu  File  Import Data…

Matrix Operation + addition - subtraction * multiplication ^ power ‘ transpose Element-by-element : preceded the operators by. Subscripts: >> B = A(2,3)

Matrix Operation Matrix Multiplication >> [1 2; 3 4]*[1 2; 3 4] [7 10; 15 22] Element-by-element Multiplication >> [1 2; 3 4].*[1 2; 3 4] [1 4;9 16]

The Colon Operator : One of Matlab’s most important operators: Portions of a matrix: >> C = A(:,3) >> D = A(1,:) >> E = A(1:2,1:3) Create matrices using increments: >> F = [1:0.1:1.5]’ >> G = [1:0.1:1.5; 1:0.5:3.5]

Matrix Generation Functions Zeros: >> zeros(3,3) Ones: >> ones(3,3) Identity: >> eye(3) More on matrices and linear algebra: >> help elmat >> help matfun

Random Matrices Pseudo-Random numbers: Change the seed: >> rng('shuffle') >> rng(15) U[0,1] random variable: >> RU = rand(3,4) Normal random variable: >> RN = randn(4,3)

Matrix manipulation Concatenation: >> A2 = [A A.^2; A./2 A] Deleting rows and columns: >> A2(:,7:8) = [] Adding rows and columns: >> A2 = [1:2:11;A2] Knowing the size: >> sizeA2 = size(A2)

Suppressing Output If you simply type a statement and press Enter Matlab automatically displays the results on the Command Window If you end the line with a semicolon ; Matlab performs the computation but does not display any result >> H = rand(2,2) >> H = rand(2,2); >> H

Functions Matlab provides a large number of standard elementary mathematical functions: >> abs(-10) >> sqrt(9) >> x = [0:0.1:2*pi]; >> y = sin(y); Look for the ones you need: Google >> help

Graphics Matlab generate 2-dimensional plots easily: >> plot(x,y) >> y2 = y ; >> y3 = y ; >> plot(x,y,x,y2,x,y3) With a friendly interface to edit them

Graphics Also 3-dimensional ones: First we need to generate a grid: >> [X,Y] = meshgrid([-2:.2:2]); Second we can calculate the function to graph: >> Z = X.*exp(-X.^2-Y.^2); Finally the graph: >> surf(X,Y,Z)

Programming M-files contain Matlab code.m is their extension Matlab editor Can be used as any command or function as long as they are in the “Current Folder” Two types: Scripts Functions

Scripts A list of code grouped together It does not accept argument or return output Use them to register your work Example: File  New  Script disp(‘Hello’) File  Save  test.m >> test

Functions Functions are M-files that can accept input arguments and return output arguments. The M-file and the function should have the same name Example: function ar = area(radius) ar = pi*radius.^2; File  Save  area.m >> area(2)

Flow Control Matlab has the standard flow controls If statements For loops While loops

If statement a = 10; b = 11; if a > b disp('greater‘) elseif a < b disp('less‘) else disp('equal‘) end >> [a==b]

For loops betavec = zeros(100,1); beta = 0.925; a = [1:100]; for i = 1:100 betavec(i)=beta^a(i); end plot(betavec) But you should avoid for loops if possible: >> newbetavec=beta.^a

While loops The previous example would be: betavec = zeros(100,1); beta = 0.925; a = [1:100]; i = 1; while i < 101 betavec(i)=beta^a(i); i = i + 1; end plot(betavec)

Solving problems Check if somebody else has already solved it Matlab itself Anybody using Matlab Solve it by yourself Use Matlab’s matrix processing capacity as much as you can Be organized with your code

Thank you! Questions, Comments, Problems to solve?