[PDF] [PDF] Getting Started with MATLAB

square is (n3 + n)/2 The magic Function MATLAB actually has a built-in function that creates magic squares of almost any size Not surprisingly, this function is 



Previous PDF Next PDF





[PDF] Lectures on Matlab

Most of the usual mathematical functions are implemented in MATLAB >> cos(0) Write a script file to calculate the squares of the integers up to 20 A script 



[PDF] Notes introductives à Matlab

On peut utiliser Matlab, soit en mode en ligne, c'est-à-dire saisir des commandes dans la fenêtre d' Matrix functions - numerical linear algebra Square root



[PDF] Initiation au logiciel Matlab

3 PROGRAMMATION ET M-FILE FUNCTIONS axis('square') présente le graphe dans un carré au lieu du rectangle habituel 7 4 Les commandes figure, hold 



[PDF] MATLAB tutorial - Faculty Washington

(MATLAB) How does a command or function work? >> help sqrt SQRT Square root SQRT(X) is the square root of the elements of X Complex results are 



[PDF] Getting Started with MATLAB

square is (n3 + n)/2 The magic Function MATLAB actually has a built-in function that creates magic squares of almost any size Not surprisingly, this function is 



[PDF] MATLAB® Primer

MATLAB and Simulink are registered trademarks of The MathWorks, Inc See MATLAB actually has a built-in function that creates magic squares of almost any  



[PDF] MATLAB Tutorial

DOC: DOC FUN displays the help browser for the MATLAB function FUN (e g doc help) You can invoke matrix is defined inside a pair of square brackets ([])



[PDF] Short Matlab Manual

To use this function to calculate the area and circumference of a rectangle with sides 5 and 7, and for a square with side 6, we type the following at the Matlab 



[PDF] MATLAB Programming

MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, and xPC To create a 5-by-5 magic square matrix, use the magic function as shown eye



[PDF] Matlab Guide - Cleveland State University

15 sept 2008 · tary math functions are in matlab\elfun, so I type help matlab\elfun than or equal to 100 that have integer square roots It shows you how to 

[PDF] functional structure

[PDF] fundamentals of corporate finance pdf

[PDF] fundamentos de administracion y gestion

[PDF] fundamentos de gestión empresarial

[PDF] fundamentos de gestion empresarial definicion

[PDF] fundamentos de gestion empresarial enfoque basado en competencias pdf

[PDF] fundamentos de gestion empresarial enfoque basado en competencias pdf gratis

[PDF] fundamentos de gestion empresarial julio garcia del junco pdf

[PDF] fundamentos de gestion empresarial libro

[PDF] fundamentos de gestion empresarial mc graw hill pdf

[PDF] fundamentos de gestión empresarial pearson pdf

[PDF] fundamentos de gestion empresarial unidad 1

[PDF] fundamentos de marketing kotler 13 edicion pdf

[PDF] fundamentos de marketing kotler 14 edicion pdf

[PDF] fundamentos de marketing kotler 8va edicion pdf

M ATLABThe Language of Technical ComputingComputation

Visualization

Programming

Getting Started with MATLAB

Version 5

How to Contact The MathWorks:

508-647-7000 Phone

508-647-7001 Fax

The MathWorks, Inc. Mail

24 Prime Park Way

Natick, MA 01760-1500

Anonymous FTP servercomp.soft-sys.matlab

Newsgroupsupport@mathworks.com

Technical supportsuggest@mathworks.comProduct enhancement suggestions bugs@mathworks.com

Bug reportsdoc@mathworks.com

Documentation error reportssubscribe@mathworks.com Subscribing user registrationservice@mathworks.comOrder status, license renewals, passcodes info@mathworks.comSales, pricing, and general information

Getting Started with MATLAB

ÓCOPYRIGHT 1984 - 1998 by The MathWorks, Inc.

The software described in this document is furnished under a license agreement. The software may be used

or copied only under the terms of the license agreement. No part of this manual may be photocopied or repro-

duced in any form without prior written consent from The MathWorks, Inc. U.S. GOVERNMENT: If Licensee is acquiring the Programs on behalf of any unit or agency of the U.S.

Government, the following shall apply: (a) For units of the Department of Defense: the Government shall

have only the rights specified in the license under which the commercial computer software or commercial

software documentation was obtained, as set forth in subparagraph (a) of the Rights in Commercial Computer Software or Commercial Software Documentation Clause at DFARS 227.7202-3, therefore the

rights set forth herein shall apply; and (b) For any other unit or agency: NOTICE: Notwithstanding any

other lease or license agreement that may pertain to, or accompany the delivery of, the computer software

and accompanying documentation, the rights of the Government regarding its use, reproduction, and disclo-

sure are as set forth in Clause 52.227-19 (c)(2) of the FAR. MATLAB, Simulink, Stateflow, Handle Graphics, and Real-Time Workshop are registered trademarks, and Target Language Compiler is a trademark of The MathWorks, Inc. Other product or brand names are trademarks or registered trademarks of their respective holders. Printing History: December 1996 First printing (for MATLAB 5)

May1997 Secondprinting(forMATLAB5.1)

September 1998 Third printing (for MATLAB 5.3)

i

Contents

Getting Started

Starting MATLAB...................................2

Matrices and Magic Squares...........................3EnteringMatrices .................................

4sum,transpose,anddiag .............................5

Subscripts .........................................7 Variables .........................................11 Operators ........................................12 Functions .........................................12 Expressions .......................................14 Working with Matrices...............................15 GeneratingMatrices ..................................15 M-Files .............................................16 Concatenation .......................................17 Deleting Rows and Columns . . . . . . ......................

17The Command Window...............................19

TheformatCommand ...............................19 SuppressingOutput ...................................21

LongCommandLines ...............................

iiContents

AddingPlotstoanExistingGraph........................25Subplots ....................-12(.........................27ImaginaryandComplexData...................-12(.........28ControllingAxes.......................................29AxisLabelsandTitles........-12(.........................30MeshandSurfacePlots................................31VisualizingFunctionsofTwoVariables...................31Images...........-12(............................-12(......32PrintingGraphics............-12(........................33HelpandOnlineDocumentation.....-12(................34ThehelpCommand. ...-12(.......-12(......-12(..................34TheHelpWindow...........................-12(......35ThelookforCommand..................................36TheHelpDesk...............-12(............ ............37ThedocCommand.................-12(...................37PrintingOnlineReferencePages.................. ...37Li nk tot heM athWorks................................37TheMATLABEnvironment.................-12(............38TheWorkspace.....-12(..........-12(............-12(............38saveCommands...........................-12(............39TheSearchPath....-12(...................................39DiskFileManipulation.............................40ThediaryCommand..............................40RunningExternalPrograms.............-12(.........-12(...41MoreAboutMatricesa ndArrays.. ..........-12(... .........42LinearAlgebra.......................................42Arrays...................-12(.........................45MultivariateData.....................................47ScalarExpansion ..................................-12(...48LogicalSubscripting......................-12(............49ThefindFunction...............................-12(......50

iii Flow Control......................................52 if ...............................................52

switchandcase ...................-12(.......-12(.........-12(...53for...............................................54while.......-12(...........................-12(.......-12(...55break.................... .....................55OtherDataStructures.......-12(......-12(.................57MultidimensionalArrays...........................57CellArra ys........................-12(............59CharactersandText..................-12(...........61Structures......................................64ScriptsandFunctions.............-12(.......-12(............67Scripts......-12(...........................67Functions...........................-12(... ........ 69GlobalVariables....................................70Command/FunctionDuality.........................71TheevalFunction.....-12(....................-12(..........71Vectorization...............................72Preallocation....................................72FunctionFunctions...........-12(......................73HandleGraphics... ..............................76GraphicsObjects...............................76GraphicsObjects............-12(......................76ObjectHandles..... .....................-12(............77ObjectCreationFunctions..........................78ObjectProperties..............................78setandget................-12(...................-12(...79GraphicsUserInterfaces..........................-12(...81Animations ..... .................................81Movies..........-12(..............................83LearningMore.................................85

ivContents

Introduction

WhatIsMATLAB?...................vi

TheMATLABSystem..................vii

AboutSimulink...................vii

Introduction

vi

What Is MATLAB?

MATLAB is a high-performance language for technical computing. It integrates computation, visualization, and programming in an easy-to-use environment where problems and solutions are expressed in familiar mathematical notation. Typical uses include: •Math and computation •Algorithm development •Modeling, simulation, and prototyping •Data analysis, exploration, and visualization •Scientific and engineering graphics •Application development, including Graphical User Interface building 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 afraction ofthetimeit wouldtaketowritea program ina scalarnoninteractive language such as C or Fortran. ThenameMATLABstandsformatrix laboratory. MATLAB was originally written to provide easy access to matrix software developed by the LINPACK and EISPACK projects, which together represent the state-of-the-art in software for matrix computation. MATLAB has evolved over a period of years with input from many users. 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. MATLAB features a family of application-specific solutions calledtoolboxes. Very important to most users of MATLAB, toolboxes allow you tolearnand applyspecialized technology. 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. vii

The MATLAB System

The MATLAB system consists of five main parts:

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 rapidly create quick and dirty throw-away programs, and "programming in the large" to create complete large and complex application programs. The MATLAB working environment. This is the set of tools and facilities that you work with as the MATLAB user or programmer. It includes facilities for managing the variables in your workspace and importing and exporting data. It also includes tools for developing, managing, debugging, and profiling

M-files, MATLAB"s applications.

Handle Graphics. This is the MATLAB graphics system. It includes high-level commands for two-dimensional and three-dimensional data visualization, image processing, animation, and presentation graphics. It also includes low-level commands that allow you to fully customize the appearance of graphics as well as to build complete Graphical User Interfaces on your

MATLAB applications.

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 Application Program Interface (API). This is a library that allows you to write C and Fortran programs that interact with MATLAB. It include facilities for calling routines from MATLAB (dynamic linking), calling MATLAB as a computational engine, and for reading and writing MAT-files.

About Simulink

Simulink, a companion program to MATLAB, is an interactive system for simulatingnonlinear dynamicsystems. Itis a graphicalmouse-drivenprogram that allows you to model a system by drawing a block diagram on the screen and manipulating it dynamically. It can work with linear, nonlinear, continuous-time, discrete-time, multivariable, and multirate systems.

Introduction

viii Blocksetsare add-ins to Simulink that provide additional libraries of blocks for specialized applications like communications, signal processing, and power systems. Real-time Workshopis a program that allows you to generate C code from your block diagrams and to run it on a variety of real-time systems.

Getting Started

Starting MATLAB.................2

Matrices and Magic Squares..........3

Expressions...................11

Working with Matrices...............15

The Command Window................19

Graphics......................23

Help and Online Documentation...........34

The MATLAB Environment............747(38MoreAboutMatricesandArrays...........42FlowControl. .. ..... ..... ......52OtherDataStructures................57ScriptsandFunctions................67Hand leGraphics.................76LearningMore..................85

Getting Started

2

Starting MATLAB

This book is intended to help you start learning MATLAB. It contains a number of examples, so you should run MATLAB and follow along. To run MATLAB on a PC, double-click on the MATLAB icon. To run MATLAB on a UNIX system, type matlabat the operating system prompt. To quit

MATLAB at any time, type

quitat the MATLAB prompt.

If you feel you need more assistance, type

helpat the MATLAB prompt, or pull down on the Helpmenu on a PC. We will tell you more about the help and online documentation facilities later.

Matrices and Magic Squares

3

Matrices and Magic Squares

The best way for you to get started with MATLAB is to learn how to handle matrices. This section shows you how to do that. In MATLAB, a matrix is a rectangular array of numbers. Special meaning is sometimes attached to

1-by-1 matrices, which are scalars, and to matrices with only one row or

column, which are vectors. MATLAB has other ways of storing both numeric and nonnumeric data, but in the beginning, it is usually best to think of everything as a matrix. The operations in MATLAB are designed to be as natural as possible. Where other programming languages work with numbers one at a time, MATLAB allows you to work with entire matrices quickly and easily.

Getting Started

4

Agoodexamplematrix,used

throughout this book, appears in the Renaissance engraving

Melancholia I by the German

artist and amateur mathematician Albrecht Dürer.

This image is filled with

mathematicalsymbolism,andif you look carefully,you willsee a matrix in the upper right corner. This matrix is known as a magic square and was believed by many in Dürer"s time to have genuinely magical properties. It does turn out to have some fascinating characteristics worth exploring.

Entering Matrices

You can enter matrices into MATLAB in several different ways. •Enteranexplicitlistofelements. •Load matrices from external data files. •Generate matrices using built-in functions. •Create matrices with your own functions in M-files. Start by entering Dürer"s matrix as a list of its elements. You have only to follow a few basic conventions: •Separate the elements of a row with blanks or commas. •Use a semicolon, ;,toindicatetheendofeachrow. •Surround the entire list of elements with square brackets,

To enter Dürer"s matrix, simply type:

A = [16 3 2 13; 5 10 11 8; 9 6 7 12; 4 15 14 1]

Matrices and Magic Squares

5

MATLAB displays the matrix you just entered,

A =

16 3 2 13

5 10 11 8

9 6 7 12

4 15 14 1

This exactly matches the numbers in the engraving. Once you have entered the matrix, it is automatically remembered in the MATLAB workspace. You can refer to it simply as

A.NowthatyouhaveAin the workspace, take a look at

what makes it so interesting. Why is it magic? sum, transpose, and diag You"re probably already aware that the special properties of a magic square have to do with the various ways of summing its elements. If you take the sum along any row or column, or along either of the two main diagonals, you will always get the same number. Let"s verify that using MATLAB. The first statement to try is sum(A)

MATLAB replies with

ans =

34 34 34 34

When you don"t specify an output variable, MATLAB uses the variableans, short forquotesdbs_dbs7.pdfusesText_13