An Anthropologist on Matlab. Data Analysis Functions (1) corrcoef(x) cov(x) cplxpair(x) cross(x,y) cumprod(x) cumsum(x) del2(A) diff(x) dot(x,y) gradient(Z,

Slides:



Advertisements
Similar presentations
259 Lecture 17 Working with Data in MATLAB. Overview  In this lecture, we’ll look at some commands that are useful for working with data!  fzero  sum,
Advertisements

COMP 116: Introduction to Scientific Programming Lecture 37: Final Review.
Lecture 4.
CSE 123 Symbolic Processing. Declaring Symbolic Variables and Constants To enable symbolic processing, the variables and constants involved must first.
Introduction to Matlab By: Dr. Maher O. EL-Ghossain.
Flash Gordon and the Mud Men of Matlab. Quick Exercise (!) Consider Polynomial Addition again : how would you write a program that takes in two polynomials.
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
Lecture 7 Sept 17 Goals: Complete Chapter 4 Chapters 5 and 6.
Matlab Basics IEF 217a: Lecture 2 Fall 2002 Sigmon and Davis, chapters 1-7.
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.
Builtin and user defined functions
January 24, 2005 Lecture 3 - By P. Lin 1 CPET 190 Lecture 3 Problem Solving with MATLAB
Chapter 4 MATLAB Programming Combining Loops and Logic Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter 5. Loops are common in most programming languages Plus side: Are very fast (in other languages) & easy to understand Negative side: Require a.
Martin Ellison University of Warwick and CEPR Bank of England, December 2005 Introduction to MATLAB.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
1 M ATLAB Short Course. History of Calculator 2 3 Introduction to Matlab Matlab is short for Matrix Laboratory Matlab is also a programming language.
Predefined MATLAB Functions ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
MATLAB Tutorials Session I Introduction to MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU.
259 Lecture 18 The Symbolic Toolbox. 2  MATLAB has a set of built-in commands that allow us to work with functions in a fashion similar to Mathematica.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
MEGN 536 – Computational Biomechanics MATLAB: Getting Started Prof. Anthony J. Petrella Computational Biomechanics Group.
MATLAB An Introduction to MATLAB (Matrix Laboratory) 1.
INTRODUCTION TO MATLAB LAB# 01
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
Introduction to Matlab Module #2 Page 1 Introduction to Matlab Module #2 – Arrays Topics 1.Numeric arrays (creation, addressing, sizes) 2.Element-by-Element.
L – Modelling and Simulating Social Systems with MATLAB Lesson 2 – Statistics and plotting Anders Johansson and Wenjian Yu © ETH.
Basic Vocabulary Math is a language, learn the words!
Matlab Basics FIN250f: Lecture 3 Spring 2010 Grifths Web Notes.
Octave. Getting Started Arithmetic is as usual: – What would (a-V)(V-1)V be for a=0.1 and V=-56? – Multiplication is *, division is /
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
Introduction to Matlab By E. Noura Semary. Contents MATLAB Environment  Command window, Workspace, Path window, Editor window,and Figure window) Basic.
Lec-10 Manipulations of Matlab Matrices. Built-in functions The chapter will be covered quickly There are quite a few built-in functions in MATLAB – If.
>> x = [ ]; y = 2*x y = Arrays x and y are one dimensional arrays called vectors. In MATLAB all variables are arrays. They allow functions.
Digital Image Processing Lecture 6: Introduction to M- function Programming.
Introduction to Matlab
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 10.
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
1 An Introduction to R © 2009 Dan Nettleton. 2 Preliminaries Throughout these slides, red text indicates text that is typed at the R prompt or text that.
Lecture 24: Rough and Ready Analysis. MATLAB uses function names consistent with most major programming languages For example sqrt sin cos log.
EEE 242 Computer Tools for Electrical Engineering Lecture IV Mustafa KARABULUT.
An Introduction to Programming in Matlab Emily Blumenthal
전자장 1 실험 - Matlab 사용법 - Photonic Systems Laboratory School of EE, Seoul National University Photonic Systems Lab School of EECS, S.N.U.
L – Modeling and Simulating Social Systems with MATLAB Lecture 2 – Statistics and plotting © ETH Zürich | Giovanni Luca Ciampaglia,
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Matlab & Image processing toolbox Heejune Ahn SeoulTech Last updated Jan.
1-2 What is the Matlab environment? How can you create vectors ? What does the colon : operator do? How does the use of the built-in linspace function.
Some “What’s the output” questions to get the day started… >>A = [1 2 3; 3 5 6] This statement stores the matrix: 1. A= 2. A= 3. A= 4. A= Ask Garvin’s.
Introduction to Programming
Part(2) MATLAB.
Definition of the Programming Language CPRL
Working with Data in MATLAB
Built-in MATLAB Functions Chapter 3
Lecture: MATLAB Chapter 1 Introduction
C++ Basic Syntax – Homework Exercises
Computer Simulation Lab
Other Kinds of Arrays Chapter 11
MATLAB DENC 2533 ECADD LAB 9.
MATLAB: Structures and File I/O
Matlab review Matlab is a numerical analysis system
T. Jumana Abu Shmais – AOU - Riyadh
Introduction to Matlab
Vectors, matrices, and arithmetic
Introduction to MATLAB
Announcements P3 due today
Data analysis with R and the tidyverse
Computer Simulation Lab
Presentation transcript:

An Anthropologist on Matlab

Data Analysis Functions (1) corrcoef(x) cov(x) cplxpair(x) cross(x,y) cumprod(x) cumsum(x) del2(A) diff(x) dot(x,y) gradient(Z, dx, dy) Correlation coefficients Covariance matrix complex conjugate pairs vector cross product cumulative prod of cols cumulative sum of cols five-point discrete Laplacian diff between elements vector dot product approximate gradient

Data Analysis Functions (2) histogram(x) max(x), max(x,y) mean(x) median(x) min(x), min(x,y) prod(x) sort(x) std(x) subspace(A,B) sum(x) Histogram or bar chart max component mean of cols median of cols minimum component product of elems in col sort cols (ascending) standard dev of cols angle between subspaces sum of elems per col

Symbolic Math Toolbox

Symbolic Expressions ‘1/(2*x^n)’ cos(x^2) - sin(x^2) M = sym(‘[a, b ; c, d]’) f = int(‘x^3 / sqrt(1 - x)’, ‘a’, ‘b’)

Symbolic Expressions diff(‘cos(x)’) ans = -sin(x) det(M) ans = a*d - b * c

Symbolic Functions numden(m) - num & denom of polynomial symadd(f,g) - add symbolic polynomials symsub(f,g) - sub symbolic polynomials symmul(f,g) - mult symbolic polynomials symdiv(f,g) - div symbolic polynomials sympow(f,’3*x’) - raise f^3

Advanced Operations f = ‘1/(1+x^2)’ g = ‘sin(x)’ compose(f,g) % f(g(x)) ans= 1/(1+sin(x)^2)

Advanced Operations finverse(x^2) ans = x^(1/2) symsum(‘(2*n - 1) ^ 2’, 1, ‘n’) ans = 11/3*n + 8/3-4*(n+1)^2 + 4/3*(n+1)^3

Symbolic Differentiation f = ‘a*x^3 + x^2 + b*x - c’ diff(f) % by default wrt x ans = 3*a^2 + 2*x + b diff(f, ‘a’) % wrt a ans = x^3 diff(f,’a’,2) % double diff wrt a ans = 0

Symbolic Integration f = sin(s+2*x) int(f) ans = -1/2*cos(s+2*x) int(f,’s’) ans = -cos(s+2*x) int(f, ‘s’, pi/2,pi) ans= -cos(s)

Comments &Punctuation (1) All text after a percentage sign (%) is ignored >> % this is a comment Multiple commands can be placed on one line separated by commas (,) >> A = magic(4), B = ones(4), C = eye(4)

Comments &Punctuation (2) A semicolon may be also used, either after a single command or multiple commands >> A = magic(4); B = ones(4); C = eye(4); Ellipses (…) indicate a statement is continued on the next line A = B/… C

SAVE Command (1) >> save Store all the variables in binary format in a file called matlab.mat >> save fred Store all the variables in binary format in a file called fred.mat >> save a b d fred Store the variables a, b and d in fred.mat

SAVE Command (2) >> save a b d fred -ascii Stores the variables a, b and d in a file called fred.mat in 8-bit ascii format >> save a b d fred -ascii -double Stores the variables a, b and d in a file called fred.mat in 16-bit ascii format

Load Command Create a text file called mymatrix.dat with – – – – “load mymatrix.dat”, create variable mymatrix

M-Files To store your own MatLab commands in a file, create it as a text file and save it with a name that ends with “.m” So mymatrix.m A = [… ]; type mymatrix

IF Condition if condition {commands} end If x = 2 output = ‘x is even’ end

WHILE Loop while condition {commands} end X = 10; count = 0; while x > 2 x = x / 2; count = count + 1; end

FOR Loop for x=array {commands} end for n = 1:10 x(n) = sin(n); end A = zeros(5,5); % prealloc for n = 1:5 for m = 5:-1:1 A(n,m) = n^2 + m^2; end disp(n) end

Creating a function function a = gcd(a,b) % GCD Greatest common divisor % gcd(a,b) is the greatest common divisor of % the integers a and b, not both zero. a = round(abs(a)); b = round(abs(b)); if a == 0 & b == 0 error('The gcd is not defined when both numbers are zero') else while b ~= 0 r = rem(a,b); a = b; b = r; end

Quick Exercise (!) Consider Polynomial Addition again : how would you write a program that takes in two polynomials and irrespective of their sizes it adds the polynomials together ? Given that the function length(A) returns the length of a vector. Answers on a postcard to : oh, and while you’re here anyhow, if you have a browser open, please go to the following sites : hungersite.com