170 likes | 541 Views
INTRODUCTION TO BASIC MATLAB. Introduction. MATLAB is a high-performance language for technical computing. It integrates computation, visualization, and programming where problems and solutions are expressed in familiar mathematical notation. Typical uses include: Math and computation
E N D
Introduction • MATLAB is a high-performance language for technical computing. It integrates computation, visualization, and programming where problems and solutions are expressed in familiar mathematical notation. • Typical uses include: • Math and computation • Algorithm development • Data acquisition • Modeling, simulation, and prototyping • Data analysis, exploration, and visualization • Scientific and engineering graphics • Application development, Including graphical user interface building
Introduction (Cont’) • MATLAB is an interactive system whose basic data element is an array that does not require dimensioning. This allows you to solve many technical computing problems, especially those with matrix and vector formulations. • In university environments, it is the standard instructional tool for introductory and advanced courses in mathematics, engineering, and science. In industry, MATLAB is the tool of choice for high-productivity research, development, and analysis.
Introduction (Cont’) • MATLAB features a family of add-on application-specific solutions called toolboxes. • Toolboxes are comprehensive collections of MATLAB functions (M-files) that extend the MATLAB environment to solve particular classes of problems. • Areas in which toolboxes are available include signal processing, control systems, neural networks, fuzzy logic, wavelets, simulation, and many others.
The MATLAB System • The MATLAB system consists of five main parts: • i) Development Environment • - This is the set of tools and facilities that help you use 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, and browsers for viewing help, the workspace, files, and the search path. • ii) The MATLAB 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 eigenvalues, Bessel functions, and Fast Fourier transforms.
The MATLAB System (cont’) • iii) The MATLAB 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 programming in the large" to create complete large and complex application programs. • iv) Graphics • - MATLAB has extensive facilities for displaying vectors and matrices as graphs, as well as annotating and printing these graphs. It includes high-level functions for two-dimensional and three-dimensional 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. • v) The MATLAB Application Program Interface (API) • - This is a library that allows you to write C and FORTRAN programs that interact with MATLAB. It includes facilities for calling routines from MATLAB (dynamic linking), calling MATLAB as a computational engine, and for reading and writing MAT-files.
Starting Matlab • When you start MATLAB, 4 windows appear (by default): • MATLAB Command Window • Current Directory Window • Workspace Window • Command History Window
i) MATLAB Command Window: • To communicate with MATLAB program, use MATLAB command window. • MATLAB display the prompt (>> ) to indicate that it is ready to receive instructions.
ii) Current Directory Window: • It is much like a file manager window. • Used to access files. • For example: file.m – it will open file in Matlab editor.
iii) Workspace Window: • Display the variables created in the command window. • Workspace refers to the names and values of any variable in-use in the current work session.
iv) Command History Window: • All the previous keystrokes entered in Matlab Command Window showed here. • You can click and drag the command into the Matlab command window or Matlab editor. • You can alter the appearance of the desktop by clicking ViewDesktop layout.
Entering Commands and Expressions: • Try out this 3-line command in Matlab Command Window: • >> x=[0:002:8]; • >> y=5*sin(x); • >> plot(x,y): • When you put semicolon (;) at the end of your command line, Matlab will not shows the answer of your commands/expressions. • Example of mathematical expressions in Matlab prompt: • >> 8/10 • ans = 0.8000 • >> 5*anw • ans = 4
Variables • A variable in Matlab is a symbol used to contain a value. • When we do not specify a variable name for a result, Matlab uses the symbol ans as a temporary variable containing the most recent answer. • Scalar variable: • >> r=8/10 • r = 0.8000 • >> s=5*r • s = 4
Variables (Cont’) Scalar arithmetic operations:
Variables (Cont’) • Variable names must begin with a letter and must contain less than 32 characters; contain letter, digits, and underscore. • Matlab is case-sensitive; the following names represent different variables: speed, Speed, SPEED. • Commands for managing the work session: • >> clc : clear the command window. • >> clear : removes all variables from memory. • >> clear var1,var2 : removes the variables var1 and var2. • >> quit : stops matlab • >> who : lists the variables currently in memory • >> whos :lists current variable and size. • : :generates an array having regularly spaced elements. • ; : suppresses screen printing, denotes a new row. • , :separates elements of an array.
Computing with Matlab • Matlab has the ability to handle collection of numbers, called array. • Example of array variable: • >> x= [0 1 3 6]; % 4-sequence of array • >> u= [0 1; 2 1]; % 2x2 matrix • >> y= [0:0.01:2]; • >> length (y); % check total number of sequence-y • >> y(7); % check the value of y in array-7 • Polynomial roots: to find roots of >> a= [1, -7, 40, -34]; • >> roots (a) • Answer: roots of a: x=1, x=3+5i • Built-in and User Defined Functions.
Computing with Matlab (cont’) Some commonly used mathematical function: