Computer Exercises for Econometrics
|
|
- Annabel Pope
- 6 years ago
- Views:
Transcription
1 Computer Exercises for Econometrics Simon Broda August 30,
2 1 Preliminaries Prerequisites Know how to turn on a computer Topics Covered MATLAB L A TEX(the program this great manual was produced with) Scientific Workplace / Maple (possibly) Required Reading The Matlab Primer. Available at and various other places on the web. The first one or two sessions will be based on this. Handouts I will give you. The Not So Short Introduction to L A TEX2e. Available in many different languages at User s Guide for the amsmath Package. Available at dunbar/docs/amsldoc.pdf 2 MATLAB Basics When you start MATLAB, you will be presented a window with 3 parts: 2
3 The right-hand part, the so-called command window, is the most important one: this is where you will enter commands to tell MATLAB what you want it to do. The left half of the screen contains a list of your variables and a command history, but we will not need them now. For the beginning, you may think of MATLAB as nothing but a calculator. Try it: In the command window, enter something like 5+5, followed by the <ENTER> key. The commands for the other basic arithmetic operations are -, / (division), * (multiplication) and ^ ( to the power of ). The single most important MATLAB command is help <functionname>. When invoked without an argument, help will display a list of available help topics: >> help HELP topics: matlab\general - General purpose commands. 3
4 matlab\ops - Operators and special characters. matlab\lang - Programming language constructs. matlab\elmat - Elementary matrices and matrix manipulation. matlab\elfun - Elementary math functions. matlab\specfun - Specialized math functions. matlab\matfun - Matrix functions - numerical linear algebra. matlab\datafun - Data analysis and Fourier transforms. matlab\audio - Audio support. matlab\polyfun - Interpolation and polynomials. matlab\funfun - Function functions and ODE solvers. matlab\sparfun - Sparse matrices. matlab\graph2d - Two dimensional graphs. matlab\graph3d - Three dimensional graphs. matlab\specgraph - Specialized graphs. matlab\graphics - Handle Graphics. matlab\uitools - Graphical user interface tools. matlab\strfun - Character strings. matlab\iofun - File input/output. matlab\timefun - Time and dates. matlab\datatypes - Data types and structures. matlab\verctrl - Version control. matlab\winfun - Windows Operating System Interface Files (DDE/COM) winfun\comcli - (No table of contents file) matlab\demos - Examples and demonstrations. toolbox\local - Preferences. toolbox\exlink - Excel Link. finance\finance - Financial Toolbox. finance\calendar - Financial Toolbox calendar functions. finance\findemos - Financial Toolbox demonstration functions. finance\finsupport - (No table of contents file) toolbox\optim - Optimization Toolbox toolbox\stats - Statistics Toolbox MATLAB6p5\work - (No table of contents file) For more help on directory/topic, type "help topic". For command syntax information, type "help syntax". 4
5 Note that MATLAB s functions are organized in so-called toolboxes. For example, we will often need the statistics toolbox, help on which is accessed by entering help stats. Entering help <topic> will display help on a specific topic. >> help sin SIN Sine. SIN(X) is the sine of the elements of X. Clearly, this is of little help when the name of the MATLAB function is not known. In this case, the command lookfor <searchphrase> is useful; it returns a list of MATLAB commands the help texts of which contain the searchphrase: >> lookfor sine ACOS Inverse cosine. ACOSH Inverse hyperbolic cosine. ASIN Inverse sine. ASINH Inverse hyperbolic sine. COS Cosine. COSH Hyperbolic cosine. SIN Sine. SINH Hyperbolic sine. TFFUNC time and frequency domain versions of a cosine modulated Gaussian pulse. xfourier.m: %% Square Wave from Sine Waves BUSDATE Next or previous business day. FBUSDATE First business date of month. ISBUSDAY True for dates that are business days. LBUSDATE Last business date of month. Scalar Functions The sin command mentioned earlier is one example of a MATLAB function. A function call is a special command which consists of the function name and, in parentheses, the function argument: 5
6 >> sin(5) ans = Other such elementary functions are exp (exponential), log (natural logarithm), sqrt (square root), abs (absolute value), etc; type help elmat for a comprehensive list. Some functions require more than one input argument. For example, normrand(<mu>,<sigma>) will return a random number from the normal distribution with mean mu and scale sigma. Matrices and Vectors Arguably the greatest strength of MATLAB is its ability to handle vectors and matrices; in fact, the name MATLAB stands for MATrix LABoratory. A matrix is entered by listing its individual elements in square brackets, separating lines with semicolons (or linefeeds) and columns with spaces: >> [ ; ] ans = Most of the elementary functions above will work for matrices; they will then operate elementwise: >> sin([ ; ]) ans = In order to make the basic arithmetic functions *, /, and ^ operate elementwise, the respective operator must be preceeded by a dot: 6
7 >> [ ].*[ ] ans = Of course, as a Matrix Laboratory, MATLAB also features special functions for matrices, some of which are (transpose), inv (inverse), eig (eigenvalues), chol (cholesky decomposition), etc; type help elmat for a list. Also, function exist for the construction of special matrices. For example, eye(<n>) will return a n n identity matrix. Similarly, ones(<n>,<m>) will produce a n m matrix of ones, while zeros(<n>,<m>) will produce a n m matrix of zeros. Variables Of course, your shiny new calculator also has the ability to store results. MATLAB uses variables for this purpose. A variable is nothing more than some reserved space in memory with a name to it. To assign a value to a variable, use the symbol = : A=[ ; ; ] A = Variable names can be made up from letters, numbers and the underscore ( ). They may not, however, start with a number. Note that MATLAB is case-sensitive: A is not the same as a. If A is a matrix, in order to access the (i,j)th element of A, write A(i,j): A=[ ; ; ] A = 7
8 >> A(2,2) ans = 6 To access a row (or column) of A as a whole, write A(i,1:end) or simply A(i,:). The special variable ans always contains the most recent result. The commands who and whos display information on current variables. The information returned by whos is also displayed in the upper left half of the MATLAB window. Variables can be saved to disk for later use with the command save <filename> <variable names>. If <variable names> is omitted, all variables will be saved. The command load <filename> <variable names> works analogously, but loads variables from file <filename>. Relational Operators Relational operators<,<=,>,>=,== (is equal), and = (is not equal) serve the purpose of comparing variables and will return 1 if the relation is true and 0 otherwise. Note the difference between == and = which is used in assignment statements: >> a=5 a = 5 >> a==5 ans = 8
9 1 Relations can be connected with the logical operators & (and), (or), and (not). For example, the following statement will always return 1 unless a = 1: (a<1) (a>1). m-files Until now, we have told MATLAB what we wanted it to do by just typing commands into the command window. This is clearly impractical if we want to reproduce the results later. Instead, it is possible put the commands into a file, called an m-file. m-files can be comfortably edited in the MATLAB editor. On a Windows machine, the MATLAB editor can be invoked from the start menu, or, usually more conveniently, by typing edit <filename> in the MATLAB command window. If <filename> does not exist, the editor will ask you if you want to create one upon starting up. m-files can be executed by simply typing their name in the command window, very much like an ordinary MATLAB function. You may want to try the following example program. In the command windows, type edit example1. The editor will ask you if you want to create a file by this name. Confirm by clicking Yes. Inside the editor window, type the following: randn( state,0) T=25,U=randn(T,1); X=[ones(T,1) [1:T] ];%the regressor matrix beta=[2;1];y=x*beta+u; betahat=inv(x *X)*X *Y Save the file to disk. From the command window, invoke our little example script file by typing example1: 9
10 >> example1 T = 25 betahat = So what can we learn from this example? The function randn(<n>,<m>) generates a n m matrix of iid standard normal (pseudo) random numbers. randn( state,0) resets the random number generator to its initial state so that the results can be reproduced. The % character starts a comment. Everything on the same line after that symbol will be ignored. You can have more than one command per line. They must be seperated by commas or semicolons; the latter will supress the output of the respective command. The command 1:T produces a row vector of the numbers 1... T in increasing order. Similarly, the command 1:2:2*T produces a vector of odd numbers ranging from 1 to 2T, i.e., the middle number determines the step size. Matrix definitions can be nested. The if-else-end Statement Sometimes we want to execute a certain command only if some condition is met This is where the if-else-end statement comes in. Its syntax is if <expression> <first command block> else <second command block> end 10
11 <expression> is an expression that produces 0 or 1 as a result. If <expression> is true, <first command block> will be executed, and <second command block> otherwise. For example, the statements if a<1 disp( a<1 ), else disp( a>1 );end will tell you if or not a > 1. It is also possible to have multiple if-branches; the syntax for this is: if <expression 1> <first command block> elseif <expression 2> <second command block> else <third command block> end Loops Sometimes we want to MATLAB to do something as long as a certain condition is met. This is achieved via the while statement. Its syntax is while <expression> end <command block> For example, the statements a=clock; while floor(a(4))<=18 & floor(a(4))>8 disp( You should be working. ); a=clock; end remind us of our working hours. Sometimes we want a loop to be executed a prespecified number of times. This could be achieved via a=1; while a<=100 11
12 end <commands> a=a+1; Since this kind of loop appears frequently, there is a shorthand notation for it: for a=1:100 end <commands> For example, the statements squares=zeros(25,1); for i=1:25; squares(i)=i^2; end; squares will store the squares of the numbers in a variable squares and display it. (Clearly, the shorter squares=[1:25].^2 would have achieved the same.) Functions So far, we have used m-files only as scripts, i.e., files that will be executed as if you had typed the commands in the command window. The other kind of m-file that MATLAB uses are user-defined function that can be used just like MATLAB s built-in functions. A function-file has a special syntax, as the following example illustrates: function result=sqr(x) %sqr(x) computes the square of the elements in x. result=x.^2; The above function must be saved in a file sqr.m 12
13 sqr is the name of the function, x is its input argument, and result is the return value. Note that variables used inside of a function are local, i.e., they have nothing to do with your workspace variables. To see this, try, in the command window: result=1;sqr(5);result and note that although the local variable result was assigned the value 5 inside the function, the workspace variable result still has the value 1. Clearly, the return variable must be assigned a value within the function, otherwise MATLAB will stop with an error message. The comment on the second line has a special purpose: It will be displayed by the help command. To see if it works, just type help sqr. Note that without the function declaration (the first line), sqr.m would be a script file. functions may have several output arguments, as the following example illustrates: function [themean,thevariance]=thestats(x) %thestats(x) computes the mean and variance of x. themean=sum(x)/length(x); thevariance=sum((x-themean).^2)/length(x); Once this is saved as thestats.m, the statement [a b]=thestats(randn(25,1)) will compute the mean and sample variance of a size 25 normal sample. Note that [a]=thestats(randn(25,1)) will only return the mean. Also, a function may have more than one input argument: function [themean,thevariance]=thestats2(x,unbiased) %thestats2(x) computes the mean and variance of x. themean=sum(x)/length(x); if unbiased==0 normalize=length(x); else normalize=length(x)-1; end thevariance=sum((x-themean).^2)/normalize; 13
14 thestats2 will return the MLE of the variance if unbiased==0 and the usual unbiased estimator otherwise. Now, of course, MATLAB will complain if thestats2 is called with only one argument. To avoid this, default values can be used: function [themean,thevariance]=thestats3(x,unbiased) %thestats3(x,unbiased) computes the mean and variance of x. if nargin<2 unbiased=1;end themean=sum(x)/length(x); if unbiased==0 normalize=length(x); else normalize=length(x)-1; end thevariance=sum((x-themean).^2)/normalize; the variable nargin contains the number of arguments the function was called with. Forcing Functions to Accept Vector Input For some purposes (e.g., plotting, quadrature; see below), it is necessary that a function accepts vector input. To understand what this means, recall function sqr.m from above: The way we implemented it, it does accept vector input. Had we instead programmed it like this function result=sqr(x) %sqr(x) computes the square of the elements in x. result=x^2;%note the missing dot before the ^ it would not. One way of forcing the function to accept vector input is the following: function result=sqr2(xvec) %sqr2(x) computes the square of the elements in x. result=zeros(size(xvec));%initialize to zero for loop=1:length(xvec)%work through the x vector x=xvec(loop); result(loop)=x^2; end; 14
15 Numerical Root Finding It often occurs that no closed-forms solution for the zeros of a function exists. The zeros must then be numerically obtained. For scalar functions, this could be achieved by, e.g., bisection or Newton s method, but it is more convenient to use the MATLAB function fzero. The syntax of the command is x=fzero(<fun>,<x0>,<options>,<p1>,<p2>,...). <fun> is the function we want to find the zeros of. It can be specified in several ways: As as string containing the name of the function. E.g., suppose we want to know a zero of the cosinus function. The syntax for this is x=fzero( cos,1) which will return π. 2 As a function handle: x=fzero(@cos,1) A function handle is a special data structure that contains all information about a function that MATLAB needs to evaluate it using feval, i.e., feval(@cos,1) is the same as cos(1). Type help function handle for more information. An inline object: x=fzero(inline( cos(x) ),1) Inline functions are a way of creating (simple) functions without having to make a function file. For example, the statement a=inline( randn(x,p1),1) will produce a function a that does the same as randn. Type help inline for more information. <x0> can be either a starting guess (when passed as a scalar) or an interval within which MATLAB will search for a zero (when passed as a 2-element vector). <options> is an object created by the optimset function. For example, optimset( TolX,1e-6) will set the tolerance on the position of the zero to To go with the default options, pass the word optimset. See help optimset for more details. fzero will search for a zero of the function with respect to its first argument. If the function takes more than one input argument, you may pass them as <p1>,<p2>,... 15
16 The following example computes the MLE for an iid Gam(a,b) sample. Remember that ˆb MLE = â MLE / X and â MLE is given implicitly as the solution to ln(a/ X) ψ(a)+ 1 n n i=1 ln x i = 0. function [a,b]=gammamle(x) a=fzero(@foc_a,1,optimset,x); b=a/mean(x); function result =foc_a(a,x) if a<=0 result=-a;return;end%quick and dirty result=log(a/mean(x))-psi(a)+mean(log(x)); To see if it works: >> a=3;b=5;randn( state,0);rand( state,0); >> X=gamrnd(a,1/b,100,1);[ahat bhat]=gammamle(x) ahat = bhat = (Note that MATLAB defines the Gamma distribution as Gamma(a,c), where c = 1/b, so that the second parameter is a genuine scaling parameter. For comparison, MATLAB s MLE routine gives: >> a=3;b=5;randn( state,0);rand( state,0); >> X=gamrnd(a,1/b,100,1);themle=mle( gam,x);[themle(1) 1/themle(2)] ans = For multidimensional root finding, fsolve must be used. 16
17 Numerical Optimization The MATLAB command for minimizing a scalar function of several variables is x=fminunc(<fun>,<x0>,<options>,<p1>,<p2>,...). fminunc uses a quasi-newton method (the BFGS algorithm). The input arguments correspond to those for the fzero command, except that for fminunc, <x0> must be starting value, the size of which must equal the number of variables over which to optimize. In our Gamma example, remember that the log likelihood is given by l(θ) = na ln b n ln Γ(a) + (a 1) n i=1 ln x i b n i=1 x i. The MLE could be implemented like this: function [a,b]=gammamle2(x) [ab]=fminsearch(@loglik,[1 1],optimset,X); a=ab(1);b=ab(2); function ll=loglik(ab,x) a=ab(1);b=ab(2); if a<=0 b<=0 ll=-a-b;return,end n=length(x); ll=-(n*a*log(b)-n*log(gamma(a))+(a-1)*sum(log(x))-b*sum(x)); Check if it works: >> a=3;b=5;randn( state,0);rand( state,0); >> X=gamrnd(a,1/b,100,1);[ahat bhat]=gammamle2(x) ahat = bhat =
18 Quadrature The term quadrature is used for numerical integration. The MATLAB command to accomplish this is quadl(<fun>,<a>,<b>,<tol>,<trace>,<p1>,<p2>,...), where <fun>, <p1>, <p2> are as above, [ab] is the interval over which to integrate, <TOL> is the absolute error tolerance, and <TRACE> will display interim results if set to anything other than zero. Use <TOL>=<TRACE>=[] to go with the defaults. Although <fun> must be a scalar function, it MUST accept vector input on which it operates elementwise; see above. The following example function will evaluate the normal cdf at <x>: function cdf=mynormcdf(x,mu,sigma) cdf=quadl(@normpdf,-1e+20,x,[],[],mu,sigma); Try what happens if -inf is used instead of -1e+20. For the evaluation of improper integrals of the form I = b a f(x) dx, with b =, the substitution t = 1/(x a + 1) proves useful, giving: Similarly, if a =, I = I = and if both a = and b =, I = 1 0 [ f f f ( a + 1 t ) 1 t t dt. 2 ( b 1 t ) 1 t t dt, 2 ( ) ( 1 t t 1 + f t t )] 1 t 2 dt. Application to our example involving the normal cdf yields function cdf=mynormcdf2(x,mu,sigma) cdf=quadl(@integrand,0,1,[],[],x,mu,sigma); function I=integrand(tvec,x,mu,sigma); 18
19 I=zeros(size(tvec)); for loop=1:length(tvec) t=tvec(loop); if (t==0 t==1) I(loop)=0; else u=x-(1-t)./t; I(loop)=normpdf(u,mu,sigma)./t.^2; end end Graphs and Printing To plot vector x versus vector y, use the MATLAB command plot(<x>,<y>). If the second argument is omitted, <x> will be plotted against its index. Example:x=[-3:0.01:3];plot(x,normpdf(x));. Various line types, plot symbols and colors may be obtained with plot(<x>,<y>,<s>) where s is a character string made from one element from any or all the following 3 columns: b blue. point - solid g green o circle : dotted r red x x-mark -. dashdot c cyan + plus dashed m magenta * star y yellow s square k black d diamond v triangle (down) ˆ triangle (up) < triangle (left) > triangle (right) p pentagram h hexagram For example, plot(<x>,<y>, c+: ) plots a cyan dotted line with a plus at each data point; plot(<x>,<y>, bd ) plots blue diamond at each data point but does not draw any line. 19
20 Use hold on to make a subsequent plots appear inside the same figure and hold off to have subsequent plot created in their own figures. a=figure creates an empty figure and returns its handle. figure(<a>) makes <a> the current figure. a=gcf gets the handle of the current figure; gca gets the handle of the current axis. grid toggles whether or not a grid is displayed on the current figure. axis([<xmin> <XMAX> <YMIN> <YMAX>]) sets the scaling for the x- and y-axes of the current figure. title( text ) adds a title to the current figure. Similarly, xlabel( text ) and ylabel( text ) set axis labels. set(<h>, PropertyName,PropertyValue) sets the value of the specified property for the graphics object with handle H. For example, set(gca, fontsize,16) will set the fontsize of the axis of the current figure to 16. set(<h>) will display a list of property names for the graphics object <H>, e.g., try set(gca). legend( string1, string2,..) will add a legend to the current figure. Try x=[-3:0.01:3];a=plot(x,normpdf(x));legend( Normal pdf ). print will send the current figure to the default printer. print -<driver> filename will use the specified driver and print to a file. E.g., use print -deps2 filename.eps for use with L A TEX. There are more options available for almost all commands listed above, but there is little use in covering every detail here. Please use the help facility. 20
21 3 L A TEX Obtaining L A TEX In the following, we will assume that you use MS Windows. If you use Linux (as you should), then chances are that all necessary programs are already installed or at least come bundled with your distribution. If you have a Macintosh, try cmactex ( From what I understand, the editor of choice for L A TEX on Macintosh is called Alpha and is available at Visit and download the file setup.exe. Run it. Choose Download only and enter a path to a temporary directory. After everything is downloaded, start setup.exe again, select Install and point it to your temporary directory. Visit Download and install the latest versions of GSview (4.5 at the time this was written) and Ghostscript (8.11 at the time this was written). Visit Download and install the latest version of WinEdt (5.3 at the time this was written). Note that unlike the other programs you just downloaded, WinEdt is NOT free. However, you may use it for 30 days without restrictions. Afterwards, WinEdt will start bugging you with requests to register it (unless you know how to avoid this ;-) Start WinEdt. Cancel the configuration wizard. Under Options Configurations, choose Miktex or Miktex Direct. Getting Started Unlike MS Word, L A TEX is not a WYSIWYG word processor, i.e., while editing a L A TEX document, you will not see right away what the result will look like. The document rather is a mixture of the actual text and specific commands that tell L A TEX what the final document should look like. Start WinEdt and create a new document. Save it as test.tex. Enter the following: 21
22 \documentclass{article} \begin{document} Hello World! \end{document} This is your first L A TEX document. To have it typeset, you have to compile the document by pressing the L A TEX button. WinEdt will call latex.exe, a DOS program which will produce the output file test.dvi. Afterwards, press the DVI button. This will open YAP, a DVI previewer. Unfortunately, the DVI format is not suitable for printing. If you want to print your document, you should convert it to a postscript file by clicking on the dvips button. Choose -P pdf -t A4 -z as generic parameters. To view the postscript file, click the button with the ghost with goggles to open GSview, the postscript viewer. To print it, select File Print... from within GSview. If you have a postscript printer (as is the case at ISB), it is recommended that you select PostScript Printer as print method. To convert the postscript document to a PDF file, press the ps2pdf button in WinEdt. There are other ways of creating PDF files: dvi2pdf will avoid the postscript step, and pdfl A TEX will directly compile to PDF, but these are NOT recommended. 22
Introduction to MATLAB
Introduction to MATLAB Contents 1.1 Objectives... 1 1.2 Lab Requirement... 1 1.3 Background of MATLAB... 1 1.4 The MATLAB System... 1 1.5 Start of MATLAB... 3 1.6 Working Modes of MATLAB... 4 1.7 Basic
More informationThe MATLAB system The MATLAB system consists of five main parts:
Introduction to MATLAB What is MATLAB? The name MATLAB stands for matrix laboratory. MATLAB is a high performance language for technical computing. It integrates computation, visualization, and programming
More information1 Introduction to Matlab
1 Introduction to Matlab 1. What is Matlab? Matlab is a computer program designed to do mathematics. You might think of it as a super-calculator. That is, once Matlab has been started, you can enter computations,
More informationLecture 1: What is MATLAB?
Lecture 1: What is MATLAB? Dr. Mohammed Hawa Electrical Engineering Department University of Jordan EE201: Computer Applications. See Textbook Chapter 1. MATLAB MATLAB (MATrix LABoratory) is a numerical
More informationIntroduction to MATLAB for CSE390
Introduction Introduction to MATLAB for CSE390 Professor Vijay Kumar Praveen Srinivasan University of Pennsylvania MATLAB is an interactive program designed for scientific computations, visualization and
More informationFundamentals of MATLAB Usage
수치해석기초 Fundamentals of MATLAB Usage 2008. 9 담당교수 : 주한규 joohan@snu.ac.kr, x9241, Rm 32-205 205 원자핵공학과 1 MATLAB Features MATLAB: Matrix Laboratory Process everything based on Matrix (array of numbers) Math
More informationIntroduction to Matlab
What is Matlab? Introduction to Matlab Matlab is software written by a company called The Mathworks (mathworks.com), and was first created in 1984 to be a nice front end to the numerical routines created
More informationPurpose of the lecture MATLAB MATLAB
Purpose of the lecture MATLAB Harri Saarnisaari, Part of Simulations and Tools for Telecommunication Course This lecture contains a short introduction to the MATLAB For further details see other sources
More informationMATLAB Introduction to MATLAB Programming
MATLAB Introduction to MATLAB Programming MATLAB Scripts So far we have typed all the commands in the Command Window which were executed when we hit Enter. Although every MATLAB command can be executed
More informationWhat is MATLAB? What is MATLAB? Programming Environment MATLAB PROGRAMMING. Stands for MATrix LABoratory. A programming environment
What is MATLAB? MATLAB PROGRAMMING Stands for MATrix LABoratory A software built around vectors and matrices A great tool for numerical computation of mathematical problems, such as Calculus Has powerful
More informationInteractive Computing with Matlab. Gerald W. Recktenwald Department of Mechanical Engineering Portland State University
Interactive Computing with Matlab Gerald W. Recktenwald Department of Mechanical Engineering Portland State University gerry@me.pdx.edu Starting Matlab Double click on the Matlab icon, or on unix systems
More informationPART 1 PROGRAMMING WITH MATHLAB
PART 1 PROGRAMMING WITH MATHLAB Presenter: Dr. Zalilah Sharer 2018 School of Chemical and Energy Engineering Universiti Teknologi Malaysia 23 September 2018 Programming with MATHLAB MATLAB Environment
More informationMatlab Tutorial 1: Working with variables, arrays, and plotting
Matlab Tutorial 1: Working with variables, arrays, and plotting Setting up Matlab First of all, let's make sure we all have the same layout of the different windows in Matlab. Go to Home Layout Default.
More informationMATLAB SUMMARY FOR MATH2070/2970
MATLAB SUMMARY FOR MATH2070/2970 DUNCAN SUTHERLAND 1. Introduction The following is inted as a guide containing all relevant Matlab commands and concepts for MATH2070 and 2970. All code fragments should
More informationIntroduction to Matlab
Introduction to Matlab November 22, 2013 Contents 1 Introduction to Matlab 1 1.1 What is Matlab.................................. 1 1.2 Matlab versus Maple............................... 2 1.3 Getting
More informationA = [1, 6; 78, 9] Note: everything is case-sensitive, so a and A are different. One enters the above matrix as
1 Matlab Primer The purpose of these notes is a step-by-step guide to solving simple optimization and root-finding problems in Matlab To begin, the basic object in Matlab is an array; in two dimensions,
More informationUsing Matlab in the Chemical Engineering Curriculum at the University of Tennessee. A Workshop presented by David Keffer August 17, 2001
Using Matlab in the Chemical Engineering Curriculum at the University of Tennessee A Workshop presented by David Keffer August 17, 2001 Abstract This talk is intended to provide someone unfamiliar with
More informationInlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS
Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS 1 6 3 Matlab 3.1 Fundamentals Matlab. The name Matlab stands for matrix laboratory. Main principle. Matlab works with rectangular
More informationIntroduction to MATLAB
Chapter 1 Introduction to MATLAB 1.1 Software Philosophy Matrix-based numeric computation MATrix LABoratory built-in support for standard matrix and vector operations High-level programming language Programming
More informationMath Scientific Computing - Matlab Intro and Exercises: Spring 2003
Math 64 - Scientific Computing - Matlab Intro and Exercises: Spring 2003 Professor: L.G. de Pillis Time: TTh :5pm 2:30pm Location: Olin B43 February 3, 2003 Matlab Introduction On the Linux workstations,
More informationIntroduction to Matlab. By: Dr. Maher O. EL-Ghossain
Introduction to Matlab By: Dr. Maher O. EL-Ghossain Outline: q What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display Facilities Flow Control
More informationSTAT 391 Handout 1 Making Plots with Matlab Mar 26, 2006
STAT 39 Handout Making Plots with Matlab Mar 26, 26 c Marina Meilă & Lei Xu mmp@cs.washington.edu This is intended to help you mainly with the graphics in the homework. Matlab is a matrix oriented mathematics
More informationDSP Laboratory (EELE 4110) Lab#1 Introduction to Matlab
Islamic University of Gaza Faculty of Engineering Electrical Engineering Department 2012 DSP Laboratory (EELE 4110) Lab#1 Introduction to Matlab Goals for this Lab Assignment: In this lab we would have
More informationA General Introduction to Matlab
Master Degree Course in ELECTRONICS ENGINEERING http://www.dii.unimore.it/~lbiagiotti/systemscontroltheory.html A General Introduction to Matlab e-mail: luigi.biagiotti@unimore.it http://www.dii.unimore.it/~lbiagiotti
More information2 Amazingly Simple Example Suppose we wanted to represent the following matrix 2 itchy = To enter itchy in Matla
Superlative-Laced Matlab Help for ECE155 Students Brian Kurkoski kurkoski@ucsd.edu October 13, 1999 This document is an introduction to Matlab for ECE155 students. It emphasizes the aspects of Matlab that
More informationMATLAB Tutorial. 1. The MATLAB Windows. 2. The Command Windows. 3. Simple scalar or number operations
MATLAB Tutorial The following tutorial has been compiled from several resources including the online Help menu of MATLAB. It contains a list of commands that will be directly helpful for understanding
More informationIntroduction to MATLAB
CHEE MATLAB Tutorial Introduction to MATLAB Introduction In this tutorial, you will learn how to enter matrices and perform some matrix operations using MATLAB. MATLAB is an interactive program for numerical
More information2.0 MATLAB Fundamentals
2.0 MATLAB Fundamentals 2.1 INTRODUCTION MATLAB is a computer program for computing scientific and engineering problems that can be expressed in mathematical form. The name MATLAB stands for MATrix LABoratory,
More information12 whereas if I terminate the expression with a semicolon, the printed output is suppressed.
Example 4 Printing and Plotting Matlab provides numerous print and plot options. This example illustrates the basics and provides enough detail that you can use it for typical classroom work and assignments.
More informationECON 502 INTRODUCTION TO MATLAB Nov 9, 2007 TA: Murat Koyuncu
ECON 502 INTRODUCTION TO MATLAB Nov 9, 2007 TA: Murat Koyuncu 0. What is MATLAB? 1 MATLAB stands for matrix laboratory and is one of the most popular software for numerical computation. MATLAB s basic
More informationGetting Started. Chapter 1. How to Get Matlab. 1.1 Before We Begin Matlab to Accompany Lay s Linear Algebra Text
Chapter 1 Getting Started How to Get Matlab Matlab physically resides on each of the computers in the Olin Hall labs. See your instructor if you need an account on these machines. If you are going to go
More informationA QUICK INTRODUCTION TO MATLAB
A QUICK INTRODUCTION TO MATLAB Very brief intro to matlab Basic operations and a few illustrations This set is independent from rest of the class notes. Matlab will be covered in recitations and occasionally
More informationAppendix A. Introduction to MATLAB. A.1 What Is MATLAB?
Appendix A Introduction to MATLAB A.1 What Is MATLAB? MATLAB is a technical computing environment developed by The Math- Works, Inc. for computation and data visualization. It is both an interactive system
More informationSome elements for Matlab programming
Some elements for Matlab programming Nathalie Thomas 2018 2019 Matlab, which stands for the abbreviation of MATrix LABoratory, is one of the most popular language for scientic computation. The classical
More informationIntroduction to Matlab
Introduction to Matlab What is Matlab The software program called Matlab (short for MATrix LABoratory) is arguably the world standard for engineering- mainly because of its ability to do very quick prototyping.
More informationWhat is MATLAB and howtostart it up?
MAT rix LABoratory What is MATLAB and howtostart it up? Object-oriented high-level interactive software package for scientific and engineering numerical computations Enables easy manipulation of matrix
More informationA QUICK INTRODUCTION TO MATLAB. Intro to matlab getting started
A QUICK INTRODUCTION TO MATLAB Very brief intro to matlab Intro to matlab getting started Basic operations and a few illustrations This set is indepent from rest of the class notes. Matlab will be covered
More informationLaboratory 1 Octave Tutorial
Signals, Spectra and Signal Processing Laboratory 1 Octave Tutorial 1.1 Introduction The purpose of this lab 1 is to become familiar with the GNU Octave 2 software environment. 1.2 Octave Review All laboratory
More informationMatlab Tutorial and Exercises for COMP61021
Matlab Tutorial and Exercises for COMP61021 1 Introduction This is a brief Matlab tutorial for students who have not used Matlab in their programming. Matlab programming is essential in COMP61021 as a
More informationINTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX
INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX 1) Objective The objective of this lab is to review how to access Matlab, Simulink, and the Communications Toolbox, and to become familiar
More informationIntroduction to MATLAB
58:110 Computer-Aided Engineering Spring 2005 Introduction to MATLAB Department of Mechanical and industrial engineering January 2005 Topics Introduction Running MATLAB and MATLAB Environment Getting help
More informationUniversity of Alberta
A Brief Introduction to MATLAB University of Alberta M.G. Lipsett 2008 MATLAB is an interactive program for numerical computation and data visualization, used extensively by engineers for analysis of systems.
More informationIntroduction to Matlab to Accompany Linear Algebra. Douglas Hundley Department of Mathematics and Statistics Whitman College
Introduction to Matlab to Accompany Linear Algebra Douglas Hundley Department of Mathematics and Statistics Whitman College August 27, 2018 2 Contents 1 Getting Started 5 1.1 Before We Begin........................................
More informationMAT 275 Laboratory 1 Introduction to MATLAB
MATLAB sessions: Laboratory 1 1 MAT 275 Laboratory 1 Introduction to MATLAB MATLAB is a computer software commonly used in both education and industry to solve a wide range of problems. This Laboratory
More informationINTRODUCTION TO MATLAB
1 of 18 BEFORE YOU BEGIN PREREQUISITE LABS None EXPECTED KNOWLEDGE Algebra and fundamentals of linear algebra. EQUIPMENT None MATERIALS None OBJECTIVES INTRODUCTION TO MATLAB After completing this lab
More informationMATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP)
Digital Signal Processing Prof. Nizamettin AYDIN naydin@yildiz.edu.tr naydin@ieee.org http://www.yildiz.edu.tr/~naydin Course Details Course Code : 0113620 Course Name: Digital Signal Processing (Sayısal
More informationMath 375 Natalia Vladimirova (many ideas, examples, and excersises are borrowed from Profs. Monika Nitsche, Richard Allen, and Stephen Lau)
Natalia Vladimirova (many ideas, examples, and excersises are borrowed from Profs. Monika Nitsche, Richard Allen, and Stephen Lau) January 24, 2010 Starting Under windows Click on the Start menu button
More informationAMS 27L LAB #2 Winter 2009
AMS 27L LAB #2 Winter 2009 Plots and Matrix Algebra in MATLAB Objectives: 1. To practice basic display methods 2. To learn how to program loops 3. To learn how to write m-files 1 Vectors Matlab handles
More informationIntroduction to Matlab
Introduction to Matlab By:Mohammad Sadeghi *Dr. Sajid Gul Khawaja Slides has been used partially to prepare this presentation Outline: What is Matlab? Matlab Screen Basic functions Variables, matrix, indexing
More informationMatlab Introduction. Scalar Variables and Arithmetic Operators
Matlab Introduction Matlab is both a powerful computational environment and a programming language that easily handles matrix and complex arithmetic. It is a large software package that has many advanced
More informationIntroduction to MatLab. Introduction to MatLab K. Craig 1
Introduction to MatLab Introduction to MatLab K. Craig 1 MatLab Introduction MatLab and the MatLab Environment Numerical Calculations Basic Plotting and Graphics Matrix Computations and Solving Equations
More informationDr Richard Greenaway
SCHOOL OF PHYSICS, ASTRONOMY & MATHEMATICS 4PAM1008 MATLAB 2 Basic MATLAB Operation Dr Richard Greenaway 2 Basic MATLAB Operation 2.1 Overview 2.1.1 The Command Line In this Workshop you will learn how
More informationA Guide to Using Some Basic MATLAB Functions
A Guide to Using Some Basic MATLAB Functions UNC Charlotte Robert W. Cox This document provides a brief overview of some of the essential MATLAB functionality. More thorough descriptions are available
More information1. Register an account on: using your Oxford address
1P10a MATLAB 1.1 Introduction MATLAB stands for Matrix Laboratories. It is a tool that provides a graphical interface for numerical and symbolic computation along with a number of data analysis, simulation
More informationLecturer: Keyvan Dehmamy
MATLAB Tutorial Lecturer: Keyvan Dehmamy 1 Topics Introduction Running MATLAB and MATLAB Environment Getting help Variables Vectors, Matrices, and linear Algebra Mathematical Functions and Applications
More informationChapter 2. MATLAB Fundamentals
Chapter 2. MATLAB Fundamentals Choi Hae Jin Chapter Objectives q Learning how real and complex numbers are assigned to variables. q Learning how vectors and matrices are assigned values using simple assignment,
More informationFinding, Starting and Using Matlab
Variables and Arrays Finding, Starting and Using Matlab CSC March 6 &, 9 Array: A collection of data values organized into rows and columns, and known by a single name. arr(,) Row Row Row Row 4 Col Col
More informationProgramming 1. Script files. help cd Example:
Programming Until now we worked with Matlab interactively, executing simple statements line by line, often reentering the same sequences of commands. Alternatively, we can store the Matlab input commands
More informationA very brief Matlab introduction
A very brief Matlab introduction Siniša Krajnović January 24, 2006 This is a very brief introduction to Matlab and its purpose is only to introduce students of the CFD course into Matlab. After reading
More informationProgramming in Mathematics. Mili I. Shah
Programming in Mathematics Mili I. Shah Starting Matlab Go to http://www.loyola.edu/moresoftware/ and login with your Loyola name and password... Matlab has eight main windows: Command Window Figure Window
More informationChapter 1 MATLAB Preliminaries
Chapter 1 MATLAB Preliminaries 1.1 INTRODUCTION MATLAB (Matrix Laboratory) is a high-level technical computing environment developed by The Mathworks, Inc. for mathematical, scientific, and engineering
More informationIntroduction to Matlab
What is Matlab? Introduction to Matlab Matlab is a computer program designed to do mathematics. You might think of it as a super-calculator. That is, once Matlab has been started, you can enter computations,
More informationExperiment 1: Introduction to MATLAB I. Introduction. 1.1 Objectives and Expectations: 1.2 What is MATLAB?
Experiment 1: Introduction to MATLAB I Introduction MATLAB, which stands for Matrix Laboratory, is a very powerful program for performing numerical and symbolic calculations, and is widely used in science
More informationCreates a 1 X 1 matrix (scalar) with a value of 1 in the column 1, row 1 position and prints the matrix aaa in the command window.
EE 350L: Signals and Transforms Lab Spring 2007 Lab #1 - Introduction to MATLAB Lab Handout Matlab Software: Matlab will be the analytical tool used in the signals lab. The laboratory has network licenses
More informationAMATH 352: MATLAB Tutorial written by Peter Blossey Department of Applied Mathematics University of Washington Seattle, WA
AMATH 352: MATLAB Tutorial written by Peter Blossey Department of Applied Mathematics University of Washington Seattle, WA MATLAB (short for MATrix LABoratory) is a very useful piece of software for numerical
More informationIntroduction to Engineering gii
25.108 Introduction to Engineering gii Dr. Jay Weitzen Lecture Notes I: Introduction to Matlab from Gilat Book MATLAB - Lecture # 1 Starting with MATLAB / Chapter 1 Topics Covered: 1. Introduction. 2.
More informationPowerPoints organized by Dr. Michael R. Gustafson II, Duke University
Part 1 Chapter 2 MATLAB Fundamentals PowerPoints organized by Dr. Michael R. Gustafson II, Duke University All images copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
More informationIntroduction to MATLAB
Introduction to MATLAB 1 Introduction to MATLAB A Tutorial for the Course Computational Intelligence http://www.igi.tugraz.at/lehre/ci Stefan Häusler Institute for Theoretical Computer Science Inffeldgasse
More informationIntroduction to Octave/Matlab. Deployment of Telecommunication Infrastructures
Introduction to Octave/Matlab Deployment of Telecommunication Infrastructures 1 What is Octave? Software for numerical computations and graphics Particularly designed for matrix computations Solving equations,
More informationMATLAB Fundamentals. Berlin Chen Department of Computer Science & Information Engineering National Taiwan Normal University
MATLAB Fundamentals Berlin Chen Department of Computer Science & Information Engineering National Taiwan Normal University Reference: 1. Applied Numerical Methods with MATLAB for Engineers, Chapter 2 &
More informationMatlab Tutorial for COMP24111 (includes exercise 1)
Matlab Tutorial for COMP24111 (includes exercise 1) 1 Exercises to be completed by end of lab There are a total of 11 exercises through this tutorial. By the end of the lab, you should have completed the
More informationIntroduction to GNU-Octave
Introduction to GNU-Octave Dr. K.R. Chowdhary, Professor & Campus Director, JIETCOE JIET College of Engineering Email: kr.chowdhary@jietjodhpur.ac.in Web-Page: http://www.krchowdhary.com July 11, 2016
More informationIntroduction to MATLAB
Introduction to MATLAB Basics MATLAB is a high-level interpreted language, and uses a read-evaluate-print loop: it reads your command, evaluates it, then prints the answer. This means it works a lot like
More informationBRUNO WELFERT Arizona State University AND. R. Kent Nagle. University of South Florida. Edward B. Saff. Vanderbilt University. A.
ONLINE MATLAB MANUAL BRUNO WELFERT Arizona State University FUNDAMENTALS OF DIFFERENTIAL EQUATIONS SEVENTH EDITION AND FUNDAMENTALS OF DIFFERENTIAL EQUATIONS AND BOUNDARY VALUE PROBLEMS FIFTH EDITION R.
More informationChapter 2 (Part 2) MATLAB Basics. dr.dcd.h CS 101 /SJC 5th Edition 1
Chapter 2 (Part 2) MATLAB Basics dr.dcd.h CS 101 /SJC 5th Edition 1 Display Format In the command window, integers are always displayed as integers Characters are always displayed as strings Other values
More informationBEGINNING MATLAB. R.K. Beatson Mathematics Department University of Canterbury. 2 Matlab as a simple matrix calculator 2
BEGINNING MATLAB R.K. Beatson Mathematics Department University of Canterbury Contents 1 Getting started 1 2 Matlab as a simple matrix calculator 2 3 Repeated commands 4 4 Subscripting, rows, columns and
More informationMatlab (Matrix laboratory) is an interactive software system for numerical computations and graphics.
Matlab (Matrix laboratory) is an interactive software system for numerical computations and graphics. Starting MATLAB - On a PC, double click the MATLAB icon - On a LINUX/UNIX machine, enter the command:
More informationMatLab Just a beginning
MatLab Just a beginning P.Kanungo Dept. of E & TC, C.V. Raman College of Engineering, Bhubaneswar Introduction MATLAB is a high-performance language for technical computing. MATLAB is an acronym for MATrix
More informationLearning from Data Introduction to Matlab
Learning from Data Introduction to Matlab Amos Storkey, David Barber and Chris Williams a.storkey@ed.ac.uk Course page : http://www.anc.ed.ac.uk/ amos/lfd/ This is a modified version of a text written
More informationHERIOT-WATT UNIVERSITY DEPARTMENT OF COMPUTING AND ELECTRICAL ENGINEERING. B35SD2 Matlab tutorial 1 MATLAB BASICS
HERIOT-WATT UNIVERSITY DEPARTMENT OF COMPUTING AND ELECTRICAL ENGINEERING Objectives: B35SD2 Matlab tutorial 1 MATLAB BASICS Matlab is a very powerful, high level language, It is also very easy to use.
More informationOutline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline (Cont d) MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An
CSE 170 Interacting with MATLAB Instructor: Aijun An Department of Computer Science and Engineering York University aan@cse.yorku.ca Outline Starting MATLAB MATLAB Windows Using the Command Window Some
More informationMatlab and Octave: Quick Introduction and Examples 1 Basics
Matlab and Octave: Quick Introduction and Examples 1 Basics 1.1 Syntax and m-files There is a shell where commands can be written in. All commands must either be built-in commands, functions, names of
More informationMATLAB primer for CHE 225
MATLAB primer for CHE 225 The following pages contain a brief description of the MATLAB features are used in CHE 225. This document is best used in conjunction with the MATLAB codes posted on Vista. Find
More informationLAB 1 General MATLAB Information 1
LAB 1 General MATLAB Information 1 General: To enter a matrix: > type the entries between square brackets, [...] > enter it by rows with elements separated by a space or comma > rows are terminated by
More informationObjectives. 1 Running, and Interface Layout. 2 Toolboxes, Documentation and Tutorials. 3 Basic Calculations. PS 12a Laboratory 1 Spring 2014
PS 12a Laboratory 1 Spring 2014 Objectives This session is a tutorial designed to a very quick overview of some of the numerical skills that you ll need to get started. Throughout the tutorial, the instructors
More informationMatlab Tutorial. The value assigned to a variable can be checked by simply typing in the variable name:
1 Matlab Tutorial 1- What is Matlab? Matlab is a powerful tool for almost any kind of mathematical application. It enables one to develop programs with a high degree of functionality. The user can write
More informationELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah)
Introduction ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah) MATLAB is a powerful mathematical language that is used in most engineering companies today. Its strength lies
More informationPC-MATLAB PRIMER. This is intended as a guided tour through PCMATLAB. Type as you go and watch what happens.
PC-MATLAB PRIMER This is intended as a guided tour through PCMATLAB. Type as you go and watch what happens. >> 2*3 ans = 6 PCMATLAB uses several lines for the answer, but I ve edited this to save space.
More informationScientific Computing Lecture 1: MATLAB fundamentals
Scientific Computing Lecture 1: MATLAB fundamentals InFoMM CDT Mathematical Institute University of Oxford Andrew Thompson (slides by Stuart Murray) Lecture I: MATLAB fundamentals What is MATLAB? MATLAB
More informationBasic stuff -- assignments, arithmetic and functions
Basic stuff -- assignments, arithmetic and functions Most of the time, you will be using Maple as a kind of super-calculator. It is possible to write programs in Maple -- we will do this very occasionally,
More informationA GUIDE FOR USING MATLAB IN COMPUTER SCIENCE AND COMPUTER ENGINEERING TABLE OF CONTENTS
A GUIDE FOR USING MATLAB IN COMPUTER SCIENCE AND COMPUTER ENGINEERING MARC THOMAS AND CHRISTOPHER PASCUA TABLE OF CONTENTS 1. Language Usage and Matlab Interface 1 2. Matlab Global Syntax and Semantic
More informationAn Introduction to Numerical Methods
An Introduction to Numerical Methods Using MATLAB Khyruddin Akbar Ansari, Ph.D., P.E. Bonni Dichone, Ph.D. SDC P U B L I C AT I O N S Better Textbooks. Lower Prices. www.sdcpublications.com Powered by
More informationTo start using Matlab, you only need be concerned with the command window for now.
Getting Started Current folder window Atop the current folder window, you can see the address field which tells you where you are currently located. In programming, think of it as your current directory,
More informationEric W. Hansen. The basic data type is a matrix This is the basic paradigm for computation with MATLAB, and the key to its power. Here s an example:
Using MATLAB for Stochastic Simulation. Eric W. Hansen. Matlab Basics Introduction MATLAB (MATrix LABoratory) is a software package designed for efficient, reliable numerical computing. Using MATLAB greatly
More informationWhat is Matlab? A software environment for interactive numerical computations
What is Matlab? A software environment for interactive numerical computations Examples: Matrix computations and linear algebra Solving nonlinear equations Numerical solution of differential equations Mathematical
More information1.1 ABOUT MATLAB and MATLAB GUI (Graphical User Interface)
Chapter 1 Introduction The Taylor Series is one of the most important tools in numerical analysis. It constitutes the foundation of numerical methods and will be used in most of the chapters of this text.
More informationAPPM 2460 PLOTTING IN MATLAB
APPM 2460 PLOTTING IN MATLAB. Introduction Matlab is great at crunching numbers, and one of the fundamental ways that we understand the output of this number-crunching is through visualization, or plots.
More informationHow to Use MATLAB. What is MATLAB. Getting Started. Online Help. General Purpose Commands
How to Use MATLAB What is MATLAB MATLAB is an interactive package for numerical analysis, matrix computation, control system design and linear system analysis and design. On the server bass, MATLAB version
More informationOutline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.
CSE 170 Interacting with MATLAB Instructor: Aijun An Department of Computer Science and Engineering York University aan@cse.yorku.ca Outline Starting MATLAB MATLAB Windows Using the Command Window Some
More informationIntroduction to MATLAB
Introduction to MATLAB Introduction MATLAB is an interactive package for numerical analysis, matrix computation, control system design, and linear system analysis and design available on most CAEN platforms
More information