MATLAB Miran H. S. Mohammed 1 Lecture 1
OUTLINES Introduction Why using MATLAB Installing MATLAB Activate your installation Getting started Some useful command Using MATLAB as a calculator 2
INTRODUCTION MATLAB is an extremely powerful software application and development tool that is widely used in most universities in technical fields. MATLAB is an interactive system whose basic data element is an array that does not require dimensioning MATLAB is available for Windows, Macintosh and UNIX systems. It is used by more than one million people in industry and academia. MATLAB features a family of add-on application-specific solutions called toolboxes. Very important to most users of MATLAB, toolboxes allow you to learn and apply specialized technology. Toolboxes are comprehensive collections of MATLAB functions (M-files) that extend the MATLAB environment to solve particular classes of problems. You can add on toolboxes for signal processing, control systems, neural networks, fuzzy logic, wavelets, simulation, and many other areas. 3
Desktop Tools and Development Environment: This is the set of tools and facilities that help you use and become more productive with MATLAB functions and files. Many of these tools are graphical user interfaces. It includes the MATLAB desktop and Command Window, a command history, an editor and debugger, a code analyzer and other reports, and browsers for viewing help, the workspace, files, and the search path. Mathematical Function Library: This is a vast collection of computational algorithms ranging from elementary functions, like sum, sine, cosine, and complex arithmetic, to more sophisticated functions like matrix inverse, matrix Eigen values, Bessel functions, and fast Fourier transforms. 4
The Language: This is a high-level matrix/array language with control flow statements, functions, data structures, input/output, and object-oriented programming features. It allows both "programming in the small" to rapidly create quick and dirty throw-away programs, and "programming in the large" to create large and complex application programs. Graphics : MATLAB has extensive facilities for displaying vectors and matrices as graphs, as well as annotating and printing these graphs. It includes highlevel functions for two-dimensional and threedimensional data visualization, image processing, animation, and presentation graphics. It also includes low-level functions that allow you to fully customize the appearance of graphics as well as to build complete graphical user interfaces on your MATLAB applications. 5
WHY USING MATLAB? Advantages: It allows quick and easy coding in a very high-level language. Rich data types: Complex number, Three dimensional matrix, structure, cell array, etc Lots of nice functions and toolboxes: fminsearch, fsolve, normcdf, norminv, etc; garch, optimization, symbolic, Lots of users: economists, mathematicians, engineers, High-quality graphics and visualization facilities are available. MATLAB M-files are completely portable across a wide range of platforms. 6
So why is it called MATLAB? MATLAB is short for MATrix LABoratory. MATLAB was originally designed for manipulating matrices. In fact, when you use a simple variable such as x in MATLAB, it is actually stored as a ( x ) matrix. In order to understand how MATLAB works, we will need to be familiar with matrix calculations. We will cover more on this topic later. 7
INSTALLING MATLAB Before you install make sure! Have your File Installation Key and License File handy. You need both these items to perform an offnetwork installation and activation. Then, click on the installer icon from the drive(cd, DVD, ) 8
Choose to Install Without Using the Internet 9
Review the License Agreement 10
Specify the File Installation Key 11
Choose the Installation Type 12
Specify the Installation Folder 13
Wait for finishing the installation 14
Program configuration note 15
Complete the Installation 16
ACTIVATE YOUR INSTALLATION Choose Activate manually without the Internet 17
Specify the Path to the License File 18
Complete the Activation 19
GETTING STARTED you can enter MATLAB by double-clicking on the MATLAB shortcut icon on your Windows desktop. When you start MATLAB, a special window called the MATLAB desktop appears. The desktop is a window that contains other windows. The major tools within or accessible from the desktop are: The Command Window The Command History The Workspace The Current Directory The Help Browser 20
Menu bar Tool bar Current directory Current folder Work space Command window History command 21
MATLAB Desktop: Launch Pad: displays all the tools and applications associated with MATLAB; Command window: the space for writing your codes. Workspace: consists of the variables you create during a MATLAB session; Command History: double click them to evaluate them; Current Directory browser: shows you where you are. 22
SOME USEFUL COMMAND Version: to show the version of MATLAB cd : change directory to the root cd.. : change directory one level cd D:\ : change directory to drive D: mkdir D:\name : make directory in D: clc : clear screen Clear: clear all exit or quit: exit from the program help about : getting help Many other 23
USING MATLAB AS A CALCULATOR You are now faced with the MATLAB desktop on your computer, which contains the prompt (>>) in the Command Window. As an example of a simple interactive calculation, just type the expression you want to evaluate. For example, let's suppose you want to calculate the expression, 1 + 2 * 3. You type it at the prompt command (>>) as follows, >> 1+2*3 ans = 7 24
You will have noticed that if you do not specify an output variable, MATLAB uses a default variable ans, short for answer, to store the results of the current calculation. Note that the variable ans is created (or overwritten, if it is already existed). To avoid this, you may assign a value to a variable or output argument name. For example, >> x = 1+2*3 x = 7 will result in x being given the value 1 + 2 * 3 = 7. This variable name can always be used to refer to the results of the previous computations. Therefore, computing 4x will result in >> 4*x ans = 28.0000 25
26