Matlab Basics FIN250f: Lecture 3 Spring 2010 Grifths Web Notes.

Slides:



Advertisements
Similar presentations
Introduction to MATLAB The language of Technical Computing.
Advertisements

Introduction to Matlab
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 20P. 1Winter Quarter Propulsion Lab with MATLAB Lecture 20.
Programming with MATLAB
ECEN/MAE 3723 – Systems I MATLAB Lecture 1. Lecture Overview  Introduction and History  Matlab architecture  Operation basics  Visualization  Programming.
Maths for Computer Graphics
Lecture 5 Review Programming Program Structures Comparison Repetition: looping or iteration Conditional execution: branching Bubble Sort.
Introduction to Matlab By: Dr. Maher O. EL-Ghossain.
Week 6 - Programming I So far, we’ve looked at simple programming via “scripts” = programs of sequentially evaluated commands Today, extend features to:
General Computer Science for Engineers CISC 106 Lecture 08 Dr. John Cavazos Computer and Information Sciences 2/27/2009.
EGR 106 – Week 8 Data Files & Functions Interacting with Data Files Functions – Concept – Examples and applications Textbook chapter ,
MATLAB TUTORIAL Dmitry Drutskoy Some material borrowed from the departmental MATLAB info session by Philippe Rigollet Kevin Wayne.
Matlab Basics IEF 217a: Lecture 2 Fall 2002 Sigmon and Davis, chapters 1-7.
Introduction to MATLAB MECH 300H Spring Starting of 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.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 21P. 1Winter Quarter MATLAB: Structures.
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.
INTRO TO PROGRAMMING Chapter 2. M-files While commands can be entered directly to the command window, MATLAB also allows you to put commands in text files.
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 Zongqiang Liao Research Computing Group UNC-Chapel Hill.
Predefined MATLAB Functions ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
GNU/Qt Octave Rohin Kumar Y, Dept. of Physics & Astro Physics, University of Delhi.
Introduction to MATLAB January 18, 2008 Steve Gu Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,
Introduction to Matlab 1. Outline: What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators Plotting Flow Control Using of M-File Writing.
CSE123 Lecture 5 Arrays and Array Operations. Definitions Scalars: Variables that represent single numbers. Note that complex numbers are also scalars,
Introduction to MATLAB CBE 502 Mathematical Methods of Engineering Analysis.
MEGN 536 – Computational Biomechanics MATLAB: Getting Started Prof. Anthony J. Petrella Computational Biomechanics Group.
Introduction to Engineering MATLAB – 1 Introduction to MATLAB Agenda Introduction Arithmetic Operations MATLAB Windows Command Window Defining Variables.
MATLAB An Introduction to MATLAB (Matrix Laboratory) 1.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
COMP 116: Introduction to Scientific Programming Lecture 6: Scripts and publishing, Creating matrices.
MATLAB Tutorial EE 327 Signals and Systems 1. What is MATLAB? MATLAB – Matrix Laboratory The premier number-crunching software Extremely useful for signal.
Matrix Computations ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Lecture 2 - Matlab Introduction CVEN 302 June 5, 2002.
ME6104: CAD. Module 4. ME6104: CAD. Module 4. Systems Realization Laboratory Module 4 Matlab ME 6104 – Fundamentals of Computer-Aided Design.
Introduction to Matlab. What is Matlab? A software environment for interactive numerical computations Examples:  Matrix computations and linear algebra.
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
MATLAB Lecture Two Tuesday 5 July Chapter 3.
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
CSE123 Lecture 3 Files and File ManagementScripts.
Matrix Computations ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
Digital Image Processing Introduction to M-function Programming.
Introduction to Matlab
EGR 115 Introduction to Computing for Engineers MATLAB Basics 3: Array Operations Monday 08 Sept 2014 EGR 115 Introduction to Computing for Engineers.
Introduction to MATLAB Zongqiang Liao Research Computing Group UNC-Chapel Hill.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
1 Lecture 3 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
MATLAB Lecture 1 염익준. Introduction MATLAB (MATrix LABoratory) a special purpose computer program optimized to perform engineering and scientific calculations.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 20P. 1Winter Quarter Propulsion Lab with.
CS100A, Fall 1998, Lecture 201 CS100A, Fall 1998 Lecture 20, Tuesday Nov 10 More Matlab Concepts: plotting (cont.) 2-D arrays Control structures: while,
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 Matlab PHY September Why Matlab? No need to compile code Huge amount of built-in functions Highly optimized and fast, in general.
Introduction to Matlab
Matlab Workshop 9/22/2018.
StatLab Matlab Workshop
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
محاسبات عددی در مهندسی پزشکی جلسه اول و دوم مقدمه ای بر نرم افزار MATLAB گلناز بغدادی 1391.
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Announcements P3 due today
Presentation transcript:

Matlab Basics FIN250f: Lecture 3 Spring 2010 Grifths Web Notes

Loading Software  Matlab  Follow matlab instructions for your own machine  Downloads  We will eventually be downloading various matlab programs and data from the website

Matlab Basics  Math Operations  Variables  Vectors  Functions  Fancy subscripts  Program files

Math Operations  Super calculator  +,-,*,/,^, ()

Variables  x = 1  1+x  x = 10  y = 20  x*y  The importance of ; (no printing)  x = 1;

Vectors  In matlab variables can be vectors  Vector = list of numbers  x = [ ];  2*x  x+1

Generating Vectors  : operator  1:10  1:2:10  60:-1:35  x = 1:5;

Parts of Vectors  x(2)  x(10)  x(b)  x(10:15), x(20:end)

Vector Operations (dot operators)  x = [1 2 3];  y = [ 2 1 3];  x.* y  x./ y  x.^ y

Matrices  x = [1 2 3; 4 5 6];  x =   rows = 2, columns = 3

Parts of Matrices  x =   x(row, column)  x(2,1) = 4  x(2,:) =  x(1,1:2) = 1 2

Functions  Scalar functions: f(x)  log(x), exp(x), sqrt(x)  sin(x), cos(x), tan(x)  Vector functions  sum(x), mean(x), median(x)

More Functions  plot(x)  plot(x,'*');  Most important function!!!!  Help  help functionname  help plot

Even More Functions  zeros(m,n) : returns a matrix of zeros  ones(m,n) : returns a matrix of ones  rand(m,n) : returns a matrix of uniform [0,1] random numbers  randn(m,n) : returns a matrix of normal, mean 0, variance 1, random numbers  (Note: We will often use my own function normal instead of randn)

Programs (mfiles)  Execute commands in a file  filename.m  Edit using matlab editor (colors)  Examples:

Conditions  >, =, <=, ==, ~=  x > 5  x < 10

If conditions  if (x>1)  x = x/2;  end

If/else  if (x<0)  x = x+1;  else  x = -1*x;  end

For loops  for j = [1 2 3]  x(j) = j+1;  end

For Loops  for j = 1:10  x(j) = 2^j;  end  also  x = 2.^(1:10);

For Loops  Useful for dealing with arrays  Costly in terms of computer time

While Loops  x = 20;  y = 0;  while (x>3)  y = y+sqrt(x);  x = x-5;  end

If’s With Vectors  if (a==b)  disp(‘a equals b’)  end  What if a and b are vectors?  True if every element of a equals every element of b

If’s With Vectors  if (a~=b)  disp(‘a not equals b’)  end  True if every element of a is not equal

Any and All  if any(a==b)  disp(‘at least one equal’)  end  if all(a==b)  disp(‘all are equal’)  end  For matrices this gets more complicated

Fancy Subscripts (find function)  x = [ ];  y = x(find(x<0));  all x values less than zero put in y  k = find(x<0);  k = subscripts  k = [ 3 4];

Fancy Subscripts  x = [ ];  y = x(x<0);  all x values less than zero put in y  k = x<0;  k = [ ];  y = x(k) = [-3 -4]  s = sum(k) = 2

Important: Comment Lines  Lines starting with % are comments  x = 1;  y = 2;  z = x*y;  % this really is not doing very much

Getting and Storing Results  diary filename  (all results to filename)  diary off  (stop)

Load  load x.dat  File x.dat =    Same thing in matrix x  x file must be matrix

Save  save  (saves everything to file matlab.mat)  load  (restores all settings)  useful for taking a break, and starting where you left off

Save  save filename x y z  (save to filename.mat variables x, y, z)  save filename x y z -ascii  (save in ascii format)

User Functions  Define your own functions  Very important and powerful

Function file (positives.m)  function count = positives(x)  % usage: count = positives(x)  % x = vector  % count = number greater than zero  count = sum(x>0);

Fancy function stuff  Multiple returns  function [ count, count2] = positives(x)  count = sum(x>0);  count2 = sum(x>2);

Summary  We will see many more of these matlab related commands as we make use of them